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 defer operator #330

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

velialiev
Copy link
Contributor

@velialiev velialiev commented May 16, 2024

Description

#329

(Why we should add this method?)

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
  • Fill frontmatter in src/method-name/readme.md
    • Add title. Make sure it uses camelCase syntax just like the method itself
    • Add slug. Use param-case to write it. In most cases it will be just like title
    • Add desription with one short sentence describing what method useful for
    • Add group. To categorize method on /operators page. Full list of available groups, you can see in documentation/src/content/config.ts

@velialiev velialiev changed the title feat: add patronum defer Add defer operator May 16, 2024
@velialiev velialiev marked this pull request as draft May 16, 2024 11:34
});

return merge([
calledAfterCondition,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if condition is already true then call event immediately

return merge([
calledAfterCondition,
combineEvents({
events: [calledBeforeCondition, condition.updates.filter({ fn: Boolean })],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if condition is not true yet then defer event call until condition became true

calledAfterCondition,
combineEvents({
events: [calledBeforeCondition, condition.updates.filter({ fn: Boolean })],
reset: condition.updates.filter({ fn: (value) => !value }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if condition became true and then false we should reset combine events since event call should be deferred until condition will be true again

filter: not(condition),
});

return merge([
Copy link
Contributor Author

@velialiev velialiev May 16, 2024

Choose a reason for hiding this comment

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

there could be 4 cases:

  1. Event called, condition is true --> call event
  2. Event called, condition is false --> wait until condition will be true and call event
  3. Condition became true, event is not called yet --> wait until event is called
  4. Condition became false, event is not called yet --> reset the state and wait both for event and condition to become true

IMPORTANT: if clock will be called more than 1 time only the last event will be deferred and called. Other events will be ignored

@sergeysova sergeysova linked an issue Oct 8, 2024 that may be closed by this pull request
@sergeysova sergeysova self-assigned this Oct 8, 2024
@YanLobat
Copy link
Member

YanLobat commented Oct 9, 2024

My suggestion is to write test(s)
And small motivation text(aka your case for example for explanation for other potential users)

P.S. yes I know that defer is a common practice but still applicable example will be very much appreciated

@sergeysova
Copy link
Member

Added default pull request template to help making new operator

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.

Operator proposal: defer
3 participants