Recommendations about implicit state
See original GitHub issueWorking with Cycle I often find myself in situation where some issue can be solved with either implicit or explicit state. For example, we have a toggler. Toggler has 2 states: favorite and non-favorite.
Implicit state
Intent relies on HTML class to produce both favup$
and unfav$
observables.
So some state is implicitly encapsulated in DOM. This reminds our old days with jQuery where ALL state was in DOM so DOM served as XML database. It was imperfect, though worked to some degree.
Short: fat Intent, skinny Model.
Explicit state
Intent produce just toggle$
observable. It’s a model purpose to decipher it. In many cases will require to have scan
in Model, because scan
is one of the few stateful methods.
Short: skinny Intent, fat Model.
Second option is probably both more complex and more “idealistic”. On the other hand, Intent barely deserves it’s name when it’s completely pure and state agnostic…
This question is obviously non-Cycle specific. But I wonder: are both approaches conventional from the author point of view? If implicit state is properly encapsulated, can it still cause some unwanted consequences later? Should we avoid implicit DOM state in Cycle whenever possible or not? Or both are fine and it’s a developer task to decide when it’s time to switch from Implicit to Explicit?
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
I prefer explicit. Skinny Intent is not a problem. Sometimes it really is skinny (specially on click events), sometimes it’s not (when doing voice recognition for instance, you need to run an algorithm. The best place to put it in is Intent).
If it causes some unwanted consequences, then it’s not properly encapsulated. 😉
Yes we should avoid.
I recommend explicit, and to clarify some potential fears: Cycle is not optimized for minimal boilerplate nor productivity. It’s optimized for separation of concerns. If a developer wants to speed up his development processes, he will often find himself mixing concerns, taking shortcuts. Cycle is not a framework for those types of shortcuts, unfortunately (or fortunately). I’m not saying they are a bad thing, I’m just saying Cycle is not the right tool for that if maximum productivity is a requirement.
Good idea, I’ll make an issue for that.
(do you mind if I close this issue? We can reopen if needed)