reactjs - Preserve redux store while updating different components -


here reducer file.

export default (state = initialstate, action) => { switch (action.type) { case appconstants.getmenuitems:   return {     ...state,     isloading: true   } case appconstants.getmenuitemssuccess:   return {     ...state,     menu_items: action.menu_items,     menu_items_copy: action.menu_items,     unmapped: false,     isloading: false   } case appconstants.getaddonsitems:   return {     ...state,     isloading: true   } case appconstants.getaddonsitemssuccess:   return {     ...state,     menu_items: action.addon_items,     isloading: false   }    case appconstants.showallproducts:    return {     ...state,     menu_items: state.menu_items,     unmapped: false   }   case appconstants.getunmappedmenuitemssuccess:   return {     ...state,     unmapped: true,     menu_items_copy: state.menu_items,     menu_items: state.menu_items_copy.filter(data => {       data.productlist = data.productlist.filter(         id => id.brandproductskulist[0].productskuid.length === 36,       );       return data.productlist.length !== 0;     })   } 

now when click on unmapped filter shows filtered data after unmapped when click allproducts still gives unmapped data ,since in unmap function state (menu_items) updated.so how show original data in allproducts. , in ui ,i using (this.props.menu_items) ,so have update only.here image of ui want ,when categories clicked should show allproducts , unmapped , addons.

i think making conceptual mistake when altering menu_items upon unmapped items request. quite useful think redux store if kind of old-good sql database , design accordingly. not remove rows not included in select operation database. still living inside table, not selected.

same story redux apps. let getmenuitemssuccess place menu_items mutated. 1 of following:

  1. introduce unmapped_items field in store update on getunmappedmenuitemssuccess action.
  2. same filtering after data loaded back-end. in case getunmappedmenuitemssuccess switch source of items without doing additional work.
  3. do filtering in component code.

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -