4

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!

Source: https://github.com/reactjs/redux/commit/fbe0852a25d4bf9819adfe95fef6aa6702658c07#diff-a7be1d864910aa327225143859006953R30

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?

Tony D
  • 266
  • 2
  • 15
  • It's not that redux is not OO, it's that Backbone's model and Redux uses completely different patterns, which seems are incompatible (but I can't be sure as I've never used redux) – Emile Bergeron Oct 06 '16 at 14:11
  • I don't see how you arrive at that conclusion. No methods attached to 'objects' that are used just as hasmaps, I don't see how that qualifies. – AME Jan 31 '19 at 08:09

1 Answers1

5

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.

DDS
  • 4,325
  • 22
  • 33
  • 2
    Thanks. It sounds like you're saying that the Flux/Redux pattern is best suited to an anemic domain model. Is that accurate? – Tony D Oct 07 '16 at 21:03
  • 1
    I would say yes. I'm not sure the term really applies and I can't say I'm very familiar with it. But Redux is based on the functional programming style. From my understanding the ADM applies in oo environments for adding transactionality. Redux is transactional in the sense that an action either completes or had no effect, but more than anything it's based on being functional. – DDS Oct 07 '16 at 21:19
  • 1
    I just found this, which is also pertinent: http://stackoverflow.com/a/32922984/6439734 – Tony D Oct 14 '16 at 02:53