frontend/src/store/helper.js

19 lines
405 B
JavaScript
Raw Normal View History

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