noderaider / redux-idle-monitor

A Redux component to schedule events at stages of user idleness across multiple browser tabs.
https://noderaider.github.io/redux-idle-monitor/
MIT License
105 stars 9 forks source link

Support Immutable.js #27

Open xnyl opened 6 years ago

xnyl commented 6 years ago

I am using the lib wit redux-immutable store. My state is Immutable.Map(). That causes problem with action.js selectIdleState() function, since the lib is retrieving idle state with state.idle instead of state.get('idle'). That causes error in the console like 'Uncaught Error: idle monitor state should have idle value'. Basides above, the lib works great, I really appreciate your work.

My proposition is to add something like stateTransformer function, configurable with opts. If present, the user will have an option to define how his state is going to be transformed into expected pure JS Object. Like this: const opts = { ... idleStatusAction, activeEvents, stateTransformer: state => state.toJS() // assuming its Immutable.js }

What do you think? Maybe there is an other way to achieve this?

cchamberlain commented 6 years ago

Thanks for opening. I'm definitely open to this, would like it to support Immutable.js. I think the proposal sounds good but its a tad tricky to implement. Would either need to replace the following call, maybe others or integrate it into the redux-mux helper:

https://github.com/noderaider/redux-idle-monitor/blob/master/src/lib/middleware.js#L42

I published redux-mux so happy with either path, just not implementing this at its level would require more changes in this library. Feel free to post a PR, otherwise I will take a look at this the next time I get a chance to work on the project.

hatemalimam commented 5 years ago

as a temporary fix, I have created a fork which works ONLY with immutable.js, might be helpful for someone searching for a solution

https://github.com/hatemalimam/redux-idle-monitor