UNPKG

2.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var empty_1 = require("./observable/empty");
4var of_1 = require("./observable/of");
5var throwError_1 = require("./observable/throwError");
6var Notification = (function () {
7 function Notification(kind, value, error) {
8 this.kind = kind;
9 this.value = value;
10 this.error = error;
11 this.hasValue = kind === 'N';
12 }
13 Notification.prototype.observe = function (observer) {
14 switch (this.kind) {
15 case 'N':
16 return observer.next && observer.next(this.value);
17 case 'E':
18 return observer.error && observer.error(this.error);
19 case 'C':
20 return observer.complete && observer.complete();
21 }
22 };
23 Notification.prototype.do = function (next, error, complete) {
24 var kind = this.kind;
25 switch (kind) {
26 case 'N':
27 return next && next(this.value);
28 case 'E':
29 return error && error(this.error);
30 case 'C':
31 return complete && complete();
32 }
33 };
34 Notification.prototype.accept = function (nextOrObserver, error, complete) {
35 if (nextOrObserver && typeof nextOrObserver.next === 'function') {
36 return this.observe(nextOrObserver);
37 }
38 else {
39 return this.do(nextOrObserver, error, complete);
40 }
41 };
42 Notification.prototype.toObservable = function () {
43 var kind = this.kind;
44 switch (kind) {
45 case 'N':
46 return of_1.of(this.value);
47 case 'E':
48 return throwError_1.throwError(this.error);
49 case 'C':
50 return empty_1.empty();
51 }
52 throw new Error('unexpected notification kind value');
53 };
54 Notification.createNext = function (value) {
55 if (typeof value !== 'undefined') {
56 return new Notification('N', value);
57 }
58 return Notification.undefinedValueNotification;
59 };
60 Notification.createError = function (err) {
61 return new Notification('E', undefined, err);
62 };
63 Notification.createComplete = function () {
64 return Notification.completeNotification;
65 };
66 Notification.completeNotification = new Notification('C');
67 Notification.undefinedValueNotification = new Notification('N', undefined);
68 return Notification;
69}());
70exports.Notification = Notification;
71//# sourceMappingURL=Notification.js.map
\No newline at end of file