3 ms·
One question which always preoccupied me is how those MVC components interact with nesting/recursion. For example, a view may include a scrollbar, which has sta
by layer8 3y ago
One question which always preoccupied me is how those MVC components interact with nesting/recursion. For example, a view may include a scrollbar, which has state, and can be interacted with, sometimes independently from the model displayed by that view. So the scrollbar has it’s own model (containing e.g. the scrollbar position) and it’s own view (responsible for how the scrollbar is rendered) and controller (allowing the user to operate the scrollbar). This nested mini-MVC for the scrollbar however is primarily or exclusively part of the larger view. The scrollbar’s model, however, may have to refer to the larger model, for example when the scrollbar size depends on the size of the larger model’s data. Or maybe its the scrollbar’s controller that queries the larger model (or gets notified by it) and then updates the scrollbar’s model. In any case, it’s not obvious how exactly the nesting could or should work.
More complex cases are for example a combo box, which consists of a text input, a dropdown button, a dropdown list, which in turn may have a scrollbar. And this is just one relatively basic control within a potentially much more complex UI.
I’ve never seen a systematic treatment of that topic. Given that UIs use nested controls, one would think that this would be widely addressed by architectural patterns for UIs.
- mejutoco 3y agoThe approach Elm uses is every event goes through a main "router", no exceptions. If you want to do sth special on the account page modal scroll, you issue a specific event for that, and deal with it in the same way as any other. It is a very simple and clean model, but not complicated enough for some people :) of course it helps that with a good type system you can catch missing or incorrect cases.
- EVa5I7bHFq9mnYK 3y agoThis is what MVVM is for. Last two letters mean View Model - a model of the view - data structures for each user control, and code that synchronizes these structures with Model structures.
- layer8 3y agoBut that’s not a recursive pattern. I would disagree that there is only a single level on which MVC, MVVM, or whatever, is relevant. For example, the controller or View Model of a view containing a combo box should not have to manage the internal mechanics of the combo box. So it makes sense for the combo box to have its own internal MVC/MVVM. Similarly, the view may be embedded into a larger dashboard, where the dashboard should not have to manage the internals of the view, but would have its own MVC/MVVM.