-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Expose timers API #327
base: main
Are you sure you want to change the base?
Expose timers API #327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from a few nitpicks about the documentation:
Awesome! Great job, thank you 💙
const timerFx = createEffect(({ canceller, timeout }: DebounceTimerFxProps) => { | ||
const { timeoutId, rejectPromise } = canceller; | ||
|
||
if (timeoutId) clearTimeout(timeoutId); | ||
if (rejectPromise) rejectPromise(); | ||
|
||
return new Promise((resolve, reject) => { | ||
canceller.timeoutId = setTimeout(resolve, timeout); | ||
canceller.rejectPromise = reject; | ||
}); | ||
}); | ||
|
||
const scope = fork({ | ||
handlers: [[debounce.timerFx, timerFx]], | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const timerFx = createEffect(({ canceller, timeout }: DebounceTimerFxProps) => { | |
const { timeoutId, rejectPromise } = canceller; | |
if (timeoutId) clearTimeout(timeoutId); | |
if (rejectPromise) rejectPromise(); | |
return new Promise((resolve, reject) => { | |
canceller.timeoutId = setTimeout(resolve, timeout); | |
canceller.rejectPromise = reject; | |
}); | |
}); | |
const scope = fork({ | |
handlers: [[debounce.timerFx, timerFx]], | |
}); | |
const handleTimer = ({ canceller, timeout }): DebounceTimerFxProps => { | |
const { timeoutId, rejectPromise } = canceller; | |
if (timeoutId) clearTimeout(timeoutId); | |
if (rejectPromise) rejectPromise(); | |
return new Promise((resolve, reject) => { | |
canceller.timeoutId = setTimeout(resolve, timeout); | |
canceller.rejectPromise = reject; | |
}); | |
}); | |
const scope = fork({ | |
handlers: [[debounce.timerFx, handleTimer]], | |
}); |
handler should be function
@@ -29,7 +49,7 @@ export function debounce< | |||
target: Target; | |||
name?: string; | |||
}): Target; | |||
export function debounce<T>( | |||
export function _debounce<T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this export of _debounce
is necessary?
@@ -186,19 +186,23 @@ describe('edge cases', () => { | |||
test('does not call target twice for sample chain doubles', async () => { | |||
const trigger = createEvent(); | |||
|
|||
const scope = fork(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope should be created AFTER the model initialization.
createWatch({ | ||
unit: db, | ||
fn: listener, | ||
scope, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved just before await allSettled(start, { scope })
Description
Checklist for a new method
src
directory inparam-case
src/method-name/index.ts
in ESModules export incamelCase
named exportsrc/method-name/method-name.test.ts
src/method-name/method-name.fork.test.ts
test-typings/method-name.ts
// @ts-expect-error
to mark expected type errorimport { expectType } from 'tsd'
to check expected return typesrc/method-name/readme.md
Patronum/MethodName
Motivation
,Formulae
,Arguments
andReturn
sections for each overloadExample
section for each overloadREADME.md
in the repository root- [MethodName](#methodname) - description.
## MethodName
[Method documentation & API](/src/method-name)
into section