refactor(async): refactor EventEmitter

Refactor EventEmitter and Async Facade to match ES7 Observable semantics, properly use RxJS typedefs, make EventEmitter inherit from RxJS Subject. Closes #4149.

BREAKING CHANGE:
- consumers of EventEmitter no longer need to call .toRx()
- EventEmitter is now generic and requires a type - e.g. `EventEmitter<string>`
- EventEmitter and Observable now use the `.subscribe(generatorOrNext, error, complete)` method instead of `.observer(generator)`
- ObservableWrapper uses `callNext/callError/callComplete` instead of `callNext/callThrow/callReturn`
This commit is contained in:
Rob Wormald
2015-10-24 18:48:43 -07:00
parent 72e65d6797
commit ca3986f31d
35 changed files with 341 additions and 113 deletions
@@ -4,7 +4,7 @@ import 'dart:core';
import 'dart:async';
import "package:angular2/src/core/facade/async.dart";
class MockEventEmitter extends EventEmitter {
class MockEventEmitter<T> extends EventEmitter<T> {
final controller = new StreamController.broadcast(sync: true);
@override
@@ -1,11 +1,11 @@
import {EventEmitter} from 'angular2/src/core/facade/async';
export class MockEventEmitter extends EventEmitter {
export class MockEventEmitter<T> extends EventEmitter<T> {
private _nextFns: Function[] = [];
constructor() { super(); }
observer(generator: any): any {
subscribe(generator: any): any {
this._nextFns.push(generator.next);
return new MockDisposable();
}
@@ -13,11 +13,11 @@ import {NgZone} from 'angular2/src/core/zone/ng_zone';
* Such that whatever goes into one's sink comes out the others source.
*/
export function createPairedMessageBuses(): PairedMessageBuses {
var firstChannels: {[key: string]: MockEventEmitter} = {};
var firstChannels: {[key: string]: MockEventEmitter<any>} = {};
var workerMessageBusSink = new MockMessageBusSink(firstChannels);
var uiMessageBusSource = new MockMessageBusSource(firstChannels);
var secondChannels: {[key: string]: MockEventEmitter} = {};
var secondChannels: {[key: string]: MockEventEmitter<any>} = {};
var uiMessageBusSink = new MockMessageBusSink(secondChannels);
var workerMessageBusSource = new MockMessageBusSource(secondChannels);
@@ -30,7 +30,7 @@ export class PairedMessageBuses {
}
export class MockMessageBusSource implements MessageBusSource {
constructor(private _channels: {[key: string]: MockEventEmitter}) {}
constructor(private _channels: {[key: string]: MockEventEmitter<any>}) {}
initChannel(channel: string, runInZone = true) {
if (!StringMapWrapper.contains(this._channels, channel)) {
@@ -38,7 +38,7 @@ export class MockMessageBusSource implements MessageBusSource {
}
}
from(channel: string): MockEventEmitter {
from(channel: string): MockEventEmitter<any> {
if (!StringMapWrapper.contains(this._channels, channel)) {
throw new BaseException(`${channel} is not set up. Did you forget to call initChannel?`);
}
@@ -49,7 +49,7 @@ export class MockMessageBusSource implements MessageBusSource {
}
export class MockMessageBusSink implements MessageBusSink {
constructor(private _channels: {[key: string]: MockEventEmitter}) {}
constructor(private _channels: {[key: string]: MockEventEmitter<any>}) {}
initChannel(channel: string, runInZone = true) {
if (!StringMapWrapper.contains(this._channels, channel)) {
@@ -57,7 +57,7 @@ export class MockMessageBusSink implements MessageBusSink {
}
}
to(channel: string): MockEventEmitter {
to(channel: string): MockEventEmitter<any> {
if (!StringMapWrapper.contains(this._channels, channel)) {
this._channels[channel] = new MockEventEmitter();
}
@@ -79,9 +79,9 @@ export class MockMessageBus extends MessageBus {
this.source.initChannel(channel, runInZone);
}
to(channel: string): MockEventEmitter { return this.sink.to(channel); }
to(channel: string): MockEventEmitter<any> { return this.sink.to(channel); }
from(channel: string): MockEventEmitter { return this.source.from(channel); }
from(channel: string): MockEventEmitter<any> { return this.source.from(channel); }
attachToZone(zone: NgZone) {}
}