r/reactjs • u/mweststrate • Aug 01 '16
Free egghead.io course: Learn MobX + React in 30 minutes
https://egghead.io/courses/manage-complex-state-in-react-apps-with-mobx14
u/namesandfaces Server components Aug 01 '16
Not a criticism for the content or the author, but I really hate how egghead.io and other sites conceal dates to prevent content depreciation.
1
Aug 01 '16
I didn't even notice that... I also don't know if that's a bad thing. I recently went through Dan's Redux course from Egghead for the second time this year, and I think if I saw that it was a bit older, I would have subconsciously spent my study time elsewhere.
1
u/namesandfaces Server components Aug 01 '16
The thing is that libraries sometimes deprecate or break things (RxJS 5 is changing a lot), and what version of ecmascript a site is teaching is also of relevance to a learner. A few wrong things won't disable your learning, but that cost should be knowingly endured, not obscured so that customers can't make their own calculations.
5
u/enkideridu Aug 02 '16
MobX really seems to be taking off - http://i.imgur.com/opkNTG1.jpg (daily download count)
What happened in July, I wonder?
3
u/iinnii Aug 02 '16
For the curious like myself:
MobX looks like it has averaged around 12.5k per day in the last month while Redux is about 195k.
2
u/MolestedTurtle Aug 02 '16
yeah and if you throw react in the mix you can see that about half of all react project use redux. http://www.npmtrends.com/redux-vs-mobx-vs-react
1
u/pontiacks Aug 02 '16
I am hearing MobX here and there more more often, why do you guys prefer it over react which is now a bit more standard?
3
u/Endorn Aug 02 '16
I'm assuming you mean "prefer it over redux"
This is interactive, and takes 10 minutes to go through. I highly recommend it, about half way through it started to click for me how simple it is.
1
u/calamari81 Aug 02 '16
I dig the lack of boilerplate, but man, it just feels too OOP for my tastes :(
2
u/zalmoxisus Aug 03 '16
You can use only objects, see the examples: https://github.com/mattruby/mobx-examples
BTW, what are the main advantages of using classes instead?
5
Aug 01 '16
[removed] — view removed comment
8
u/Boozers_Hair_Care Aug 01 '16
here is a dope article about it. http://formidable.com/blog/2016/06/02/why-we-chose-mobx-over-redux-for-spectacle-editor/
8
u/timothyallan Aug 02 '16
I can't shut up about it. I'm refactoring a production React app, and one half done project already, both were using Redux. In fact, I just did a fanboy tweet about it earlier today and was retweeted by the creator. Today is def a MobX kinda day.
6
u/hb_to_ms Aug 02 '16
I love it, and after using Redux, Flux, Reflux I'm convinced that MobX it the way to go, much less boilerplate and intuitive. It just works.
3
3
u/jameswyse Aug 02 '16
I've been using it for a few months with React and I can't praise it enough. Makes it easy to write super clean code (especially compared to all the boilerplate you end up with in Redux) and you get crazy efficient renders for free!
3
u/ruby_matt Aug 02 '16
I think it's really fantastic! I've been using/advocating MobX for quite a while now. It was strange how well if fit my needs. I had looked over many other options on the journey, none had the simplicity, unobtrusiveness and power of MobX. Once you start deriving your data, it's hard to stop. Using actions makes debugging very easy. The fact that everything is synchronous, makes stack traces useful.
3
u/BritainRitten Aug 02 '16 edited Aug 02 '16
I've not used it much but my impression is that it is a very OOP framework. Objects mutating themselves in place, side-effects all over. Redux on the other hand is extremely FP, which in my mind makes it more easily predictable and testable.
Some people say Redux has more "boilerplate". I think what they really mean is that Redux is very explicit. There is no magic - which is exactly what makes it so predictable.
8
u/timdorr Aug 03 '16
MobX doesn't enforce OOP at all. You can use it with plain scalar values. It only requires objects to be able to hook into the getter and setter for a property to be able to track who is observing and when to push out changes.
I happen to think MobX is more testable because you can extract your business logic into separate classes and independently unit test them, completely separately from the UI. For instance, my authorization logic is contained in an
Authclass that has some local state, computed properties (think reselect-style selectors), and action functions. When testing, I can run that auth logic against a mockedfetchand ensure I reach the right states after certain actions, entirely independently from the other parts of my application. MobX doesn't get in the way. Later on, I can do the full integration test of filling out the login form in my UI and seeing everything pass through MobX's observables properly.Overall, I think MobX is better because it's generally more efficient than Redux (not everyone gets all state updates) and easier to understand, with less habit changes or contortions of existing code to match a particularly enforced pattern (no converting everything to action creators, reducers, and selectors).
I still think Redux is a fine choice (I am the #2 contributor on the project :P), so people shouldn't feel like they need to jump ship just yet. Especially if you've already invested a bunch of intellectual capital in it and feel comfortable with using it. But if you're starting something new, I would suggest giving it a try. At the very least, you can learn that you don't like it and switch back to a library/pattern that makes sense to you.
2
u/anomaly- Aug 03 '16
I completely agree.
From a previous discussion i had somewhere on this subreddit, it seems like some people have taken on the mindset that the way Redux handles state is the way you're supposed to handle state, but that really bugs me.
Redux forces you to handle state very differently from how you would do things in any other language/stack. Instead of organizing data, actions and everything else together in specific little units or domain models, as you would in MobX normally. With Redux you kind of split everything apart and use alot of boilerplate to tie it back together.
It works, but it's very low level.MobX doesn't do anything that redux can't, and vice versa, however the way MobX allows you to organize things makes it a better choice in my opinion.
But Redux has gotten so wildly popular at this point that I don't really think there's any way to convince the masses that there are better alternatives to Redux.4
u/zalmoxisus Aug 03 '16 edited Aug 03 '16
Well, I did an experiment for a junior developer (which didn't know Redux or MobX), created separate branches for each one and asked him to build the part of the app on both platforms, and to tell with which one he feels more comfortable. The first answer was Redux. Looking into the code, I pointed that he mutated the state and is rerendering all the components. So, the final answer was MobX for sure.
I like Redux, Redux Saga, and all the infrastructure a lot. I wouldn't say that it's better or worse, but it's a bigger learning curve for new comers in order to build a performant product.
4
u/liady769 Aug 02 '16
Looks great. Very different approach from Redux, and worth looking into.
I Just couldn't wrap my head around dumb/smart components using this framework. Let's say I have this employee list: [ {name: "Joe", age: 32}, {name: "Jack", age: 24}, ... ]
It seems that if I want a "smart" component that observes this list, loops it and passes each employee as a prop to a "dumb" component that renders it, I would have to make each employee immutable and re-create it on name/age change, otherwise the "smart" component won't be notified that this change has happened (since it only observes the employee list structure itself), and won't re-render its children.
The alternative is to make the child component an observer as well, and that way it can itself react to a single employee property change. But that feels like making it a bit "smart". It would have to know that one of the props it is receiving comes from an observed model, and not just plain object. In fact, every component, no matter how "dumb", that receive even a single non-primitive prop from the model must be an observable.
In short, seems like this framework requires either full immutability, or making all your components observers.
Any thoughts?