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

Binding to the calculated property is occasionally breaks in case when IsSynchronizedWithCurrentItem = true #27

Open
FoggyFinder opened this issue May 6, 2019 · 0 comments
Labels

Comments

@FoggyFinder
Copy link
Collaborator

I faced with odd behaviour:

isSWCI

So, there are not only additional calls of the function update here but also failures of the binding.

I'm not sure is it really a bug in Gjallarhorn.Bindable/Gjallarhorn or this is expected behaviour.
But in the last case I would want to know why it happens.

Workaround: exposing immutable object. I.e. in the code below use Seq.toList instead of Seq.toArray.

MCVE:

    <ListBox
        IsSynchronizedWithCurrentItem="True"
        ItemsSource="{Binding TestData}"
        SelectedItem="{Binding Current}" />
open System

[<RequireQualifiedAccess>]
module Views = 
    open FsXaml

    type MainWindow = XAML<"MainWindow.xaml">

open Gjallarhorn.Wpf
open Gjallarhorn.Bindable
open Gjallarhorn.Bindable.Framework

type SomeType = {
    AllData : string
    Current : char
}
with member x.TestData = x.AllData |> Seq.toArray

[<RequireQualifiedAccess>]
type SomeMessages = | SetCurrent of char

let update message model =
    match message with
    | SomeMessages.SetCurrent c ->
        printfn "setCurrent"
        { model with Current = c }

let allData = "test string"
let init = { AllData = allData; Current = allData.[0] }

let appComp : IComponent<SomeType, unit, SomeMessages> =
    Component.create<SomeType, unit, SomeMessages> [
        <@ init.Current @> |> Bind.twoWay (fun m -> m.Current) SomeMessages.SetCurrent
        <@ init.TestData @> |> Bind.oneWay (fun m -> m.TestData)
    ]

let applicationCore nav = Framework.application init update appComp nav

[<EntryPoint>]
[<STAThread>]
let main _ = 
    let navigator = Navigation.singleViewFromWindow Views.MainWindow

    let app = applicationCore navigator.Navigate

    Framework.RunApplication (navigator, app)
    0

code also available in the project IsSynchronizedWithCurrentItemCase here

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

No branches or pull requests

1 participant