Skip to content
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

Application helpers? #408

Open
Evangelink opened this issue Aug 14, 2021 · 4 comments
Open

Application helpers? #408

Evangelink opened this issue Aug 14, 2021 · 4 comments

Comments

@Evangelink
Copy link
Contributor

Evangelink commented Aug 14, 2021

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.
@TysonMN
Copy link
Member

TysonMN commented Aug 15, 2021

  • 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.

type InOutMsg<'a, 'b> =
| InMsg of 'a
| OutMsg of 'b


[...] 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.

@YkTru
Copy link

YkTru commented Sep 21, 2024

@Evangelink I think this is a great idea, have you had any success implementing some of it? Could you share some examples/code samples? I think the best thing for now would be to create a repo where any user can propose their helpers/patterns etc. so we can browse them at a unique place (instead endlessly searching/reading posted “Issues”) and discuss how to refine these.

@YkTru
Copy link

YkTru commented Sep 21, 2024

@TysonMN You seem to have many of these scattered throughout the “Issues”/“PR” posts, do you have personal nugets/class libraries of such templates/features/helpers that you could share with all of us (I am aware of Undo/Redo, but sometimes some links are "404" broken)? It would certainly help a lot. Thank you very much

@TysonMN
Copy link
Member

TysonMN commented Sep 22, 2024

I have nothing private. Everything is in this GitHub repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants