summaryrefslogblamecommitdiff
path: root/iridescence/src/store/index.js
blob: 0e5d3bef759aaeda5d1bb3ffb28d87f91a0b316c (plain) (tree)
1
2
3
4
5
6
7
8
9

                        
                                           


              

                                   
                               
          

                   

            
                     
                                            


                                                    



              







                                  
                              




                                                                
     
    

             
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: []
  },
  getters: {
    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: {}
});