Closed leolorenzoluis closed 2 years ago
Lit actually provides the index so this is not difficult. But where do you need the index exactly, in the getId
or the template
function. For the template
function it makes sense, but I'd prefer to discourage for the getId
function as users shouldn't use the index to calculate the ID because this will create problems when sorting or adding/removing elements in the middle of the list.
I was thinking inside the template
function. Should I try to just copy the implementation for mapiUnique from F#'s mapi? 😀 I could try to take a stab on making a PR for it.
If it's only template
it's very easy because currently we are just ignoring the index argument 😅
type Lit with
static member mapiUnique (getId: 'T -> string) (template: int -> 'T -> TemplateResult) (items: 'T seq): TemplateResult =
LitBindings.repeat (items, getId, (fun x i -> template i x))
I change the order of the arguments for consistency with F# Lit.mapi signature
https://github.com/fable-compiler/Fable.Lit/pull/51 It's really based off your code, but added some docs. 👍
I think it's useful to create a helper function similar to
mapi
in F#. I'd like to access the index to be passed to the function besides the value of an array.