@@ -3,8 +3,13 @@ import { Observable } from './Observable';
3
3
import { empty } from './observable/empty' ;
4
4
import { of } from './observable/of' ;
5
5
import { throwError } from './observable/throwError' ;
6
+ import { deprecate } from 'util' ;
6
7
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 {
8
13
NEXT = 'N' ,
9
14
ERROR = 'E' ,
10
15
COMPLETE = 'C' ,
@@ -27,8 +32,8 @@ export const enum NotificationKind {
27
32
export class Notification < T > {
28
33
hasValue : boolean ;
29
34
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' ;
32
37
}
33
38
34
39
/**
@@ -38,11 +43,11 @@ export class Notification<T> {
38
43
*/
39
44
observe ( observer : PartialObserver < T > ) : any {
40
45
switch ( this . kind ) {
41
- case NotificationKind . NEXT :
46
+ case 'N' :
42
47
return observer . next && observer . next ( this . value ) ;
43
- case NotificationKind . ERROR :
48
+ case 'E' :
44
49
return observer . error && observer . error ( this . error ) ;
45
- case NotificationKind . COMPLETE :
50
+ case 'C' :
46
51
return observer . complete && observer . complete ( ) ;
47
52
}
48
53
}
@@ -58,11 +63,11 @@ export class Notification<T> {
58
63
do ( next : ( value : T ) => void , error ?: ( err : any ) => void , complete ?: ( ) => void ) : any {
59
64
const kind = this . kind ;
60
65
switch ( kind ) {
61
- case NotificationKind . NEXT :
66
+ case 'N' :
62
67
return next && next ( this . value ) ;
63
- case NotificationKind . ERROR :
68
+ case 'E' :
64
69
return error && error ( this . error ) ;
65
- case NotificationKind . COMPLETE :
70
+ case 'C' :
66
71
return complete && complete ( ) ;
67
72
}
68
73
}
@@ -92,18 +97,18 @@ export class Notification<T> {
92
97
toObservable ( ) : Observable < T > {
93
98
const kind = this . kind ;
94
99
switch ( kind ) {
95
- case NotificationKind . NEXT :
100
+ case 'N' :
96
101
return of ( this . value ) ;
97
- case NotificationKind . ERROR :
102
+ case 'E' :
98
103
return throwError ( this . error ) ;
99
- case NotificationKind . COMPLETE :
104
+ case 'C' :
100
105
return empty ( ) ;
101
106
}
102
107
throw new Error ( 'unexpected notification kind value' ) ;
103
108
}
104
109
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 ) ;
107
112
108
113
/**
109
114
* A shortcut to create a Notification instance of the type `next` from a
@@ -115,7 +120,7 @@ export class Notification<T> {
115
120
*/
116
121
static createNext < T > ( value : T ) : Notification < T > {
117
122
if ( typeof value !== 'undefined' ) {
118
- return new Notification ( NotificationKind . NEXT , value ) ;
123
+ return new Notification ( 'N' , value ) ;
119
124
}
120
125
return Notification . undefinedValueNotification ;
121
126
}
@@ -129,7 +134,7 @@ export class Notification<T> {
129
134
* @nocollapse
130
135
*/
131
136
static createError < T > ( err ?: any ) : Notification < T > {
132
- return new Notification ( NotificationKind . ERROR , undefined , err ) ;
137
+ return new Notification ( 'E' , undefined , err ) ;
133
138
}
134
139
135
140
/**
0 commit comments