2020-05-09 22:08:18 +02:00
|
|
|
import {LOADING} from './mutation-types'
|
|
|
|
|
2020-12-23 21:26:43 +01:00
|
|
|
export const setLoading = (context, loadFunc = null) => {
|
2020-05-09 22:08:18 +02:00
|
|
|
const timeout = setTimeout(() => {
|
2020-12-23 21:26:43 +01:00
|
|
|
if (loadFunc === null) {
|
|
|
|
context.commit(LOADING, true, {root: true})
|
|
|
|
} else {
|
|
|
|
loadFunc(true)
|
|
|
|
}
|
2020-05-09 22:08:18 +02:00
|
|
|
}, 100)
|
|
|
|
return () => {
|
|
|
|
clearTimeout(timeout)
|
2020-12-23 21:26:43 +01:00
|
|
|
if (loadFunc === null) {
|
|
|
|
context.commit(LOADING, false, {root: true})
|
|
|
|
} else {
|
|
|
|
loadFunc(false)
|
|
|
|
}
|
2020-05-09 22:08:18 +02:00
|
|
|
}
|
|
|
|
}
|