FormidableLabs / freactal

Clean and robust state management for React and React-like libs.
MIT License
1.65k stars 46 forks source link

Add support to use immutable.js data structures #51

Open JustFly1984 opened 7 years ago

JustFly1984 commented 7 years ago

Currently All my projects using redux with immutable.js instead of Object.assign approach.

If you do not mind, I could help you and make a pull request of immutable.js lib usage for better performance and all goods which comes with immutability.

JustFly1984 commented 7 years ago

I give up, cos there is no possible way to use freactal with immutable.js

Whole idea of freactal is great, but when it comes to performance, I choose immutable.js on top of redux.

It looks like freactal need complete rewrite to support immutable data types. It is really sad, cos I do not have time to do that.

JustFly1984 commented 7 years ago

Object.assign({}, ... creates new object, which is kind of good, if you do not want to mutate, but Garbage Collector will do it's dirty work each state is update. In my case I can't afford GC, and this is why I'm stuck with immutable.js

After fast lookup into freact source code, I see the MAGIC under the hood and it just doesn't feels right for me.

JustFly1984 commented 7 years ago

Please, put some mention in docs, that there is no support for immutable.js, so people save time.

everdimension commented 7 years ago

@JustFly1984

In my case I can't afford GC, and this is why I'm stuck with immutable.js

I don't get this argument. Immutable.js does basically the same thing that Object.assign({}, /* ... */) does, but with arguably more convenient syntax.

What is it exactly that you couldn't do with this library by using Immutable?

divmain commented 7 years ago

@everdimension is correct - there should be no measurable performance difference between the two approaches. And, in fact, you could use Immutable.js for everything aside from the top-level state container. However, I'll leave this issue open until I decide how I want to address this in the docs. I'm moving to gitbook-style documentation, so it's not an immediate fix.

tomisme commented 7 years ago

there should be no measurable performance difference between the two approaches

Immutable uses structual sharing for some significant performance improvements over Object.assign (for large collections).

JustFly1984 commented 7 years ago

Exactly. Structural sharing is the main feature of immutable.js for me.

2017-06-29 9:55 GMT+08:00 Tom Hutchinson notifications@github.com:

Immutable uses structual sharing https://medium.com/@dtinth/immutable-js-persistent-data-structures-and-structural-sharing-6d163fbd73d2 for some significant performance improvements over Object.assign (for large collections).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FormidableLabs/freactal/issues/51#issuecomment-311840406, or mute the thread https://github.com/notifications/unsubscribe-auth/ACJsef2Gj4DiGYMS6GExvHYByJBYj3VPks5sIwP7gaJpZM4NYZRV .

divmain commented 7 years ago

Alright, I'm convinced. I'm going to look into what it would take for the data-store to be pluggable, allowing the dev to use the default, immutable.js, or some other alternative.

JustFly1984 commented 7 years ago

Can't wait to see your progress)

JustFly1984 commented 7 years ago

I wanna give you heads up. There is an article: https://medium.com/azendoo-team/immutable-record-react-redux-99f389ed676

Current issue I'm experiencing, that it is not possible to use Immutable.Record as rootReducer initialState with redux-immutable combineReducers. Can you please think through an Idea to have Immutable.Record as main initialState? It has very nice API which is very close to native JS API.

JustFly1984 commented 7 years ago

Do you have any updates on this issue? I'm eager to try it out in my next project.

ryan-roemer commented 7 years ago

@JustFly1984 -- Can you open up a minimal repository with a sample app that uses Immutable the way you'd like to with freactal so we have something easy and tangible to work with as we develop out support for immutable?

If you're up for this, please also provide install, build, and dev instructions that so that we can make sure we're on the same page for supporting your use case. Thanks!

JustFly1984 commented 7 years ago

Sorry, currently very busy. I can't reproduce my view of behavior. The main idea is that there is a single Immutable.Map data structure in the root instead of standard JS Object, so all reducers added to this Map with something like combineReducers from react-redux-immutable. Currently your freactal uses Object.assign instead of combineReducers. You just can't do Object.assign with Immutable.Map without mutating it. Please invest your time to understand Immutability ideas. The main feature is memory and performance savings on state update. Please read about persistence. Also you could try to experiment using JS ES6 Map and WeakMap as root data structure. Basically you need to implement several adapters for root data structures to support Map, WeakMap and Immutable.Map along with standard JS Object.

2017-10-27 1:08 GMT+08:00 Ryan Roemer notifications@github.com:

@JustFly1984 https://github.com/justfly1984 -- Can you open up a minimal repository with a sample app that uses Immutable the way you'd like to with freactal so we have something easy and tangible to work with as we develop out support for immutable?

If you're up for this, please also provide install, build, and dev instructions that so that we can make sure we're on the same page for supporting your use case. Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FormidableLabs/freactal/issues/51#issuecomment-339734177, or mute the thread https://github.com/notifications/unsubscribe-auth/ACJseZnUp9AWct1tBfYRQUd0311aHDbrks5swLyUgaJpZM4NYZRV .