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.
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:
- introduce
unmapped_itemsfield in store update ongetunmappedmenuitemssuccessaction. - same filtering after data loaded back-end. in case
getunmappedmenuitemssuccessswitch source of items without doing additional work. - do filtering in
componentcode.
Comments
Post a Comment