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

Expose timers API #327

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

movpushmov
Copy link

@movpushmov movpushmov commented Apr 22, 2024

Description

Checklist for a new method

  • Create a directory for the new method in the src directory in param-case
  • Place the source code to src/method-name/index.ts in ESModules export in camelCase named export
  • Add tests to src/method-name/method-name.test.ts
  • Add fork tests to src/method-name/method-name.fork.test.ts
  • Add type tests to test-typings/method-name.ts
    • Use // @ts-expect-error to mark expected type error
    • import { expectType } from 'tsd' to check expected return type
  • Add documentation in src/method-name/readme.md
    • Add header Patronum/MethodName
    • Add section with overloads, if have
    • Add Motivation, Formulae, Arguments and Return sections for each overload
    • Add useful examples in Example section for each overload
  • Add section to README.md in the repository root
    • Add method to the table of contents into correct category - [MethodName](#methodname) - description.
    • Add section ## MethodName
    • Add [Method documentation & API](/src/method-name) into section
    • Add simple example

Copy link
Member

@AlexandrHoroshih AlexandrHoroshih left a 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 💙

src/debounce/index.ts Outdated Show resolved Hide resolved
src/time/readme.md Outdated Show resolved Hide resolved
@sergeysova sergeysova changed the title feat: expose timers api Expose timers api May 14, 2024
@sergeysova sergeysova changed the title Expose timers api Expose timers API May 14, 2024
Comment on lines +207 to +221
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]],
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>(
Copy link
Member

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();
Copy link
Member

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.

Comment on lines +194 to +198
createWatch({
unit: db,
fn: listener,
scope,
})
Copy link
Member

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 })

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.

3 participants