Last active
November 30, 2023 12:33
-
-
Save artalar/cfca839afed55fa5c29666666f1b4ba6 to your computer and use it in GitHub Desktop.
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
// BASE | |
// debounce | |
const onChange = debounce((ctx, event) => { | |
inputAtom(ctx, event.currentTarget.value); | |
}, 500); | |
// concurrent | |
const onChange = concurrent(async (ctx, event) => { | |
await ctx.schedule(() => sleep(500)); | |
inputAtom(ctx, event.currentTarget.value); | |
}); | |
// PREPARATION MAPPING | |
// debounce | |
const handleChange = debounce((ctx, value) => { | |
inputAtom(ctx, value); | |
}, 500); | |
const onChange = (ctx, event) => { | |
handleChange(ctx, event.currentTarget.value); | |
}; | |
// concurrent | |
const onChange = concurrent(async (ctx, event) => { | |
const { value } = event.currentTarget; | |
await ctx.schedule(() => sleep(500)); | |
inputAtom(ctx, value); | |
}); | |
// CONDITIONS | |
// debounce | |
const handleChange = (ctx, value) => { | |
inputAtom(ctx, value); | |
}; | |
const handleDebounceChange = debounce(handleChange, 500); | |
const onChange = (ctx, event) => { | |
const { value } = event.currentTarget; | |
if (Math.random() > 0.5) handleChange(ctx, value); | |
else handleDebounceChange(ctx, value); | |
}; | |
// concurrent | |
const onChange = concurrent(async (ctx, event) => { | |
const { value } = event.currentTarget; | |
if (Math.random() > 0.5) await ctx.schedule(() => sleep(500)); | |
inputAtom(ctx, value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment