Reputation: 266
I come from an OOP background and I'm learning Redux. It seems the more I learn about Redux, I realize how it contrasts with the OOP paradigm by employing more functional constructs.
That said, I've never used Backbone, but I came across this in the redux docs regarding migrating from Backbone models:
Backbone's model layer is quite different from Redux, so we don't suggest mixing them. If possible, it is best that you rewrite your app's model layer from scratch instead of connecting Backbone to Redux...
Source: https://github.com/reactjs/redux/blob/master/docs/recipes/MigratingToRedux.md#from-backbone
Moreover, I found that initially, this simply read:
Sorry, you’ll need to rewrite your model layer. It’s way too different!
Sooo... Is Dan saying to rewrite you model layer because models, (such as those from Backbone) are OO in nature and redux prescribes to a more functional paradigm?
Upvotes: 4
Views: 841
Reputation: 4375
Yes and no. You need to rewrite your data stuff to not be models but POJOs in the state. They can look a lot like models and they are definitely objects, but they can't have methods. Well, technically they could and it may not even be a problem, but it's discouraged because the state ought to be serializable.
Because I like setting properties and calling methods more than I like dispatching actions, and because I like to attach my code to my data, I wrote a library that lets you use models instead of the standard Redux action creator/action/dispatch/reducer paradigm. Under the hood, it's 100% Redux, but the Dev API is all OOP. This way it has all of Redux's benefits and all OOP's benefits. You may find it alleviates some of the concerns you voiced.
But you still have to rewrite your model layer.
Upvotes: 5