-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make so elmish update and cmd loop can run on non-ui thread #552
Make so elmish update and cmd loop can run on non-ui thread #552
Conversation
What is the advantage of doing work in another thread while the UI thread is blocked compared to doing that work on the UI thread instead of blocking? |
If you are only updating the model from actions coming from the UI, there is none. However if you have subscriptions, you can guarantee that when you dispatch from a subscription, the update to the model always happens right away no matter what is happening on the UI thread. This has two potential advantages:
There may be a gotcha with skipping updates and the captured |
…ed to always update view model with latest model rather than captured one)
c4ff716
to
73bf4b9
Compare
Add comments Co-authored-by: Lyndon Gingerich <84735110+LyndonGingerich@users.noreply.github.com>
The basic implementation of this PR would be to invoke all calls to the underlying dispatch on one thread, then invoke all calls to
UpdateViewModel
on the UI thread associated with the window.However, WPF expects events to raise
NotifyPropertyChanged
events before they exit, otherwise things like textboxes will "reset" following the disconnected update coming from the elmish update thread. This causes, for instance, the cursor to jump to a different location as you are typing. This means that we cannot simply invoke the dispatch calls coming from WPF in an async manner - we must block that call until the elmish update thread has processed that update and generatedNotifyPropertyChanged
events. This block is ok, because any dispatch calls from the non-ui thread will dispatch the UI update asyncronously.One of the optimizations is to skip
UpdateViewModel
invocations if there is a pending UI update. This is ok, because calls to this function are transitive (skipping one in the middle still results in the same final state).EDIT: Added a sample project that illustrates the threading capability and how to use it.