Comments (9)
ImmutableJS also offers nicer syntax for reducers, like:
state = state.setIn(['playlist', 'current'], song);
The downside is that the mapStateToProps()
function, and the usage of the objects on the React side must also use get()
to get usable data.
from react-boilerplate.
I'm not sure I feel comfortable making developers use that abstraction. Remove Immutable is probably harder than adding it in after the fact.
We could add some documentation on how you would go about adding it though, so people who want to use it have a tutorial right at hand!
from react-boilerplate.
Cons:
- Another dependency (increased bundle size, etc.)
- not a standard API (access via get, set, and other functions)
- Incompatible with combineReducers, redux-[simple-]router
Pros:
- Forces immutability
- Rich API for collections and maps with nice optimizations like Seq
I suggest that you do your best to put all direct access to state in no more than one or two places. For example - wrap the state with an abstraction that the reducers will call. You can also implement mapStateToProps there.
Within - it'll be a simple Object.assign - but anyone can change to immutable.
from react-boilerplate.
Mapping from ImmutableJS to plain JS in few places will force the developer to use .toJS()
- basically exporting the Immutable tree into plain JS (Heavy memory & performance impact).
Not tested, but feels like unless one uses Immutable fully - there will be no performance/memory gains (quite the opposite).
From Doron's comment it sounds like, unless you need all the extra structures of ImmutableJS - it should be avoided.
from react-boilerplate.
@zavelevsky that sounds interesting, being able to swap in Immutable quickly would be a big plus. To be honest I have no idea how one would go about doing this, would you be able to submit a PR? I'd love to see that!
@borisd I'm thinking, it's a useful tool if you're working across a massive team on a massive app, but until then it's kind of a bit too big to include. That's why what @zavelevsky suggested sounds really good, get all the benefits but none of the drawbacks, and you can swap in Immutable on short notice!
from react-boilerplate.
Maybe a clarification is in place (based on @borisd comment) - I'm against passing the entire state tree/object to components - so there's no reason for any component to access the state directly.
Even "controller component" does not access the state directly in redux - they get what they need via props because of mapStateToProps of redux-react @connect().
So in any case you break the state tree to more or less primitive props. You don't have to use toJS on the entire state - you can fetch what you need selectively.
The exception here being huge collections which admittedly aren't handled well in any of the cases (how do you deep copy a huge collection when you perform Object.assign?). Huge collections usually require special treatment anyway.
So - in order to read from the state you simply implement mapStateToProps in a way that reads the desired fields from the immutable Map and from there it's passed via props. To me it makes sense.
No risk of anyone mutating the state anywhere - as the state is only manipulated in one place - and there it's an ImmutableJS Map.
from react-boilerplate.
@zavelevsky I see what you're saying, but to be honest I don't think including ImmutableJS by default is a good way of going.
Redux enforces a (more or less) immutable app structure by default. (in the sense that you cannot do globalApplicationState = someObject;
anywhere)
ImmutableJS might be nice to have on bigger teams to explicitly remind and keep people from ever setting the state, but the boilerplate already isn't very beginner friendly and adding even more magic won't make it easier on them.
I think ImmutableJS is a nice lib itself, so adding a section on how to use it with the boilerplate to the advanced documentation would be nice - would love a PR about that. (I've added it to the documentation todo list in #14)
from react-boilerplate.
I've reconsidered using ImmutableJS and have opened a new issue/discussion, see #129
from react-boilerplate.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from react-boilerplate.
Related Issues (20)
- Redux Saga API is being called twice yet the action is dispatched only once HOT 1
- npm setup failed: `Error: could not resolve` HOT 4
- The DLL files are missing. Sit back while we build them for you with "npm run build-dll" HOT 1
- not working on macbook
- Include relative static files from index.html HOT 3
- Migration from old boiler plate to CRA base boiler plate
- updating node 12 to node 16 HOT 1
- micro frontend structer HOT 1
- upgrade package and project HOT 1
- ngrok - platform darwinarm64 is not supported HOT 3
- caniuse-lite is outdated HOT 1
- Not able setup react boilerplate on Windows 10 Home Single Language
- Existence of security vulnerabilities
- opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error'
- Actions calling in different containers HOT 1
- Install New Project
- your website is down
- upgrade the project from react-boilerplate to cra-react-boilerplate
- migrating to react-router-dom v6 HOT 1
- How to migrate from react-boilerplate to react CRA? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-boilerplate.