One of the smaller projects required functional changes...so I decided to update version of the Gjallarhorn.Bindable.Wpf library also.
In fact, I just added an additional parameter where it was needed.
But now the application doesn't work correctly because the function callable by command gets calling twice.
The minimal example is below:
type Message = |Number of int
let rand = Random()
let mbindings _ source _ =
let getNumber() =
let number = rand.Next()
printfn "RAND = %A" number //print a number twice
number |> Some
[
Bind.Explicit.createCommand "NewNumber" source
|> Observable.map (fun _ -> getNumber())
|> Observable.toMessage Number
]
let mcomponent : IComponent<int, obj, Message> =
Component.fromExplicit mbindings
let app nav =
let model = 42
let update message _ =
match message with
|Number number -> number
Framework.application model update mcomponent nav
...
let nav = Navigation.singleView Application MainWin
let app = app nav.Navigate
Framework.RunApplication (nav, app)
Is it a bug on the library or I miss something?
This was a bug. It has been corrected in Gjallarhorn.Bindable Beta 6.
The issue was that the framework subscribed to the observable in the binding twice. This is typically fine, but in your case, the observable has a side effect, which was getting run multiple times. I reworked how this is handled in the framework to prevent multiple subscriptions, so it should no longer fire twice if you upgrade to the latest.