3 ms·
And hence the general recommendation of having a single direction in your input/render cycle: - wait for input - a dispatcher take any input and turn it into
by BiteCode_dev 4y ago
And hence the general recommendation of having a single direction in your input/render cycle:
- wait for input
- a dispatcher take any input and turn it into a queue of model update actions
- pop queue to perform latest model updates.
- trigger a full tree rendering, passing the new model
- start again
So:
- the model is a dumb static data structure
- the dispatcher is the responsible for model updates and is a single entry point for the data flow
- the UI and the model don't know about each other
That what ELM, react and so on do now. Monodirectional MVC. It's hard to optimize the rendering though, but it's way easier to reason about when concurrency gets high.
- mejutoco 4y ago> - trigger a full tree rendering, passing the new model I agree the Elm model makes it easy to reason about it. Just because we pass "the state of the world" each time instead of mutating it, does not mean that we need a full tree rendering. That is an implementation detail. We can update just the relevant part. If we think of it mostly as pure functions a lot of it is easier to memoize and — for same input — it is possible to return the same output straight away.
- BiteCode_dev 4y agoThat's what I mean by hard to optimize. Memoization is hard to get right, because if you compare only by value, it can be slow, but if you compare by identity, the cache can take a lot of memory. And of course, forcing a purely immutable model comes with its own unique challenges.