Reputation: 508
I have an function that accepts populateKey
as a parameter and this parameter gets passed on and used in my new state named substate. The substate now looks like this: let subState = _.get(state, "meta.populate." + populateKey);
. Is there any way in Immutable to accomplish the same?
EDIT: I now used this method: see screenshot, but I get "state.updateIn" is not a function. Any reason why that is the case?
Upvotes: 0
Views: 79
Reputation: 203241
There's Map#getIn()
:
// Example state
let state = Immutable.fromJS({ meta : { populate : { someKey : { some : 'value' } } } });
// Get the substate
let populateKey = 'someKey';
let subState = state.getIn([ 'meta', 'populate', populateKey ]); // Map { "some" : "value" }
This obviously assumes that state
is an Immutable object and that any changes to it are also propagated throughout your app as Immutable objects.
Upvotes: 1