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

                        
                                           



                               
          

                   

            

                                                        
 
                                            
                

                                                                  




              









                                                     
     
    

             
import Vue from "vue";
import Vuex from "vuex";
import Dichroism from "@/api/dichroism.js";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    searchTerm: "",
    products: []
  },
  getters: {
    products(state) {
      const searchTerm = state.searchTerm.toLowerCase();

      return state.products.filter(item => {
        return (
          item.name.toLowerCase().indexOf(searchTerm) != -1 ||
          item.description.toLowerCase().indexOf(searchTerm) != -1
        );
      });
    }
  },
  mutations: {
    searchTerm(state, term) {
      state.searchTerm = term;
    },
    setProducts(state, products) {
      state.products = products;
    }
  },
  actions: {
    refreshProducts({ commit }) {
      commit("setProducts", Dichroism.getProducts());
    }
  },
  modules: {}
});