I am using React, Redux & Immutable here. The question is regarding merging a plain Js object into Immutable Map obj.
Importing Immutable.js:
import { List as iList,
Map as iMap } from "immutable";
action.payload is this:
{
Preview : {
tabClass : "tabPreview tab activeTab"
},
Body : {
tabClass : "tabBody tab"
},
Sleeve : {
tabClass : "tabSleeve tab"
}
};
InitialTabState created with 'Immutable.js' is this:
const initialTabState = iList.of(
iMap({
tabClass : "tabPreview tab activeTab",
tabName : "Preview"
}),
iMap({
tabClass : "tabBody tab",
tabName : "Body"
}),
iMap({
tabClass : "tabSleeve tab",
tabName : "Sleeve"
})
);
The reducer function, which is merging the action.payload at the top, into the InitialTabState above is this:
const tabsState = ( state = initialTabState, action ) => {
let payload = action.payload;
switch( action.type ) {
case( ENABLE_TAB ):
return (
state.map( (obj) => {
let curObjName = obj.get( "tabName" );
return (
obj.merge( payload[ curObjName ][ "tabName" ] )
);
})
);
...
};
However, nothing seems to be happening. I do not get any error, the output object remains the same as InitialTabState, when the property tabClass within it should change as per the merge function from Immutable.js.