@@ -3,8 +3,13 @@ import { Observable } from './Observable';
33import { empty } from './observable/empty' ;
44import { of } from './observable/of' ;
55import { throwError } from './observable/throwError' ;
6+ import { deprecate } from 'util' ;
67
7- export const enum NotificationKind {
8+ // TODO: When this enum is removed, replace it with a type alias. See #4556.
9+ /**
10+ * @deprecated NotificationKind is deprecated as const enums are not compatible with isolated modules. Use a string literal instead.
11+ */
12+ export enum NotificationKind {
813NEXT = 'N' ,
914ERROR = 'E' ,
1015COMPLETE = 'C' ,
@@ -27,8 +32,8 @@ export const enum NotificationKind {
2732export class Notification < T > {
2833hasValue : boolean ;
2934
30- constructor ( public kind : NotificationKind , public value ?: T , public error ?: any ) {
31- this . hasValue = kind === NotificationKind . NEXT ;
35+ constructor ( public kind : 'N' | 'E' | 'C' , public value ?: T , public error ?: any ) {
36+ this . hasValue = kind === 'N' ;
3237}
3338
3439/**
@@ -38,11 +43,11 @@ export class Notification<T> {
3843 */
3944observe ( observer : PartialObserver < T > ) : any {
4045switch ( this . kind ) {
41- case NotificationKind . NEXT :
46+ case 'N' :
4247return observer . next && observer . next ( this . value ) ;
43- case NotificationKind . ERROR :
48+ case 'E' :
4449return observer . error && observer . error ( this . error ) ;
45- case NotificationKind . COMPLETE :
50+ case 'C' :
4651return observer . complete && observer . complete ( ) ;
4752}
4853}
@@ -58,11 +63,11 @@ export class Notification<T> {
5863do ( next : ( value : T ) => void , error ?: ( err : any ) => void , complete ?: ( ) => void ) : any {
5964const kind = this . kind ;
6065switch ( kind ) {
61- case NotificationKind . NEXT :
66+ case 'N' :
6267return next && next ( this . value ) ;
63- case NotificationKind . ERROR :
68+ case 'E' :
6469return error && error ( this . error ) ;
65- case NotificationKind . COMPLETE :
70+ case 'C' :
6671return complete && complete ( ) ;
6772}
6873}
@@ -92,18 +97,18 @@ export class Notification<T> {
9297toObservable ( ) : Observable < T > {
9398const kind = this . kind ;
9499switch ( kind ) {
95- case NotificationKind . NEXT :
100+ case 'N' :
96101return of ( this . value ) ;
97- case NotificationKind . ERROR :
102+ case 'E' :
98103return throwError ( this . error ) ;
99- case NotificationKind . COMPLETE :
104+ case 'C' :
100105return empty ( ) ;
101106}
102107throw new Error ( 'unexpected notification kind value' ) ;
103108}
104109
105- private static completeNotification : Notification < any > = new Notification ( NotificationKind . COMPLETE ) ;
106- private static undefinedValueNotification : Notification < any > = new Notification ( NotificationKind . NEXT , undefined ) ;
110+ private static completeNotification : Notification < any > = new Notification ( 'C' ) ;
111+ private static undefinedValueNotification : Notification < any > = new Notification ( 'N' , undefined ) ;
107112
108113/**
109114 * A shortcut to create a Notification instance of the type `next` from a
@@ -115,7 +120,7 @@ export class Notification<T> {
115120 */
116121static createNext < T > ( value : T ) : Notification < T > {
117122if ( typeof value !== 'undefined' ) {
118- return new Notification ( NotificationKind . NEXT , value ) ;
123+ return new Notification ( 'N' , value ) ;
119124}
120125return Notification . undefinedValueNotification ;
121126}
@@ -129,7 +134,7 @@ export class Notification<T> {
129134 * @nocollapse
130135 */
131136static createError < T > ( err ?: any ) : Notification < T > {
132- return new Notification ( NotificationKind . ERROR , undefined , err ) ;
137+ return new Notification ( 'E' , undefined , err ) ;
133138}
134139
135140/**
0 commit comments