staltz / ama

Ask me anything!
https://blog.sindresorhus.com/answering-anything-678ce5623798
93 stars 1 forks source link

Separate model and view layers #23

Closed marcusradell closed 7 years ago

marcusradell commented 7 years ago

Hi, I've found myself using a pattern where I do the model layer first for a component and then send it in as an argument to a viewable component that then extends the model object with a view. I've found myself liking that pattern, but still feel like I'm missing out on a great community that cycle.js have.

Is there some way to structure your application in an idiomatic way in cycle.js so that I can have a model that doesn't know about the view, or what kind of transport system (http or websockets) that is being used, but still setup the logic?

Reference component: https://github.com/marcusnielsen/reactive-tournament/tree/development/src/components/button

Good luck with the scuttlebutt stuff! I'm counting on you :-)

staltz commented 7 years ago

I feel like we've always done this separation with Model-View-Intent. You could add a viewable or ViewModel in between the model and the view, it's just a matter of making a function wrapping the view function. Check a real world example of model view intent https://github.com/staltz/matrixmultiplication.xyz/tree/master/src/Matrix

marcusradell commented 7 years ago

Snap! I misunderstood Intent as a part of the model, but looking at it now it seems more similar to a Redux action creator.

Thanks a bunch!