wix-incubator / redux-cornell

A Redux library which helps reduce boilerplate
MIT License
34 stars 4 forks source link

Support Immutable.js #1

Open bohdanbirdie opened 6 years ago

bohdanbirdie commented 6 years ago

Hello @eyaleizenberg! First of all - thanks for your work on this project, I like it!

I'm the guy who had a microphone on the Q&A session right after your speech on the Odessa.js 2018 and asked about Immutable.js. I haven't tested you lib yet, but it seems like it won't work with immutable library, which is pretty popular on the react-redux community. Here are some examples of it used with React:

Best of luck with the project! Thanks!

eyaleizenberg commented 6 years ago

Hi @bohdanbirdie , Thanks for your feedback!

Can you maybe offer up ideas on what you would like to see here for immutable.js?

bohdanbirdie commented 6 years ago

@eyaleizenberg basically, some people like to use an immutable map or list instead of object and array with respect. This will convert the store to one solid Map object, or whatever kind of data structure developer prefer.

So for cases when a developer decides to create the store as an Immutable.Map

const initialState = Immutable.Map({});

Which will be passed to your corneel constructor,

export interface IConstructorOpts {
  initialState: IState;
}

So returning a new object in the reducer won't work. https://github.com/wix/redux-cornell/blob/master/src/superReducer.ts#L8

return { ...state, [action.reducerKey]: toggleState };

Instead, we need something like

return state.set(action.reducerKey, toggleState);

My experience isn't too big for such decisions, but it might make sense to use the strategy pattern to select whether to use immutable.js API or not. https://github.com/torokmark/design_patterns_in_typescript/tree/master/strategy