combine.fm/public/src/store/index.js

37 lines
838 B
JavaScript
Raw Normal View History

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,
},
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 })),
2018-04-08 16:31:46 +01:00
FETCH_ITEM: ({ commit }, { service, type, id }) => fetchItem(service, type, id)
.then(item => commit('SET_ITEM', { item })),
},
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
},
},
});
export default store;