Created
March 1, 2016 02:47
-
-
Save jhoguet/fc5788243bc8e3e4e5cd to your computer and use it in GitHub Desktop.
demonstrating lift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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