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

Introduce skip and take operators #339

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

Conversation

rokashkovvd
Copy link

Description

I think everyone had to write logic for limiting calls to effects or events. For example, limiting the number of repeated requests (take) or displaying some kind of warning if the user abuses a button or other interactive element (skip).
They are based on abstract and repeating elements that can be put into separate operators - skip & take.

These operators were inspired by their rxjs analogs:
skip - https://rxjs.dev/api/index/function/skip;
take - https://rxjs.dev/api/index/function/take.

I know the effector API tries to be minimalistic. I agree with this. But I don't consider these particular operators redundant.
If you think otherwise, you can safely close this PR by writing feedback.

In case of positive feedback, I am ready to complete the entire checklist for adding new operators and follow your comments in order to bring these operators to release.

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

@sergeysova sergeysova added the RFC Some new feature that should be discussed label Oct 10, 2024
Comment on lines 18 to 21
const $canTrigger = sample({
source: [$skipped, $count],
fn: ([skp, cnt]) => skp >= cnt,
});
Copy link
Member

Choose a reason for hiding this comment

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

Why not combine?

Suggested change
const $canTrigger = sample({
source: [$skipped, $count],
fn: ([skp, cnt]) => skp >= cnt,
});
const $canTrigger = combine(
[$skipped, $count],
([skipped, count]) => skipped >= count,
);

@sergeysova sergeysova changed the title feat: add skip & take Introduce skip and take operators Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Some new feature that should be discussed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants