Restructure status module for easier testing.

This commit is contained in:
Roger Braun 2016-11-07 18:04:00 +01:00
parent 26d47c0f41
commit 78db0db637

View file

@ -2,7 +2,7 @@ import { map, slice, last, intersectionBy, sortBy, unionBy, toInteger, groupBy,
import moment from 'moment'
import apiService from '../services/api/api.service.js'
const defaultState = {
export const defaultState = {
allStatuses: [],
maxId: 0,
timelines: {
@ -110,21 +110,7 @@ const updateTimestampsInStatuses = (statuses) => {
})
}
const statuses = {
state: defaultState,
actions: {
favorite ({ rootState, commit }, status) {
// Optimistic favoriting...
commit('setFavorited', { status, value: true })
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
},
unfavorite ({ rootState, commit }, status) {
// Optimistic favoriting...
commit('setFavorited', { status, value: false })
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
}
},
mutations: {
export const mutations = {
addNewStatuses (state, { statuses, showImmediately = false, timeline }) {
state.timelines[timeline] = addStatusesToTimeline(statuses, showImmediately, state.timelines[timeline])
state.allStatuses = unionBy(state.timelines[timeline].statuses, state.allStatuses.id)
@ -156,6 +142,22 @@ const statuses = {
})
}
}
const statuses = {
state: defaultState,
actions: {
favorite ({ rootState, commit }, status) {
// Optimistic favoriting...
commit('setFavorited', { status, value: true })
apiService.favorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
},
unfavorite ({ rootState, commit }, status) {
// Optimistic favoriting...
commit('setFavorited', { status, value: false })
apiService.unfavorite({ id: status.id, credentials: rootState.users.currentUser.credentials })
}
},
mutations
}
export default statuses