Code refactoring

This commit is contained in:
Edijs 2019-02-07 16:23:18 -07:00
parent 19870c0b6d
commit 0dc7c45f32
6 changed files with 15 additions and 30 deletions

View file

@ -1,5 +1,4 @@
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
import { isArray } from 'lodash'
import { Socket } from 'phoenix'
const api = {
@ -34,26 +33,12 @@ const api = {
}
},
actions: {
startFetching (store, payload) {
let userId = false
let timeline = 'friends'
let tag = false
if (isArray(payload)) {
// For user timelines
timeline = payload[0]
userId = payload[1]
} else if (payload.tag) {
// For tag timelines
timeline = 'tag'
tag = payload.tag
}
startFetching (store, {timeline = 'friends', tag = false, userId = false}) {
// Don't start fetching if we already are.
if (!store.state.fetchers[timeline]) {
const fetcher = store.state.backendInteractor.startFetching({timeline, store, userId, tag})
store.commit('addFetcher', {timeline, fetcher})
}
if (store.state.fetchers[timeline]) return
const fetcher = store.state.backendInteractor.startFetching({ timeline, store, userId, tag })
store.commit('addFetcher', { timeline, fetcher })
},
stopFetching (store, timeline) {
const fetcher = store.state.fetchers[timeline]