1

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.

1
  • What do you expect the state to look like when it returns from the reducer? Commented Apr 9, 2016 at 13:04

1 Answer 1

1

obj.merge( payload[ curObjName ][ "tabName" ] ) merging a property that doesn't exist on the payload. I believe you want obj.merge( payload[ curObjName ]), which will update the tab's classes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.