vue-express-mongo-boilerplate
Version:
Express NodeJS application server boilerplate with Mongo and VueJS
81 lines (67 loc) • 1.47 kB
JavaScript
import {
LOAD, LOAD_MORE, ADD, SELECT, CLEAR_SELECT, UPDATE, REMOVE,
CLEAR, NO_MORE_ITEMS, FETCHING,
CHANGE_SORT, CHANGE_VIEWMODE
} from "./types";
import { each, find, assign, remove, isArray } from "lodash";
const state = {
rows: [],
offset: 0,
hasMore: true,
fetching: false,
sort: "-votes",
viewMode: "all"
};
const mutations = {
[] (state, models) {
state.rows.splice(0);
state.rows.push(...models);
state.offset = state.rows.length;
},
[] (state, models) {
state.rows.push(...models);
state.offset = state.rows.length;
},
[] (state) {
state.offset = 0;
state.hasMore = true;
},
[] (state, status) {
state.fetching = status;
},
[] (state, sort) {
state.sort = sort;
mutations[CLEAR](state);
},
[] (state, mode) {
state.viewMode = mode;
mutations[CLEAR](state);
},
[] (state) {
state.hasMore = false;
},
[] (state, model) {
let found = find(state.rows, (item) => item.code == model.code);
if (!found)
state.rows.unshift(model);
},
[] (state, model) {
each(state.rows, (item) => {
if (item.code == model.code) {
assign(item, model);
}
});
},
[] (state, model) {
state.rows = state.rows.filter(item => item.code != model.code);
}
};
import * as getters from "./getters";
import * as actions from "./actions";
export default {
namespaced: true,
state,
getters,
actions,
mutations
};