davedawkins / Sutil

Lightweight front-end framework for F# / Fable. No dependencies.
https://sutil.dev
MIT License
285 stars 17 forks source link

Props never get updated in WebComponent with elmish #70

Closed pkese closed 1 year ago

pkese commented 1 year ago
let MyComponent (props : IStore<Props>) =
    let store, dispatch = Store.makeElmish Model.init update ignore props.Value
    use propsSubscription = props.Subscribe (PropsChanged >> dispatch)

In above code, PropsChanged message will always get delivered with initial value of props.
Events get fired, but value of props is always the same.

Normal IStore<Props> |> Store.map rendering code appears to work fine (below): Html text is changing correctly.
Just elmish (above) never sees any change.

    Bind.el(props |> Store.map (fun m -> m.text), Html.text)
pkese commented 1 year ago

Eh it was

use propsSubscription = ...

instead of

let propsSubscription = ...

so subscription got disposed at the end of code block.

davedawkins commented 1 year ago

I didn't even know we had use in F# - seems to work same as using (...) { ... } in C#.

I'm glad you fixed it, and thanks for logging the issue