toEventEmitter
Rx.Node.toEventEmitter(observable, eventName)
Converts the given observable sequence to an event emitter with the given event name. The errors are handled on the 'error' event and completion on the 'end' event.
参数
observable
(Obsesrvable): The observable sequence to convert to an EventEmitter.eventName
(String): The event name to subscribe.
返回值
(EventEmitter): An EventEmitter which emits the given eventName for each onNext call in addition to 'error' and 'end' events.
例
var Rx = require('Rx');
var source = Rx.Observable.return(42);
var emitter = Rx.Node.toEventEmitter(source, 'data');
emitter.on('data', function (data) {
console.log('Data: ' + data);
});
emitter.on('end', function () {
console.log('End');
});
// Ensure to call publish to fire events from the observable
emitter.publish();
// => Data: 42
// => End