ImmutableJS fromJS call not working

The docs say “If you are using the Immutable-js in your web app, instead of the Immutable.Map() , call the Immutable.fromJS() which converts deeply nested objects to an Immutable Map .” (https://docs.sendbird.com/javascript/quick_start#3_use_functions_of_sendbird_objects_with_immutable_js) but the fromJS call on SendBird objects just returns a plain object. I have no issues with ImmutableJS outside of this issue, our entire redux store uses it.

Anything I am missing here?

Just to prove what I am seeing here are is an image:

You can see calling fromJS is not turning the object immutable.

Hi There,

The purpose of using immutable JS is to make deep copies of the channel objects as they are mutable by nature. I found this particularly important if trying to keep within the bounds of Redux.

I’m not quite clear what the issue is. Your screen short doesn’t indicate if the fromJS channel objects is a deep copy of the first channel object.

One thing to note, not all sendbird channel objects inherit from the parent SDK. If you fetch a particular channel or a list of channels they will inherit the methods of the parent SDK. However, if the channel object originates from a channel event handler then you only have access to its data and not any prototypes.

The problem is that the fromJS call is performing the deep copy but returning a plain object instead of an immutable object.

When you create an immutable object like this:

const obj1 = fromJS({ test1: { test2: 'test' } });

You can access inner objects with:

console.log(obj1.get('test'));

And you will get an immutable Map back:
Screen Shot 2020-06-02 at 4.22.13 PM

The problem is that when using fromJS on a SendBird object like this where action.conversation is returned from the SendBird JS client:

const obj = fromJS({ conversation: action.conversation });

and then trying to access it with this:

console.log(obj.get('conversation'));

You get a deep copy of the object but it is not an immutable object, instead just a plain object (see image in next post)

Screen Shot 2020-06-02 at 4.24.05 PM

I looked a bit deeper and I was able to solve it from this StackOverflow post: https://stackoverflow.com/questions/40661729/immutable-fromjs-is-not-deep/44148628#44148628 but that removes the prototypes which is obviously not ideal so I will need to keep the SendBird objects as plain objects in my redux store.