Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cmd.debounce #1062

Merged
merged 3 commits into from
Jan 29, 2024
Merged

Add Cmd.debounce #1062

merged 3 commits into from
Jan 29, 2024

Conversation

TimLariviere
Copy link
Member

Following #1061, add a Cmd.debounce helper to debounce events like Entry.TextChanged, etc.

Usage:

type Model =
    { EntryValue: string
      ValidatedText: string }

type Msg =
    | TextChanged of string
    | TextValidated of string

let validateTextCmd =
    Cmd.debounce 300 (fun value ->
       TextValidated value
    )

let update msg model =
    match msg with
    | TextChanged newValue -> { model with EntryValue = newValue }, validateTextCmd newValue
    | TextValidated value -> { model with ValidatedText = value }, Cmd.none

let view model =
    VStack() {
        Entry(model.EntryValue, TextChanged)
        Label($"Validated text: {model.ValidatedText}")
    }

@TimLariviere TimLariviere merged commit 733900c into main Jan 29, 2024
1 check passed
@TimLariviere TimLariviere deleted the debounce-cmd branch January 29, 2024 08:42
@TimLariviere TimLariviere restored the debounce-cmd branch January 29, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants