Fetch Public and TWKN timelines when viewed.

This commit is contained in:
Roger Braun 2017-02-16 11:17:47 +01:00
parent 14f07dde5d
commit 832bd3cdd2
6 changed files with 46 additions and 8 deletions

View file

@ -2,11 +2,32 @@ import backendInteractorService from '../services/backend_interactor_service/bac
const api = {
state: {
backendInteractor: backendInteractorService()
backendInteractor: backendInteractorService(),
fetchers: {}
},
mutations: {
setBackendInteractor (state, backendInteractor) {
state.backendInteractor = backendInteractor
},
addFetcher (state, {timeline, fetcher}) {
state.fetchers[timeline] = fetcher
},
removeFetcher (state, {timeline}) {
delete state.fetchers[timeline]
}
},
actions: {
startFetching (store, timeline) {
// Don't start fetching if we already are.
if (!store.state.fetchers[timeline]) {
const fetcher = store.state.backendInteractor.startFetching({timeline, store})
store.commit('addFetcher', {timeline, fetcher})
}
},
stopFetching (store, timeline) {
const fetcher = store.state.fetchers[timeline]
window.clearInterval(fetcher)
store.commit('removeFetcher', {timeline})
}
}
}