Skip to content

Instantly share code, notes, and snippets.

@jhoguet
Created March 1, 2016 02:47
Show Gist options
  • Save jhoguet/fc5788243bc8e3e4e5cd to your computer and use it in GitHub Desktop.
Save jhoguet/fc5788243bc8e3e4e5cd to your computer and use it in GitHub Desktop.
demonstrating lift
import { Observable, Subscriber} from 'rxjs';
const _lift = Observable.prototype.lift;
function LogOperator(childOperator) {
this.childOperator = childOperator;
}
LogOperator.prototype.call = function (subscriber) {
return this.childOperator.call(new LogSubscriber(subscriber));
};
window.log = [];
function LogSubscriber() {
Subscriber.apply(this, arguments);
}
LogSubscriber.prototype = Object.create(Subscriber.prototype);
LogSubscriber.prototype.constructor = LogSubscriber;
LogSubscriber.prototype.next = function (x) {
log.push('next ' + x);
this.destination.next(x);
};
Observable.prototype.lift = function(observerFactory) {
const pretendOperator = {
call : subscriber => {
console.log('in call');
return observerFactory.call(new LogSubscriber(subscriber));
}
};
return _lift.call(this, pretendOperator);
};
window.Observable = Observable;
Observable.of(3).map(val => val*2).subscribe(() => {});
// window.log === ["next 6"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment