Skip to content

Commit

Permalink
#84
Browse files Browse the repository at this point in the history
  • Loading branch information
Jooseppi12 committed Dec 2, 2022
1 parent 46eb05f commit 74ec894
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion WebSharper.UI/Attr.Client.fs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,22 @@ module BindVar =
| Some x when x = v -> None
| _ -> Some v
init, Option.iter << set, var.View.Map map

let FileApplyValue (get: Get<'a>) (set: Set<'a>) : Apply<'a> = fun (var: Var<'a>) ->
let mutable expectedValue = None
let init (el: Dom.Element) =
let onChange () =
var.UpdateMaybe(fun v ->
expectedValue <- get el
match expectedValue with
| Some x as o when x !==. v -> o
| _ -> None)
el.AddEventListener("change", onChange)
let map v =
match expectedValue with
| Some x when x = v -> None
| _ -> Some v
init, Option.iter << set, var.View.Map map

let BoolCheckedApply : Apply<bool> = fun var ->
let init (el: Dom.Element) =
Expand Down Expand Up @@ -350,7 +366,7 @@ module BindVar =
let files : FileList = el?files
[| for i in 0..files.Length-1 do yield files.Item(i) |] |> Some
let FileApplyUnchecked : Apply<File array> =
ApplyValue FileGetUnchecked FileSetUnchecked
FileApplyValue FileGetUnchecked FileSetUnchecked

let IntSetUnchecked : Set<int> = fun el i ->
el?value <- string i
Expand Down

0 comments on commit 74ec894

Please # to comment.