Comments (1)
Hi! Thanks for your comments. I fixed the readme links.
You're right, you could put all the redux actions, action creators, reducers and selectors in a single file since they are all just a bunch of "loose" variables. Some people find that breaking things into files provides some order - and prevents you from having to scroll in a massive file. But those things really do belong together, so having every branch of the state tree in a single file would make life easier. My criticism against redux isn't so much the number of files, but the lack of structure, and the onus on the developer to try to keep all these variables and concepts organized.
Redux is extremely useful (speaking from experience) when developing a large and complex applications where you want to trace all actions and updates to the state.
This is often mentioned as the great benefit to redux – that the extra effort required will payoff as your application grows. However, I don't see how this is true. If simple things (like the app in the shootout) are verbose and somewhat complicated, how will that help when trying to build more complicated things?
In my experience, adding a variable to a redux store (e.g. tracking the state of a toggle control) requires an action, an action creator, a reducer, a selector, and then separate methods to wire up the setter (mapDispatchToProps
) and the getter (mapStateToProps
). In comparision, adding a variable to a MobX store is a one-liner, injecting your store into a component is another one-liner, and accessing the variable (for setting or getting) is another one-liner.
but I would be worried about long-term maintainability for larger projects, as well as compatibility with future versions of React.
That seems like just FUD to me. Why would shorter, simpler, more readable code be harder to maintain? MobX is not magic. It tracks which components access variables in the store, and then if the value in the store changes, it triggers a render on those components that accessed the variable. It's a powerful concept - and I'm still finding amazing new things you can do with MobX.
For example, reactions allow you to run any arbitrary code when when a store value changes. So, let's say that after a login, the server returns a userId
, and then you need to hit a different endpoint to pull more info about the user. In your store, if your userId
is observable, you can add a reaction to fire off code whenever the userId changes. Simple. With redux, you'd have to listen to the SET_USERID
action, and create/dispatch another FETCH_USER_PROFILE
action, which would be used to trigger a saga/thunk. It's more verbose and "spread out". (And you had better hope that you never want to rename your actions, because refactoring the action constant, action creator, reducers, etc. is painful chore.)
Hooks should also make it simpler to roll your own state management
Maybe, but I'm skeptical. React wants everything to be a component (e.g. higher-order components, container components), but keeping the data model out of components seems cleaner to me. But I'm always interested in ways to write simpler, more elegant code.
from mobx-redux-showdown.
Related Issues (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 mobx-redux-showdown.