This repository was archived by the owner on Apr 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathnotification.js
140 lines (116 loc) · 4.62 KB
/
notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* Represents a notification to an observer.
*/
var Notification = Rx.Notification = (function () {
function Notification() {
}
Notification.prototype._accept = function (onNext, onError, onCompleted) {
throw new NotImplementedError();
};
Notification.prototype._acceptObserver = function (onNext, onError, onCompleted) {
throw new NotImplementedError();
};
/**
* Invokes the delegate corresponding to the notification or the observer's method corresponding to the notification and returns the produced result.
* @param {Function | Observer} observerOrOnNext Function to invoke for an OnNext notification or Observer to invoke the notification on..
* @param {Function} onError Function to invoke for an OnError notification.
* @param {Function} onCompleted Function to invoke for an OnCompleted notification.
* @returns {Any} Result produced by the observation.
*/
Notification.prototype.accept = function (observerOrOnNext, onError, onCompleted) {
return observerOrOnNext && typeof observerOrOnNext === 'object' ?
this._acceptObserver(observerOrOnNext) :
this._accept(observerOrOnNext, onError, onCompleted);
};
/**
* Returns an observable sequence with a single notification.
*
* @memberOf Notifications
* @param {Scheduler} [scheduler] Scheduler to send out the notification calls on.
* @returns {Observable} The observable sequence that surfaces the behavior of the notification upon subscription.
*/
Notification.prototype.toObservable = function (scheduler) {
var self = this;
isScheduler(scheduler) || (scheduler = immediateScheduler);
return new AnonymousObservable(function (o) {
return scheduler.schedule(self, function (_, notification) {
notification._acceptObserver(o);
notification.kind === 'N' && o.onCompleted();
});
});
};
return Notification;
})();
var OnNextNotification = (function (__super__) {
inherits(OnNextNotification, __super__);
function OnNextNotification(value) {
this.value = value;
this.kind = 'N';
}
OnNextNotification.prototype._accept = function (onNext) {
return onNext(this.value);
};
OnNextNotification.prototype._acceptObserver = function (o) {
return o.onNext(this.value);
};
OnNextNotification.prototype.toString = function () {
return 'OnNext(' + this.value + ')';
};
return OnNextNotification;
}(Notification));
var OnErrorNotification = (function (__super__) {
inherits(OnErrorNotification, __super__);
function OnErrorNotification(error) {
this.error = error;
this.kind = 'E';
}
OnErrorNotification.prototype._accept = function (onNext, onError) {
return onError(this.error);
};
OnErrorNotification.prototype._acceptObserver = function (o) {
return o.onError(this.error);
};
OnErrorNotification.prototype.toString = function () {
return 'OnError(' + this.error + ')';
};
return OnErrorNotification;
}(Notification));
var OnCompletedNotification = (function (__super__) {
inherits(OnCompletedNotification, __super__);
function OnCompletedNotification() {
this.kind = 'C';
}
OnCompletedNotification.prototype._accept = function (onNext, onError, onCompleted) {
return onCompleted();
};
OnCompletedNotification.prototype._acceptObserver = function (o) {
return o.onCompleted();
};
OnCompletedNotification.prototype.toString = function () {
return 'OnCompleted()';
};
return OnCompletedNotification;
}(Notification));
/**
* Creates an object that represents an OnNext notification to an observer.
* @param {Any} value The value contained in the notification.
* @returns {Notification} The OnNext notification containing the value.
*/
var notificationCreateOnNext = Notification.createOnNext = function (value) {
return new OnNextNotification(value);
};
/**
* Creates an object that represents an OnError notification to an observer.
* @param {Any} error The exception contained in the notification.
* @returns {Notification} The OnError notification containing the exception.
*/
var notificationCreateOnError = Notification.createOnError = function (error) {
return new OnErrorNotification(error);
};
/**
* Creates an object that represents an OnCompleted notification to an observer.
* @returns {Notification} The OnCompleted notification.
*/
var notificationCreateOnCompleted = Notification.createOnCompleted = function () {
return new OnCompletedNotification();
};