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 pathscopescheduler.js
72 lines (56 loc) · 2.16 KB
/
scopescheduler.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
var ScopeScheduler = Rx.ScopeScheduler = (function (__super__) {
function ScopeScheduler($scope) {
this.$scope = $scope;
__super__.call(this);
}
Rx.internals.inherits(ScopeScheduler, __super__);
ScopeScheduler.prototype.schedule = function (state, action) {
if (this.$scope.$$destroyed) { return Rx.Disposable.empty; }
var sad = new Rx.SingleAssignmentDisposable();
var $scope = this.$scope;
if ($scope.$$phase || $scope.$root.$$phase) {
sad.setDisposable(Rx.Disposable._fixup(state(action)));
} else {
$scope.$apply.call(
$scope,
function () { sad.setDisposable(Rx.Disposable._fixup(state(action))); }
);
}
};
ScopeScheduler.prototype._scheduleFuture = function (state, dueTime, action) {
if (this.$scope.$$destroyed) { return Rx.Disposable.empty; }
var sad = new Rx.SingleAssignmentDisposable();
var $scope = this.$scope;
var id = setTimeout(function () {
if ($scope.$$destroyed || sad.isDisposed) { return clearTimeout(id); }
if ($scope.$$phase || $scope.$root.$$phase) {
sad.setDisposable(Rx.Disposable._fixup(state(action)));
} else {
$scope.$apply.call(
$scope,
function () { sad.setDisposable(Rx.Disposable._fixup(state(action))); }
);
}
}, dueTime);
return new Rx.BinaryDisposable(
sad,
Rx.Disposable.create(function () { clearTimeout(id); })
);
};
ScopeScheduler.prototype.schedulePeriodic = function (state, period, action) {
if (this.$scope.$$destroyed) { return Rx.Disposable.empty; }
period = Rx.Scheduler.normalize(period);
var $scope = this.$scope;
var s = state;
var id = setInterval(function () {
if ($scope.$$destroyed) { return clearInterval(id); }
if ($scope.$$phase || $scope.$root.$$phase) {
s = action(s);
} else {
$scope.$apply.call($scope, function () { s = action(s); });
}
}, period);
return Rx.Disposable.create(function () { clearInterval(id); });
};
return ScopeScheduler;
}(Rx.Scheduler));