summaryrefslogblamecommitdiff
path: root/iridescence/src/store/index.js
blob: 2b24816480efc82ee6c4370c2110d142acba9b82 (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 dichroism = 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", dichroism.getProducts());
    },
    updateProduct(context, product) {
      dichroism.updateProduct(product);
      context.dispatch("refreshProducts");
    }
  },
  modules: {}
});