Elmish.WPF
Elmish.WPF copied to clipboard
Application helpers?
Hey there,
There are a couple of helpers (types & functions) that seems to be reusable patterns and I am wondering if they could/should be part of the Elmish.WPF framework or maybe even some global Elmish as maybe some could also be used in Elmish web. I am sure there are some helpers you have also defined and generally reuse hence this question/proposition.
Some ideas:
- application state (normal, busy, showing modal, ...)
- request (DU with Start, Cancel, Finish)
- Undo/Redo
- helpers to get to background thread, UI thread for functions but also async.
- as it's not possible to use datatemplateselector, I am usually defining the various views at once and using visibility to "select" the view. There might be a few generic helpers we could provide.
- Undo/Redo
I created this undo/redo code that doesn't even depend on the Elmish NuGet package, but it is intended to be consumed by an Elimsh application. I did not make it into a NuGet package.
- helpers to get to background thread, UI thread for functions but also async.
In my application at my (former) employer, I wrote several functions to do this. Most of the work was creating a function-based API for the Async<_> type. Some of it can be tricky because getting the correct signature doesn't mean it has the right behavior. Subscriptions and commands are executed on the UI thread (though not synchronously as we recently discussed in issue #403), so I never found a need to move execution back to the UI thread from a background thread.
There are a couple of helpers (types & functions) that seems to be reusable patterns [...]
In my application at my (former) employer, I defined this type (after dropping the suffix Msg) in an AutoOpened module because I find the OutMsg with translator pattern so useful.
https://github.com/elmish/Elmish.WPF/blob/1bf4d28c238671d990736e4030792b53776b2927/src/Samples/SubModelSeq.Core/Program.fs#L9-L11
[...] I am wondering if they could/should be part of the Elmish.WPF framework or maybe even some global Elmish as maybe some could also be used in Elmish web.
I only want to add code to Elmish.WPF if it is specific to WPF (while keeping at eye out for what is truly unique to WPF and what can be shared with Elmish.Uno...c.f. issue #364). For everything else, the easiest thing is to simply share the code (like I did for undo/redo) or write about it. A more streamlined solution is to package up that code via NuGet and maybe even host it from within the Elmish organization.
- as it's not possible to use datatemplateselector, I am usually defining the various views at once and using visibility to "select" the view. There might be a few generic helpers we could provide.
Yes, I do that too. It is a bit annoying, but I don't know of a better solution. This is specific to WPF, so we might be able to add something one day that helps with this.