mobxjs / mobx

Simple, scalable state management.
http://mobx.js.org
MIT License
27.51k stars 1.77k forks source link

Question: React-only? #833

Closed spock123 closed 7 years ago

spock123 commented 7 years ago

This project seems really nice but it looks like it's only for React-projects. Is this so?

The documentation, examples and all communication only talk about React , but can it be used as well with other frameworks? (Vue, Angular for example)?

Thanks

spion commented 7 years ago

Vue already comes with its own observables and computed values.

Angular likewise has its own data binding system, however mobx can still bring computed values to the table there. Also has ng2 version. Unless you already have an existing angular project and you really need the performance benefits, its probably not worth the size overhead and the general confusion of having several different ways of doing things.

You can also use mobx with inferno, with Preact or even with virtual-dom (the library).

p.s. I don't know about other React users, but I think this challenge explains why I like React over vue: https://jsfiddle.net/wn90xez2/1/

spock123 commented 7 years ago

@spion Thank you so much. Apologize for the question, this is really a cool project.

I'm using Redux with Ng2-Redux bindings in my current Angular project, but this seems really really great....

Thanks again

spion commented 7 years ago

No apologies necessary! 😸

The above was just my personal "general" opinion, things could be vastly different depending on the needs of the specific project.

hccampos commented 7 years ago

We are using it with Angular and it makes life much easier when it comes to managing state. RxJS is awesome for streams of events and naturally async things, but for keeping and managing state, MobX is much easier. We make our models observable with MobX and serializable with serializr and then we derive most other things from there. The actions to modify the state then go in services that can be injected into the components that need them. In some cases, for practical reasons and when we consider that the component should be "smart"ish we place a few actions in the component itself.

MobX also doesn't require sprinkling | async all over the templates like RxJS does. We have a directive that we use to wrap components that use MobX and it acts basically as the observer decorator in mobx-react. Very similar to ng2-mobx. For now this requires adding an extra element to those components to place the Directive on, but hopefully they'll eventually add support for adding directives to the host component directly via the @Component annotations.

In any case, MobX is indeed a much better fit for React just because React makes it transparent and easy to wrap your components with other components in a nice and functional way. If you have the choice of using React with MobX, I would highly recommend it; if not, go for ng2-mobx and MobX.