blob: 1a83c01164564001d12210966b938c37647873b3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import Vue from "vue";
import Vuex from "vuex";
import Dichroism from "@/api/dichroism.js";
Vue.use(Vuex);
let dichroismApi = new Dichroism();
export default new Vuex.Store({
state: {
searchTerm: "",
products: [],
busy: false
},
getters: {
busy(state) {
return state.busy;
},
products(state) {
return state.products.filter(item => {
return JSON.stringify(item)
.toLowerCase()
.includes(state.searchTerm.toLowerCase());
});
}
},
mutations: {
searchTerm(state, term) {
state.searchTerm = term;
},
setProducts(state, products) {
state.products = products;
}
},
actions: {
refreshProducts(context) {
context.commit("setProducts", dichroismApi.getProducts());
},
updateProduct(context, product) {
dichroismApi.updateProduct(product);
context.dispatch("refreshProducts");
}
},
modules: {}
});
|