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 ListModels in Docs #270

Open
granicz opened this issue Sep 24, 2023 · 0 comments
Open

Binding ListModels in Docs #270

granicz opened this issue Sep 24, 2023 · 0 comments
Assignees

Comments

@granicz
Copy link
Member

granicz commented Sep 24, 2023

Given shoppingCart, a ListModel<string, (Product * int)> value, meant to model an imaginary shopping cart with products identified by a string key, one ususally tries the following variants to bind it to reactive DOM:

// 1. Works
shoppingCart.View.Doc(fun cart ->
    cart
    |> Seq.map (fun (product, quantity) ->
        div [] [
            text $"""{product.Title} x {string quantity}"""
        ]
    )
    |> Doc.Concat
)
// 2. Works
shoppingCart.View.DocSeqCached(fun (product, quantity) ->
    div [] [
        text $"""{product.Title} x {string quantity}"""
    ]
)
// 3. Doesn't work
shoppingCart.Doc(fun (product, quantity) ->
    div [] [
        text $"""{product.Title} x {string quantity}"""
    ]
)
// 4. Doesn't work
Doc.BindListModel(fun (product, quantity) ->
    div [] [
        text $"""{product.Title} x {string quantity}"""
    ]
) shoppingCart
// 5. Works
Doc.BindSeqCached(fun (product, quantity) ->
    div [] [
        text $"""{product.Title} x {string quantity}"""
    ]
) shoppingCart.View

No 3 and No 4 are variants that don't reactively update on changing the items in the shopping cart. This is either a bug or these variants are confusing and misleading: there is little point in mapping a ListModel to reactive DOM if we only use the current snapshot of its values.

@Jooseppi12 Jooseppi12 self-assigned this Sep 26, 2023
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

2 participants