RXJS .filter and distinctUntilChanged on mouseover

871 views Asked by At

In the RXJS autocomplete example you can filter keyup events but how can I filter mouseenter and mouseleave events?

1

There are 1 answers

2
paulpdaniels On BEST ANSWER

The same way. fromEvent automatically detects the source type and transparently wraps an observable around it. For instance, both options below will work:

var entered = Rx.Observable.fromEvent($('#mydiv'), 'mouseenter', function(e) {
    return e[0].target;
});

var exited = Rx.Observable.fromEvent(document.getElementById('mydiv'), 'mouseleave', function(e) {
    return e[0].target;
});

entered.subscribe(function(x) {
   $(x).css('background-color', 'green'); 
});

exited.subscribe(function(x) {
   $(x).css('background-color', 'yellow');
});