Skip to content

Commit e460eec

Browse files
cartantbenlesh
authored andcommitted
fix(Notification): replace const enum (#4556)
* fix(Notification): replace const enum Closes#4538 * chore: use literal union and keep enum The enum is kept, but it is no longer a const enum. It cannot be exported as a const enum without effecting an error if isolated modules are used.
1 parent 2aa666b commit e460eec

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

‎src/internal/Notification.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ import { Observable } from './Observable';
33
import{empty}from'./observable/empty';
44
import{of}from'./observable/of';
55
import{throwError}from'./observable/throwError';
6+
import{deprecate}from'util';
67

7-
exportconstenumNotificationKind{
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+
exportenumNotificationKind{
813
NEXT='N',
914
ERROR='E',
1015
COMPLETE='C',
@@ -27,8 +32,8 @@ export const enum NotificationKind {
2732
exportclassNotification<T>{
2833
hasValue: boolean;
2934

30-
constructor(publickind: NotificationKind,publicvalue?: T,publicerror?: any){
31-
this.hasValue=kind===NotificationKind.NEXT;
35+
constructor(publickind: 'N'|'E'|'C',publicvalue?: T,publicerror?: any){
36+
this.hasValue=kind==='N';
3237
}
3338

3439
/**
@@ -38,11 +43,11 @@ export class Notification<T> {
3843
*/
3944
observe(observer: PartialObserver<T>): any{
4045
switch(this.kind){
41-
caseNotificationKind.NEXT:
46+
case'N':
4247
returnobserver.next&&observer.next(this.value);
43-
caseNotificationKind.ERROR:
48+
case'E':
4449
returnobserver.error&&observer.error(this.error);
45-
caseNotificationKind.COMPLETE:
50+
case'C':
4651
returnobserver.complete&&observer.complete();
4752
}
4853
}
@@ -58,11 +63,11 @@ export class Notification<T> {
5863
do(next: (value: T)=>void,error?: (err: any)=>void,complete?: ()=>void): any{
5964
constkind=this.kind;
6065
switch(kind){
61-
caseNotificationKind.NEXT:
66+
case'N':
6267
returnnext&&next(this.value);
63-
caseNotificationKind.ERROR:
68+
case'E':
6469
returnerror&&error(this.error);
65-
caseNotificationKind.COMPLETE:
70+
case'C':
6671
returncomplete&&complete();
6772
}
6873
}
@@ -92,18 +97,18 @@ export class Notification<T> {
9297
toObservable(): Observable<T>{
9398
constkind=this.kind;
9499
switch(kind){
95-
caseNotificationKind.NEXT:
100+
case'N':
96101
returnof(this.value);
97-
caseNotificationKind.ERROR:
102+
case'E':
98103
returnthrowError(this.error);
99-
caseNotificationKind.COMPLETE:
104+
case'C':
100105
returnempty();
101106
}
102107
thrownewError('unexpected notification kind value');
103108
}
104109

105-
privatestaticcompleteNotification: Notification<any>=newNotification(NotificationKind.COMPLETE);
106-
privatestaticundefinedValueNotification: Notification<any>=newNotification(NotificationKind.NEXT,undefined);
110+
privatestaticcompleteNotification: Notification<any>=newNotification('C');
111+
privatestaticundefinedValueNotification: Notification<any>=newNotification('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
*/
116121
staticcreateNext<T>(value: T): Notification<T>{
117122
if(typeofvalue!=='undefined'){
118-
returnnewNotification(NotificationKind.NEXT,value);
123+
returnnewNotification('N',value);
119124
}
120125
returnNotification.undefinedValueNotification;
121126
}
@@ -129,7 +134,7 @@ export class Notification<T> {
129134
* @nocollapse
130135
*/
131136
staticcreateError<T>(err?: any): Notification<T>{
132-
returnnewNotification(NotificationKind.ERROR,undefined,err);
137+
returnnewNotification('E',undefined,err);
133138
}
134139

135140
/**

0 commit comments

Comments
 (0)