I am trying to learn how to use Immutable.js properly. I found this article: http://frontendinsights.com/immutablejs-with-redux-his-best-friend/.
It has a following code snippet:
const initialState = Immutable.Map({ counter: 0 });
const reducer = (state, action) => {
switch (action.type) {
case 'INCREMENT':
return state.set('counter', state.get('counter') + 1);
case 'DECREMENT':
return state.set('counter', state.get('counter') - 1);
default:
return state;
}
};
const store = createStore(reducer, initialState);
What confuses me is that for me it looks like the switch is returning Map as a state.
I tried the immutable with following:
var obj = {
lol: 'trol',
}
var immu = Immutable.Map(obj)
var immu2 = immu
immu2 = immu2.set('lol', 'trollz')
console.log(immu2) // Map {size: 1, _root: ArrayMapNode, __ownerID: undefined, __hash: undefined, __altered: false}
console.log(immu2.toObject()) // Object {lol: "tral"}
I thought that Redux states needs to always be objects.
So, what is Map() actually returning and why is it possible to set that as a Redux state?