davedawkins / Sutil

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

Bind.each requires F# list instead of array #49

Closed kaeedo closed 2 years ago

kaeedo commented 3 years ago

Hello. I've been attempting to write a sample app using this, and was wondering about Bind.each requiring an F# list instead of the more general seq. As I understand Fable, F# lists get transpiled using a special list.js helper library from fable, instead of the native JavaScript array, whereas .Net arrays do get transpiled to JS arrays.

Is there a specific reason Bind.each requires a list? I would like to be able to use the JS array in my fable app, both for familiarity on how it behaves, as well as avoiding the extra import if possible.

e.g.:

    let tags: IStore<string array> = Store.make [| "one"; "two" |]
    let otherTags: IStore<string list> = Store.make [ "one"; "two" ]

    Html.div [
        disposeOnUnmount [
            tags
            otherTags
        ]
        Bind.each (tags, (fun tag -> Html.div [ text tag ])) // This one is compiler error
        Bind.each (otherTags, (fun tag -> Html.div [ text tag ])) // This one works

    ]

thanks

davedawkins commented 3 years ago

This is just my inexperience with F# showing through. I made the same observation myself a couple of weeks ago, and I'll fix the API. Thanks for reporting.

AngelMunoz commented 3 years ago

Probably a seq, array, and list overloads would be nice to have, I've been hitting these recently as well

davedawkins commented 3 years ago

As I understand it, a single seq overload will cover all the others. At worst, it can be specified as #seq

davedawkins commented 3 years ago

OK.. I tried this and of course, we have not just list<'T> but IObservable<list<'T>>. I was able to make everything compile with IObservable<#seq<'T>>, but the compiler really wasn't happy about and then the samples no longer worked. So..I need to think a little more.

davedawkins commented 2 years ago

This is now working with both Lists and Arrays. I kind of made a DIY typeclass, which I might throw out to the #fsharp community so they can tell me exactly why that was a bad idea and how to do it better. The main this, this works now, and will be in the next release