elmish / Elmish.WPF

Static WPF views for elmish programs
Other
421 stars 68 forks source link

Improve threading behavior #575

Closed marner2 closed 10 months ago

marner2 commented 10 months ago

Adds a caching feature for setters which allows us to notify property changed within the setter rather than waiting for UpdateModel to be called (which is more idiomatic within MVVM).

With this in play, the threaded behavior no longer has to block on potentially expensive ViewModel Updates in order to guarantee well-behaved TwoWay bindings on TextBoxes. Instead, we can schedule ViewModel Updates so that they "drop" intermediate Updates when they start piling up. This is possible because ViewModel Updates are fundamentally transitive with MVU. So for example, vm.Update(model1); vm.Update(model2); vm.Update(model3); always results in the same final view state as vm.Update(model1); vm.Update(model3);

This latter behavior only applies to Elmish in multithreaded mode. It does not change the normal singlethreaded behavior at all.