2016-10-03 13:31:29 +01:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { fetchItem, fetchRecents } from './api';
|
|
|
|
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
debug: true,
|
|
|
|
state: {
|
|
|
|
recents: [],
|
|
|
|
item: {},
|
|
|
|
services: [],
|
2016-10-24 00:18:36 +01:00
|
|
|
share: true,
|
2016-10-03 13:31:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
// ensure data for rendering given list type
|
|
|
|
FETCH_RECENTS: ({ commit }) => fetchRecents()
|
2018-04-08 16:31:46 +01:00
|
|
|
.then(res => commit('SET_RECENTS', { recents: res.body.recents })),
|
2016-10-03 13:31:29 +01:00
|
|
|
|
2018-04-08 16:31:46 +01:00
|
|
|
FETCH_ITEM: ({ commit }, { service, type, id }) => fetchItem(service, type, id)
|
|
|
|
.then(item => commit('SET_ITEM', { item })),
|
2016-10-03 13:31:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
mutations: {
|
|
|
|
SET_RECENTS: (state, { recents }) => {
|
|
|
|
state.recents = recents; // eslint-disable-line no-param-reassign
|
|
|
|
},
|
|
|
|
|
|
|
|
SET_ITEM: (state, { item }) => {
|
2018-04-08 16:31:46 +01:00
|
|
|
state.item = item.body; // eslint-disable-line
|
2016-10-03 13:31:29 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default store;
|