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

fix(throttle): properly handle default ThrottleConfig values #7176

Conversation

jakovljevic-mladen
Copy link
Member

Description:
This PR is split into two commits. The first one fixes an issue described in #7146, while the second one adds ThrottleConfig docs.

This issue should be probably cherry picked to the 7.x branch.

Related issue (if exists):
Fixes #7146

@@ -47,15 +47,15 @@ import { timer } from '../observable/timer';
* internally by the optional `scheduler`.
* @param scheduler The {@link SchedulerLike} to use for
* managing the timers that handle the throttling. Defaults to {@link asyncScheduler}.
* @param config a configuration object to define `leading` and
* @param config A configuration object to define `leading` and
* `trailing` behavior. Defaults to `{ leading: true, trailing: false }`.
* @return A function that returns an Observable that performs the throttle
* operation to limit the rate of emissions from the source.
*/
export function throttleTime<T>(
duration: number,
scheduler: SchedulerLike = asyncScheduler,
Copy link
Member Author

Choose a reason for hiding this comment

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

Should throttleTime merge scheduler and config parameters effectively introducing a ThrottleTimeConfig interface which would extend ThrottleConfig interface by adding scheduler?: SchedulerLike property to it?

It would effectively remove the need to use throttleTime like this: throttleTime(1000, undefined, { trailing: true }) to throttleTime(1000, { trailing: true }).

@benlesh, thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this should probably be throttleTime(number, config) where config has a scheduler option. We'll need to deprecate the other signatures that take a scheduler as the second argument, but allow the scheduler to be passed with the config.

@jakovljevic-mladen jakovljevic-mladen merged commit b7a4e94 into ReactiveX:master Apr 6, 2023
@jakovljevic-mladen jakovljevic-mladen deleted the fix_an_issue_with_throttle branch April 6, 2023 07:11
jakovljevic-mladen added a commit that referenced this pull request Apr 6, 2023
* fix(throttle): properly handle default ThrottleConfig values

* docs(ThrottleConfig): document "leading" and "trailing" behavior

(cherry picked from commit b7a4e94)
@jakovljevic-mladen jakovljevic-mladen added 7.x Issues and PRs for version 7.x 8.x Issues and PRs for version 8.x labels Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.x Issues and PRs for version 7.x 8.x Issues and PRs for version 8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected false default value for leading when only trailing is specified in config parameter
2 participants