Stackedit/src/store/file.js
2017-11-10 23:39:51 +00:00

36 lines
748 B
JavaScript

import moduleTemplate from './moduleTemplate';
import empty from '../data/emptyFile';
const module = moduleTemplate(empty);
module.state = {
...module.state,
currentId: null,
};
module.getters = {
...module.getters,
current: state => state.itemMap[state.currentId] || empty(),
lastOpened: (state, getters, rootState, rootGetters) =>
state.itemMap[rootGetters['data/lastOpenedIds'][0]] || getters.items[0] || empty(),
};
module.mutations = {
...module.mutations,
setCurrentId(state, value) {
state.currentId = value;
},
};
module.actions = {
...module.actions,
patchCurrent({ getters, commit }, value) {
commit('patchItem', {
...value,
id: getters.current.id,
});
},
};
export default module;