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 88
/
Copy pathfactory.js
63 lines (54 loc) · 1.8 KB
/
factory.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
/**
* @ngdoc service
* @name rx.rx
*
* @requires $window
*
* @description
* Factory service that exposes the global `Rx` object to the Angular world.
*/
rxModule.factory('rx', function($window) {
$window.Rx || ($window.Rx = Rx);
var CreateObservableFunction = (function(__super__) {
Rx.internals.inherits(CreateObservableFunction, __super__);
function CreateObservableFunction(self, name, fn) {
this._self = self;
this._name = name;
this._fn = fn;
__super__.call(this);
}
CreateObservableFunction.prototype.subscribeCore = function (o) {
var fn = this._fn;
this._self[this._name] = function () {
var len = arguments.length, args = new Array(len);
for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
if (angular.isFunction(fn)) {
var result = tryCatch(fn).apply(this, args);
if (result === errorObj) { return o.onError(result.e); }
o.onNext(result);
} else if (args.length === 1) {
o.onNext(args[0]);
} else {
o.onNext(args);
}
};
return new InnerDisposable(this._self, this._name);
};
function InnerDisposable(self, name) {
this._self = self;
this._name = name;
this.isDisposed = false;
}
InnerDisposable.prototype.dispose = function () {
if (!this.isDisposed) {
this.isDisposed = true;
delete this._self[this._name];
}
};
return CreateObservableFunction;
}(Rx.ObservableBase));
Rx.createObservableFunction = function (self, functionName, listener) {
return new CreateObservableFunction(self, functionName, listener).publish().refCount();
};
return $window.Rx;
});