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

Rx debounceTime doesn't work. #5925

Closed
tandu opened this issue Dec 15, 2015 · 16 comments
Closed

Rx debounceTime doesn't work. #5925

tandu opened this issue Dec 15, 2015 · 16 comments

Comments

@tandu
Copy link

tandu commented Dec 15, 2015

I have modified example from here ReactiveX/rxjs#916 -> http://jsfiddle.net/889byemb/. It works as expected. I have created service that should only notify after 1.5s after scroll end and it is never fired.

import {EventEmitter} from 'angular2/core';
import 'rxjs/add/operator/debounceTime.js';

export class ScrollService {
  scrolled = new EventEmitter().debounceTime(1500);
}

using service from another component

<holder (scroll)="scrollService.scrolled.next()"></holder>

If I replace debounceTime by throttleTime events are fired fine but I need debounce behavior not the throttle one. I think there might be an issue in angular because the jsfiddle example above with pure rx is working as expected.

@robwormald
Copy link
Contributor

Could you reproduce this in a plunker?

@tandu
Copy link
Author

tandu commented Dec 15, 2015

I will do it tomorrow.

@tandu
Copy link
Author

tandu commented Dec 15, 2015

I have tried to create the plunker: http://plnkr.co/edit/Blgmi6CTo1v9puIQSLAI?p=preview. I don't know how to add debounceTime method here, can you complete it yourself?

@robwormald
Copy link
Contributor

This is more to do with the fact you're using a Subject (don't use EventEmitter here either, fwiw) than anything to do with Angular2.

See http://jsfiddle.net/8g968xh7/ which exhibits the same behavior.

The correct-ish way to do the same thing in your original fiddle would be something like this http://plnkr.co/edit/0pldDi0TSqS69rsWOmZ8?p=preview (using Observable.fromEvent). Ideally we'd like to make this easier, getting proper Observables from the view. See #4062 for info on that.

@Blesh would this be the expected behavior on a Subject? seems kinda weird.

@tandu
Copy link
Author

tandu commented Dec 16, 2015

Thank you for explanation. It looks strange because throttleTime is working and debounceTime doesn't with Subject. I will create related issue in rxjs.

@jorgeunimicro
Copy link

I have the same problem. Here is the plunker: http://plnkr.co/edit/UCi63b?p=preview

@robwormald
Copy link
Contributor

@jorgeunimicro you're importing your operator wrong: http://plnkr.co/edit/IoV11B?p=preview

@jorgeunimicro
Copy link

still doesn't work. Validation keep being false

@tandu
Copy link
Author

tandu commented Dec 16, 2015

So far it seems that fix is to pass anything when you emit event, for example if instead of scrollService.scrolled.next() you emit scrollService.scrolled.next(0) or scrollService.scrolled.next('a') everything works fine.

@jorgeunimicro
Copy link

But, I can't handle what a Controls emit. That depends on the user input

@jorgeunimicro
Copy link

@robwormald I import the operator in a correct way. It is defined (see console.log). But still doesn't work even if I import from add/operator instead of operator. http://plnkr.co/edit/UCi63b?p=preview

@jorgeunimicro
Copy link

@robwormald it seems start validation throws an exception because c.valueChanges is undefined.

http://plnkr.co/edit/tRfGWb?p=preview

@benlesh
Copy link
Contributor

benlesh commented Dec 18, 2015

This is likely a bug with RxJS beta.

@benlesh
Copy link
Contributor

benlesh commented Dec 18, 2015

File an issue over there, and we'll take a look. The holiday season will slow things down a bit though

@pkozlowski-opensource
Copy link
Member

This one sounds like stale. Closing for now.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants