Moving an application from Backbone to MobX
Currently I’m cutting over a fairly large application from Backbone to React and MobX. This started with just writing new features using MobX and then keeping my MobX application state in sync with the Backbone model by subscribing to all the right events.
Now that I want to do a more comprehensive integration, it seems like the easiest path forward would be to wrap my existing global state in an observable and then use it from MobX. However, the data model is pretty old and really needs to be cleaned up. The new data model is something I’m very happy with…
Any opinions on how to keep my legacy data (wrapped in an observable) synced with my new data model? The eventual goal is to destroy the legacy data model… Some things I’ve thought of / tried to some degree:
- build out my new data model and use tons of getters and setters that access the legacy model (in mobx) directly. This would basically be turning my new data model into a view on the legacy model.
- autorunAsync to batch up changes to the legacy model and map those over to the new data model. Is an autorun permitted to invoke an action?
- would a reaction make more sense here? one reaction targeting each field that needs mapping?
- transformer? My reading on this is that it creates new observables, not updating existing ones.
This is my first time posting on Medium, and I’d specifically like to thank Michel Weststrate for his fantastic articles here!