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

Leading/Trailing throttle and throttleTime configuration #2465

Merged
merged 3 commits into from
May 9, 2017
Merged

Leading/Trailing throttle and throttleTime configuration #2465

merged 3 commits into from
May 9, 2017

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Mar 15, 2017

related to #1625 see commits for details.

Benjamin Lesh added 2 commits March 15, 2017 10:47
Adds the ability to configure the `throttle` operator via a
configuration object in the same manner as Lodash's throttle.

Currently this defaults to the existing behavior, which is `{ leading:
true, trailing: false }`. In an upcoming major version, I think we
should change this to align with other libraries that have similar
functionality. In particular Lodash, given it's popularity.

NOTE: While working on this I discovered that the leading value is
actually being emitted *after* the durationSelector is called and
subscribed to. This is likely a bug, but I'll file a separate issue.

related #1625
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 97.701% when pulling 437a5db on benlesh:trailing-throttle into 69d051b on ReactiveX:master.

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

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

Looks good overall, minus the two comments for the diagrams.

});

describe('throttleTime(fn, { leading: false, trailing: true })', () => {
asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should immediately emit the first value in each time window', () => {
Copy link
Member

Choose a reason for hiding this comment

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

{ leading: true, trailing: true } should be { leading: false, trailing: true }

});

describe('throttle(fn, { leading: false, trailing: true })', () => {
asDiagram('throttle(fn, { leading: true, trailing: true })')('should immediately emit the first value in each time window', () => {
Copy link
Member

Choose a reason for hiding this comment

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

{ leading: true, trailing: true } should be { leading: false, trailing: true }

@david-driscoll
Copy link
Member

Is it fair to say...

  • x.throttleTime(100, { trailing: true }) is the same as x.auditTime(100)?
  • x.throttleTime(100, { leading: true, trailing: true }) is the same as Observable.merge(x.throttleTime(100), x.auditTime(100))?

Also would it be possible (perhaps as a separate PR!) to give the same treatment to debounce and debounceTime?

We have no operator that compares to lodash's debounce(x => {}, { leading: true})

@benlesh
Copy link
Member Author

benlesh commented Mar 15, 2017

Also would it be possible (perhaps as a separate PR!) to give the same treatment to debounce and debounceTime?

That's the idea.

@benlesh
Copy link
Member Author

benlesh commented Mar 15, 2017

@david-driscoll the changes are made. Good catch. I put them in a separate commit so I didn't have to pull everything apart and change two commits.

@coveralls
Copy link

coveralls commented Mar 15, 2017

Coverage Status

Coverage increased (+0.01%) to 97.701% when pulling 437a5db on benlesh:trailing-throttle into 69d051b on ReactiveX:master.

@david-driscoll
Copy link
Member

Looks good to me. @kwonoj @trxcllnt @jayphelps any complaints?

@benlesh
Copy link
Member Author

benlesh commented Mar 15, 2017

The potential bug found in throttle (it existed prior, and this PR does NOT address it) I mention in my commit messages is listed here: #2466

@connorwyatt
Copy link

Hi, I would be interested in knowing when you guys think this will be in a release? We have a workaround that we can remove once this goes in and I was wondering when you think this will be merged.

Thanks

@lee-tunnicliffe
Copy link

I could also do with this change for my project. Any update would be greatly appreciated.

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants