Current @EventEmitter has fallowing issues:
- It pollutes the constructor.
- It makes it difficult to unit test the code because it requires a lot of mock code.
Replacement
Use inline Emitter class which reverses the dependency.
class Emitter {
listener; // we only support one
constructor() {
this.listener = null;
}
emit(data) {
return if (this.listener) this.listener(data);
}
}
Here is what the code would look like.
@Component({
selector: 'my-component',
events: ['open', 'close']
})
@View(...)
class MyComponent {
open:Emitter;
close:Emitter;
constructor() {
this.open = new Emitter();
this.close = new Emitter();
}
}
previous code:
@Component({
selector: 'my-component'
// events not listed here.
})
@View(...)
class MyComponent {
open:Function;
close:Function;
constructor(@EventEmitter('open') open:Function, @EventEmitter('close') close:Function) {
this.open = open;
this.close = close;
}
}
Rx and Streams
Angular should be able to consume not only Emitter but also Rx and Streams. (We prefer Emitter because it is much more light weight and synchronous)
Current
@EventEmitterhas fallowing issues:Replacement
Use inline
Emitterclass which reverses the dependency.Here is what the code would look like.
previous code:
Rx and Streams
Angular should be able to consume not only
Emitterbut alsoRxandStreams. (We preferEmitterbecause it is much more light weight and synchronous)