javascript - Assigning a reducer for a dynamic store property -


i'm trying figure out how set reducer property in state tree gets created user events.

my state tree looks this:

{   session: { session object },   dashboard: {     id: 'id001',     charts: {       'cid001': { dimensions: { ... }, more objects... },       'cid002': { dimensions: { ... }, more objects... }     }    }  } 

new charts properties come in through redux when user clicks add chart button. key set chart id, cid.

i'm using combinereducers() set reducer tree.

import session './session'; import charts './charts';  const rootreducer = combinereducers({   session,   dashboard: combinereducers({     charts   }); }); 

i able nest reducers if know property names ahead of time. however, i'd avoid having massive reducer charts property, since each chart inside have 20 more objects on need reducing, dimensions 1 example.

is there way set reducer charts['cidxxx'].dimensions, , other sub-properties? there wildcard tokens this? thoughts?

object spreads nice this.

function chartsreducer(state, {payload}) {   const {cid} = payload;   const currentchart = state[cid] || {};   return {...state, [cid]: {...currentchart, ...payload}}; } 

if looking go deeper in terms of property trees, may worth thinking how change shape of data match how using it.


Comments

Popular posts from this blog

Python Pandas join aggregated tables -

java - Static nested class instance -

java - How to access payload from REST 404 response in Camel cxfrs? -