-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: showcase debounce reactive duration (#110)
- Loading branch information
Showing
7 changed files
with
499 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
<script lang="ts"> | ||
import { useDebounce } from "runed"; | ||
import Input from "../ui/input/input.svelte"; | ||
import Label from "../ui/label/label.svelte"; | ||
import DemoContainer from "$lib/components/demo-container.svelte"; | ||
import { Button } from "$lib/components/ui/button"; | ||
let count = $state(0); | ||
let logged = $state(""); | ||
let isFirstTime = $state(true); | ||
let durationMs = $state(1000); | ||
const logCount = useDebounce(() => { | ||
if (isFirstTime) { | ||
isFirstTime = false; | ||
logged = `You pressed the button ${count} times!`; | ||
} else { | ||
logged = `You pressed the button ${count} times since last time!`; | ||
} | ||
count = 0; | ||
}, 1000); | ||
const logCount = useDebounce( | ||
() => { | ||
if (isFirstTime) { | ||
isFirstTime = false; | ||
logged = `You pressed the button ${count} times!`; | ||
} else { | ||
logged = `You pressed the button ${count} times since last time!`; | ||
} | ||
count = 0; | ||
}, | ||
() => durationMs | ||
); | ||
function ding() { | ||
count++; | ||
logCount(); | ||
} | ||
</script> | ||
|
||
<DemoContainer> | ||
<DemoContainer class="flex flex-col gap-4"> | ||
<div class="flex flex-col gap-1.5"> | ||
<Label for="duration">Debounce duration (ms)</Label> | ||
<Input id="duration" type="number" bind:value={durationMs} /> | ||
</div> | ||
<div class="flex items-center gap-4"> | ||
<Button variant="brand" size="sm" onclick={ding}>DING DING DING</Button> | ||
<Button variant="subtle" size="sm" onclick={logCount.cancel} disabled={!logCount.pending} | ||
>Cancel message</Button | ||
> | ||
</div> | ||
<p class="mt-4">{logged || "Press the button!"}</p> | ||
<p class="mt-2">{logged || "Press the button!"}</p> | ||
</DemoContainer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters