1 | /** PURE_IMPORTS_START _observable_empty,_observable_of,_observable_throwError PURE_IMPORTS_END */
|
---|
2 | import { empty } from './observable/empty';
|
---|
3 | import { of } from './observable/of';
|
---|
4 | import { throwError } from './observable/throwError';
|
---|
5 | export var NotificationKind;
|
---|
6 | /*@__PURE__*/ (function (NotificationKind) {
|
---|
7 | NotificationKind["NEXT"] = "N";
|
---|
8 | NotificationKind["ERROR"] = "E";
|
---|
9 | NotificationKind["COMPLETE"] = "C";
|
---|
10 | })(NotificationKind || (NotificationKind = {}));
|
---|
11 | var Notification = /*@__PURE__*/ (function () {
|
---|
12 | function Notification(kind, value, error) {
|
---|
13 | this.kind = kind;
|
---|
14 | this.value = value;
|
---|
15 | this.error = error;
|
---|
16 | this.hasValue = kind === 'N';
|
---|
17 | }
|
---|
18 | Notification.prototype.observe = function (observer) {
|
---|
19 | switch (this.kind) {
|
---|
20 | case 'N':
|
---|
21 | return observer.next && observer.next(this.value);
|
---|
22 | case 'E':
|
---|
23 | return observer.error && observer.error(this.error);
|
---|
24 | case 'C':
|
---|
25 | return observer.complete && observer.complete();
|
---|
26 | }
|
---|
27 | };
|
---|
28 | Notification.prototype.do = function (next, error, complete) {
|
---|
29 | var kind = this.kind;
|
---|
30 | switch (kind) {
|
---|
31 | case 'N':
|
---|
32 | return next && next(this.value);
|
---|
33 | case 'E':
|
---|
34 | return error && error(this.error);
|
---|
35 | case 'C':
|
---|
36 | return complete && complete();
|
---|
37 | }
|
---|
38 | };
|
---|
39 | Notification.prototype.accept = function (nextOrObserver, error, complete) {
|
---|
40 | if (nextOrObserver && typeof nextOrObserver.next === 'function') {
|
---|
41 | return this.observe(nextOrObserver);
|
---|
42 | }
|
---|
43 | else {
|
---|
44 | return this.do(nextOrObserver, error, complete);
|
---|
45 | }
|
---|
46 | };
|
---|
47 | Notification.prototype.toObservable = function () {
|
---|
48 | var kind = this.kind;
|
---|
49 | switch (kind) {
|
---|
50 | case 'N':
|
---|
51 | return of(this.value);
|
---|
52 | case 'E':
|
---|
53 | return throwError(this.error);
|
---|
54 | case 'C':
|
---|
55 | return empty();
|
---|
56 | }
|
---|
57 | throw new Error('unexpected notification kind value');
|
---|
58 | };
|
---|
59 | Notification.createNext = function (value) {
|
---|
60 | if (typeof value !== 'undefined') {
|
---|
61 | return new Notification('N', value);
|
---|
62 | }
|
---|
63 | return Notification.undefinedValueNotification;
|
---|
64 | };
|
---|
65 | Notification.createError = function (err) {
|
---|
66 | return new Notification('E', undefined, err);
|
---|
67 | };
|
---|
68 | Notification.createComplete = function () {
|
---|
69 | return Notification.completeNotification;
|
---|
70 | };
|
---|
71 | Notification.completeNotification = new Notification('C');
|
---|
72 | Notification.undefinedValueNotification = new Notification('N', undefined);
|
---|
73 | return Notification;
|
---|
74 | }());
|
---|
75 | export { Notification };
|
---|
76 | //# sourceMappingURL=Notification.js.map
|
---|