@@ -90,20 +90,46 @@ export class Observable {
9090} 
9191
9292/** 
93+  * Use by directives and components to emit custom {@link  Event}s. 
94+  * 
95+  * ## Examples 
96+  * 
97+  * In the following example, `Zippy` alternatively emits `open` and `close` events when its 
98+  * title gets clicked: 
99+  * 
100+  * ``` 
101+  * @Component ({selector: 'zippy'}) 
102+  * @View ({template: ` 
103+  *   <div class="zippy"> 
104+  *     <div (click)="toggle()">Toggle</div> 
105+  *     <div [hidden]="!visible"> 
106+  *       <ng-content></ng-content> 
107+  *     </div> 
108+  *  </div>`}) 
109+  * export class Zippy { 
110+  *   visible: boolean = true; 
111+  *   @Event () open: EventEmitter = new EventEmitter(); 
112+  *   @Event () close: EventEmitter = new EventEmitter(); 
113+  * 
114+  *   toggle() { 
115+  *     this.visible = !this.visible; 
116+  *     if (this.visible) { 
117+  *       this.open.next(null); 
118+  *     } else { 
119+  *       this.close.next(null); 
120+  *     } 
121+  *   } 
122+  * } 
123+  * ``` 
124+  * 
93125 * Use Rx.Observable but provides an adapter to make it work as specified here: 
94126 * https://github.com/jhusain/observable-spec 
95127 * 
96128 * Once a reference implementation of the spec is available, switch to it. 
97129 */ 
98130export  class  EventEmitter  extends  Observable  { 
99-   _subject : Rx . Subject < any > ; 
100-   _immediateScheduler ; 
101- 
102-   constructor ( )  { 
103-     super ( ) ; 
104-     this . _subject  =  new  Rx . Subject < any > ( ) ; 
105-     this . _immediateScheduler  =  ( < any > Rx . Scheduler ) . immediate ; 
106-   } 
131+   _subject : Rx . Subject < any >  =  new  Rx . Subject < any > ( ) ; 
132+   _immediateScheduler  =  ( < any > Rx . Scheduler ) . immediate ; 
107133
108134  observer ( generator : any ) : Rx . IDisposable  { 
109135    return  this . _subject . observeOn ( this . _immediateScheduler ) 
@@ -114,9 +140,18 @@ export class EventEmitter extends Observable {
114140
115141  toRx ( ) : Rx . Observable < any >  {  return  this . _subject ;  } 
116142
143+   /** 
144+    * Emits a `value`. 
145+    */ 
117146  next ( value : any )  {  this . _subject . onNext ( value ) ;  } 
118147
148+   /** 
149+    * Emits an `error`. 
150+    */ 
119151  throw ( error : any )  {  this . _subject . onError ( error ) ;  } 
120152
153+   /** 
154+    * Closes the stream. 
155+    */ 
121156  return  ( value ?: any )  {  this . _subject . onCompleted ( ) ;  } 
122157} 
0 commit comments