Skip to content

Commit 163df75

Browse files
committed
fix(EventEmitter): Update rxjs dependency. Add 'emit' method.
fixes #122 BREAKING CHANGE: Before: ```js @output() foo = new EventEmitter(); foo.next(); ``` Before: ```js @output() foo = new EventEmitter(); foo.emit(); // <-- ```
1 parent a96b817 commit 163df75

7 files changed

+32
-25
lines changed

API.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class App {
196196
- **`directives`** **[Array&lt;[IProvidable](#iprovidable)&gt;]** Any directives or components that this component or any of it's children depends on.
197197
- **`pipes`** **[Array&lt;[IProvidable](#iprovidable)&gt;]** Any [pipes](#pipe) that this component or any of it's children depends on.
198198
- **`inputs`** **[Array&lt;string&gt;]** An array of strings naming what class properties you want to expose in `bindToController` (or `scope` if angular 1.3). For example, `inputs: ['foo']` will connect the class property `foo` to the input `foo`. You can also rename the input, for example `inputs: ['foo:theFoo']` will connect the class property `foo` to the input `the-foo`.
199-
- **`outputs`** **[Array&lt;string&gt;]** An array of strings naming what class properties you want to expose as outputs. For example, `outputs: ['fooChange']` will notify the app that this component can fire a `'fooChange'` event. If there is a class property `fooChange` that is an `EventEmitter` it can trigger this event via `this.fooChange.next()`. Otherwise the event can also be triggered with a regular DOM event of name `'fooChange'`. You can also rename the output, for example `inputs: ['fooChange:theFooChange']` will notify of a 'theFooChange' event, but will still look for a `fooChange` property on the class.
199+
- **`outputs`** **[Array&lt;string&gt;]** An array of strings naming what class properties you want to expose as outputs. For example, `outputs: ['fooChange']` will notify the app that this component can fire a `'fooChange'` event. If there is a class property `fooChange` that is an `EventEmitter` it can trigger this event via `this.fooChange.emit()`. Otherwise the event can also be triggered with a regular DOM event of name `'fooChange'`. You can also rename the output, for example `inputs: ['fooChange:theFooChange']` will notify of a 'theFooChange' event, but will still look for a `fooChange` property on the class.
200200
- **`controllerAs`** **[string='ctrl']** The controller name used in the template. By default uses 'ctrl'. We wanted to use something consistent across all components to make migration to Angular 2 easier later. When migrating you'll only need to do a simple find and replace of all 'ctrl.' and remove them. If you want the controllerAs name to match the selector (camel-cased) then set controllerAs to '$auto'.
201201

202202
## Inputs and Outputs
@@ -267,7 +267,7 @@ class MenuDropdown {
267267

268268
triggerEventViaEventEmitter() {
269269
// You can optionally pass along a payload
270-
this.optionSelect.next(selectedOption);
270+
this.optionSelect.emit(selectedOption);
271271
}
272272
}
273273
```
@@ -439,7 +439,7 @@ class MenuDropdown {
439439
@Output() optionSelect = new EventEmitter();
440440

441441
someMethod() {
442-
this.optionSelect.next('payload');
442+
this.optionSelect.emit('payload');
443443
}
444444
}
445445
```
@@ -467,9 +467,9 @@ We use this method behind the scenes to subscribe to your output events. You mos
467467
- **`error`** **[Function]** Callback that is called when the Subject has an 'error'.
468468
- **`complete`** **[Function]** Callback that is called when the Subject is 'completed'.
469469

470-
#### `next()`
470+
#### `emit()`
471471

472-
`next(value: any)`
472+
`emit(value: any)`
473473

474474
Will trigger all subscriber's next callbacks, passing along the value. This is the main way to trigger an EventEmitter-based output.
475475

Walkthrough.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class InnerApp{
132132
}
133133

134134
triggerEventViaEventEmitter() {
135-
this.evt2.next()
135+
this.evt2.emit()
136136
}
137137
}
138138

@@ -227,7 +227,7 @@ and here's where we call them in the component
227227

228228
triggerEventViaEventEmitter() {
229229
// this won't bubble, but most custom events probably shouldn't...
230-
this.evt2.next()
230+
this.evt2.emit()
231231
}
232232
```
233233

@@ -404,7 +404,7 @@ class InnerApp{
404404
}
405405

406406
triggerEventViaEventEmitter() {
407-
this.evt2.next()
407+
this.evt2.emit()
408408
}
409409
}
410410

lib/decorators/component.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ describe('@Component', function(){
759759
private fooChanged = new EventEmitter();
760760
setAndTriggerFoo(val) {
761761
this.foo = val;
762-
this.fooChanged.next(val);
762+
this.fooChanged.emit(val);
763763
}
764764
}
765765

@@ -974,7 +974,7 @@ describe('@Component', function(){
974974

975975
fixture.debugElement.componentInstance.bar.should.be.false;
976976

977-
fixture.debugElement.componentViewChildren[0].componentInstance.output.next();
977+
fixture.debugElement.componentViewChildren[0].componentInstance.output.emit();
978978
this.clock.tick();
979979

980980
fixture.debugElement.componentInstance.bar.should.be.true;
@@ -993,7 +993,7 @@ describe('@Component', function(){
993993

994994
fixture.debugElement.componentInstance.bar.should.be.false;
995995

996-
fixture.debugElement.componentViewChildren[0].componentInstance.outputChange.next();
996+
fixture.debugElement.componentViewChildren[0].componentInstance.outputChange.emit();
997997
this.clock.tick();
998998

999999
fixture.debugElement.componentInstance.bar.should.be.true;
@@ -1014,7 +1014,7 @@ describe('@Component', function(){
10141014

10151015
let detail = 'hello';
10161016

1017-
fixture.debugElement.componentViewChildren[0].componentInstance.output.next(detail);
1017+
fixture.debugElement.componentViewChildren[0].componentInstance.output.emit(detail);
10181018
this.clock.tick();
10191019

10201020
fixture.debugElement.componentInstance.bar.should.eql('hello');
@@ -1033,7 +1033,7 @@ describe('@Component', function(){
10331033

10341034
fixture.debugElement.componentInstance.bar.should.be.false;
10351035

1036-
fixture.debugElement.componentViewChildren[0].componentInstance.o.next();
1036+
fixture.debugElement.componentViewChildren[0].componentInstance.o.emit();
10371037
this.clock.tick();
10381038

10391039
fixture.debugElement.componentInstance.bar.should.be.true;
@@ -1099,7 +1099,7 @@ describe('@Component', function(){
10991099
fixtureComponent.bar.should.be.false;
11001100
fooComponent.bar.should.be.false;
11011101

1102-
barComponent.barChange.next();
1102+
barComponent.barChange.emit();
11031103
this.clock.tick();
11041104

11051105
fixtureComponent.bar.should.be.false;

lib/decorators/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// }
2727
// async send(){
2828
// let message = await this.Messenger.create(this.subject, this.message);
29-
// this.sent.next(message);
29+
// this.sent.emit(message);
3030
// }
3131
// }
3232
//```

lib/decorators/input-output.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ describe('@Input Decorator', function(){
395395
fooChanged = new EventEmitter();
396396
setAndTriggerFoo(val) {
397397
this.foo = val;
398-
this.fooChanged.next(val);
398+
this.fooChanged.emit(val);
399399
}
400400
}
401401

@@ -633,7 +633,7 @@ describe('@Output Decorator', function(){
633633

634634
fixture.debugElement.componentInstance.bar.should.be.false;
635635

636-
fixture.debugElement.componentViewChildren[0].componentInstance.output.next();
636+
fixture.debugElement.componentViewChildren[0].componentInstance.output.emit();
637637
this.clock.tick();
638638

639639
fixture.debugElement.componentInstance.bar.should.be.true;
@@ -652,7 +652,7 @@ describe('@Output Decorator', function(){
652652

653653
fixture.debugElement.componentInstance.bar.should.be.false;
654654

655-
fixture.debugElement.componentViewChildren[0].componentInstance.outputChange.next();
655+
fixture.debugElement.componentViewChildren[0].componentInstance.outputChange.emit();
656656
this.clock.tick();
657657

658658
fixture.debugElement.componentInstance.bar.should.be.true;
@@ -673,7 +673,7 @@ describe('@Output Decorator', function(){
673673

674674
let detail = 'hello';
675675

676-
fixture.debugElement.componentViewChildren[0].componentInstance.output.next(detail);
676+
fixture.debugElement.componentViewChildren[0].componentInstance.output.emit(detail);
677677
this.clock.tick();
678678

679679
fixture.debugElement.componentInstance.bar.should.eql('hello');
@@ -692,7 +692,7 @@ describe('@Output Decorator', function(){
692692

693693
fixture.debugElement.componentInstance.bar.should.be.false;
694694

695-
fixture.debugElement.componentViewChildren[0].componentInstance.o.next();
695+
fixture.debugElement.componentViewChildren[0].componentInstance.o.emit();
696696
this.clock.tick();
697697

698698
fixture.debugElement.componentInstance.bar.should.be.true;
@@ -760,7 +760,7 @@ describe('@Output Decorator', function(){
760760
fixtureComponent.bar.should.be.false;
761761
fooComponent.bar.should.be.false;
762762

763-
barComponent.barChange.next();
763+
barComponent.barChange.emit();
764764
this.clock.tick();
765765

766766
fixtureComponent.bar.should.be.false;

lib/events/event-emitter.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Subject from '@reactivex/rxjs/dist/es6/Subject';
1+
import Subject from 'rxjs/Subject';
22

33
/**
44
* Use by directives and components to emit custom Events. Copied from Angular 2's [EventEmitter](
@@ -27,9 +27,9 @@ import Subject from '@reactivex/rxjs/dist/es6/Subject';
2727
* toggle() {
2828
* this.visible = !this.visible;
2929
* if (this.visible) {
30-
* this.open.next(null);
30+
* this.open.emit(null);
3131
* } else {
32-
* this.close.next(null);
32+
* this.close.emit(null);
3333
* }
3434
* }
3535
* }
@@ -53,6 +53,13 @@ export default class EventEmitter<T> extends Subject<T> {
5353
this._isAsync = isAsync;
5454
}
5555

56+
emit(value: T) { super.next(value); }
57+
58+
/**
59+
* @deprecated - use .emit(value) instead
60+
*/
61+
next(value: any) { super.next(value); }
62+
5663
subscribe(generatorOrNext?: any, error?: any, complete?: any): any {
5764
if (generatorOrNext && typeof generatorOrNext === 'object') {
5865

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
],
3232
"license": "ISC",
3333
"dependencies": {
34-
"@reactivex/rxjs": "5.0.0-alpha.7",
34+
"rxjs": "5.0.0-beta.0",
3535
"reflect-metadata": "^0.1.2"
3636
},
3737
"devDependencies": {

0 commit comments

Comments
 (0)