ui
ui copied to clipboard
LensInto throws exception if key is not found
The following code works as long as current is equal to "a" or "b":
let snippets = ListModel.Create id [ "a" ; "b" ]
let current = Var.Create "a"
let currentOf k = snippets.LensInto id (fun s n -> n) k
div [
Doc.Input [] current
current.View |> Doc.BindView (fun cur -> Doc.Input [] (currentOf cur))
] |> Doc.RunById "tasks"
... when current is different it throws:
WebSharper: Uncaught asynchronous exception TypeError: Cannot read property '$0' of null
at a (WebSharper.UI.Next.js:1961)
at WebSharper.UI.Next.js:849
at Object.Snap.When (WebSharper.UI.Next.js:957)
at Object.Snap.Map (WebSharper.UI.Next.js:844)
at Object.o (WebSharper.UI.Next.js:1581)
at WebSharper.UI.Next.js:1595
at Object.o (WebSharper.UI.Next.js:1580)
at WebSharper.UI.Next.js:1595
at Object.o (WebSharper.UI.Next.js:1580)
at WebSharper.UI.Next.js:1595
Yes it would be useful to provide partial lenses, ie. lenses that return an IRef<option<'T>>
.
An alternative is to be able to provide a default value
LensInto default id (fun s n -> n) k