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

How to create static OneWaySeq binding? #596

Open
xperiandri opened this issue Apr 2, 2024 · 6 comments
Open

How to create static OneWaySeq binding? #596

xperiandri opened this issue Apr 2, 2024 · 6 comments
Assignees

Comments

@xperiandri
Copy link

High-level description
I want to create a static OneWaySeq binding. How to define it?

Additional Information
Elmish.WPF version: 4

@TysonMN
Copy link
Member

TysonMN commented Apr 3, 2024

@marner2?

@marner2 marner2 self-assigned this Apr 3, 2024
@marner2
Copy link
Collaborator

marner2 commented Apr 3, 2024

@xperiandri Could you expand in more detail what exactly you want to get done? There are a lot of things this could mean. The main one is a XAML {x:Static Class.StaticObject} binding, which we use for design-time view models in our examples. The other main one in the context of this project is the statically-typed bindings.

Preferably, please provide a link to a working example repository that can be viewed publicly for easier discussion. Examples are much easier to talk about.

@xperiandri
Copy link
Author

I mean Binding.oneWaySeq inside a statically typed view model:

    member _.User = base.Get () (Binding.OneWayT.id >> Binding.mapModel (fun m -> m.User))
    member _.RecentBuildings = base.Get () (Binding.oneWaySeq ((fun m -> m.RecentBuildings), (=), id))
    member _.RecentAssets = base.Get () (Binding.oneWaySeq ((fun m -> m.RecentAssets), (=), id))

    member _.SearchFilter = base.Get () (Binding.TwoWay.id >> Binding.mapModel (fun m -> m.SearchFilter) >> Binding.mapMsg (fun s -> SearchFilterChanged s))
    member _.FindCommand = base.Get() (Binding.CmdT.setAlways Find)

@xperiandri
Copy link
Author

Any ideas? Was this scenario considered?

@marner2
Copy link
Collaborator

marner2 commented Apr 9, 2024

Ah, that looks like an oversight on my part when porting everything over. Binding.oneWaySeq under the hood returns an ObservableCollection<'T> when given any seq<'T>. In this case, it gets boxed to an obj before being applied to the member. You do lose the type information for that member, but it's perfectly safe to use those old bindings in a statically typed view model (in fact, the only thing the "T" functions do differently is not box the output of the corresponding non-T ones).

This is an aside, but I noticed your _.SearchFilter member is still using Binding.TwoWay.id. See /src/Samples/SubModelStatic.Core/Program.fs#L40 for an example on how this works with two separate bindings for get and set of two way properties.

@xperiandri
Copy link
Author

xperiandri commented Apr 10, 2024

Actually, I use the port of Elmish.WPF to Uno
So I took v4, migrated it from scratch (previously I used v3) and implemented TwoWayT for me as OneWayToSource is not supported in WinUI.
Thanks for suggestion

@marner2 marner2 mentioned this issue Apr 22, 2024
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