-
-
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
Get the model from event streams #331
Comments
Can you share a link to a GitHub repo that demonstrates what you are currently doing and maybe includes some comments about how you would like it to be different? |
I have created a dummy project to showcase the behavior. Let me know your thoughts. Here is the link https://github.com/Evangelink/Elmish.Wpf.Experiments |
I understand now. Thanks for creating a project that I can run. I think you could achieve your desired behavior given the ability to dispatch a list of messages instead of just a single message. Of course a list can be empty, so that would give you the ability to dispatch no messages. See #321. I also expect the message-mapping feature in Your subscription to the |
In my real app, I am trying to mimic a bookmark feature like in web browsers so I really want the Ctrl + D to work from anywhere within the app and not only when a specific part of the app is focused. Of course, it needs to work only when the page is "active". Regarding the access to an
I must be missing something but I fail to see how the ability to dispatch multiple messages will help in this case? |
I don't recommend calling
Because "multiple" here really means "zero or more". Your binding code could look something like this. "AddOne" |> Binding.cmd (fun m obj -> if shouldAddOne m obj then [ AddOne ] else []) |
As far as I understand this is just changing the How are you or how would you you do something similar? Let's say you want to have undo (ctrl + z) or redo (ctrl + y) or save (ctrl + s) or whatever else and you need both a button (with a |
Oh, two mistakes on my part. I know think that this problem is much simpler than I first thought. First mistake is thinking that we needed support for multi-message bindings in order to dispatch zero messages. The family of
Second mistake is using Anyway, I think what you want is already possible. See this branch. The commit on that branch turns the event into a command and then creates a binding via Is that the behavior you want? |
Your response here makes me think that you don't know it is possible to turn an event into a command. In addition to the branch linked to in my previous comment, see the |
I have a guess for the answer to my question. In the branch I created for you, I turned the |
🤦 I saw the event to command example but totally forgot about it and so went with a complex approach... I will look in details the example, your comments and example and let you know if I have some question. |
This is definitely better than what I was doing... Also with my WPF skills getting back to memory, I think for this exact case of having a view global handler it's even easier if I go with <UserControl.InputBindings>
<KeyBinding Command="{Binding Undo}" Gesture="Ctrl+Z" />
<KeyBinding Command="{Binding Redo}" Gesture="Ctrl+Y" />
</UserControl.InputBindings> where |
I didn't know about this |
I am going to close the issue as I think we sorted it out. Out of curiosity, would you like me to open a PR updating the https://github.com/elmish/Elmish.WPF/tree/master/src/Samples/EventBindingsAndBehaviors sample project or adding a new one with an example of |
I am up for it. What do you think @cmeeren? This is a really just a feature of WPF, so nothing novel, but I didn't know of it. |
Sure! 👍 Try updating the existing EventBindingsAndBehaviors sample. As I understand it, this will just be another demonstration of that. Keep it simple. |
I have started to implement keyboard shortcuts in my application which I am handling through the dispatch mechanism:
(note that I am using observables to make it easy to test the behavior) and I also have a button for the same command. The button is bound using
Binding.cmdIf
which prevents the action under some context but the shortcut can't do the same.So far, I am handling the "invalid" case in the update and return
model, []
in case the state is not good but I would prefer to be able to create some kind of observable state of my model which I could plug into my observable streams.Any suggestion?
The text was updated successfully, but these errors were encountered: