Skip to content

Commit

Permalink
Greatly improve form input robustness against sim input.
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Dec 19, 2023
1 parent 28b2382 commit a015edf
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 69 deletions.
20 changes: 10 additions & 10 deletions src/Client/Helper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@ let logf a b =

open System.Collections.Generic

let mutable memoizations = Dictionary<string, int>(HashIdentity.Structural)

let debounce<'T> (key: string) (timeout: int) (fn: 'T -> unit) value =
let debounce<'T> (storage:Dictionary<string, int>) (key: string) (timeout: int) (fn: 'T -> unit) value =
let key = key // fn.ToString()
// Cancel previous debouncer
match memoizations.TryGetValue(key) with
match storage.TryGetValue(key) with
| true, timeoutId -> printfn "CLEAR"; Fable.Core.JS.clearTimeout timeoutId
| _ -> printfn "Not clear";()

// Create a new timeout and memoize it
let timeoutId =
Fable.Core.JS.setTimeout
(fun () ->
memoizations.Remove(key) |> ignore
storage.Remove(key) |> ignore
fn value
)
timeout
memoizations.[key] <- timeoutId
storage.[key] <- timeoutId

let debouncel<'T> (key: string) (timeout: int) (setLoading: bool -> unit) (fn: 'T -> unit) value =
let debouncel<'T> (storage:Dictionary<string, int>) (key: string) (timeout: int) (setLoading: bool -> unit) (fn: 'T -> unit) value =
let key = key // fn.ToString()
// Cancel previous debouncer
match memoizations.TryGetValue(key) with
match storage.TryGetValue(key) with
| true, timeoutId -> Fable.Core.JS.clearTimeout timeoutId
| _ -> setLoading true; ()

// Create a new timeout and memoize it
let timeoutId =
Fable.Core.JS.setTimeout
(fun () ->
memoizations.Remove(key) |> ignore
storage.Remove(key) |> ignore
setLoading false
fn value
)
timeout
memoizations.[key] <- timeoutId
storage.[key] <- timeoutId

let newDebounceStorage = fun () -> Dictionary<string, int>(HashIdentity.Structural)
13 changes: 8 additions & 5 deletions src/Client/MainComponents/Metadata/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

open Feliz
open Feliz.Bulma

open Spreadsheet
open Messages
open Browser.Types
open Fable.Core.JsInterop
open ARCtrl.ISA
open Shared

Expand Down Expand Up @@ -43,11 +39,18 @@ let Main(assay: ArcAssay, model: Messages.Model, dispatch: Msg -> unit) =
assay.TechnologyPlatform <- oa
assay |> Assay |> Spreadsheet.UpdateArcFile |> SpreadsheetMsg |> dispatch
)
FormComponents.PersonInput(
FormComponents.PersonsInput(
assay.Performers,
"Performers",
fun persons ->
assay.Performers <- persons
assay |> Assay |> Spreadsheet.UpdateArcFile |> SpreadsheetMsg |> dispatch
)
FormComponents.CommentsInput(
assay.Comments,
"Comments",
fun comments ->
assay.Comments <- comments
assay |> Assay |> Spreadsheet.UpdateArcFile |> SpreadsheetMsg |> dispatch
)
]
Loading

0 comments on commit a015edf

Please sign in to comment.