-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
TrackerTask.js
103 lines (89 loc) · 2.44 KB
/
TrackerTask.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
(function() {
/**
* TrackerTask utility.
* @constructor
* @extends {tracking.EventEmitter}
*/
tracking.TrackerTask = function(tracker) {
tracking.TrackerTask.base(this, 'constructor');
if (!tracker) {
throw new Error('Tracker instance not specified.');
}
this.setTracker(tracker);
};
tracking.inherits(tracking.TrackerTask, tracking.EventEmitter);
/**
* Holds the tracker instance managed by this task.
* @type {tracking.Tracker}
* @private
*/
tracking.TrackerTask.prototype.tracker_ = null;
/**
* Holds if the tracker task is in running.
* @type {boolean}
* @private
*/
tracking.TrackerTask.prototype.running_ = false;
/**
* Gets the tracker instance managed by this task.
* @return {tracking.Tracker}
*/
tracking.TrackerTask.prototype.getTracker = function() {
return this.tracker_;
};
/**
* Returns true if the tracker task is in running, false otherwise.
* @return {boolean}
* @private
*/
tracking.TrackerTask.prototype.inRunning = function() {
return this.running_;
};
/**
* Sets if the tracker task is in running.
* @param {boolean} running
* @private
*/
tracking.TrackerTask.prototype.setRunning = function(running) {
this.running_ = running;
};
/**
* Sets the tracker instance managed by this task.
* @return {tracking.Tracker}
*/
tracking.TrackerTask.prototype.setTracker = function(tracker) {
this.tracker_ = tracker;
};
/**
* Emits a `run` event on the tracker task for the implementers to run any
* child action, e.g. `requestAnimationFrame`.
* @return {object} Returns itself, so calls can be chained.
*/
tracking.TrackerTask.prototype.run = function() {
var self = this;
if (this.inRunning()) {
return;
}
this.setRunning(true);
this.reemitTrackEvent_ = function(event) {
self.emit('track', event);
};
this.tracker_.on('track', this.reemitTrackEvent_);
this.emit('run');
return this;
};
/**
* Emits a `stop` event on the tracker task for the implementers to stop any
* child action being done, e.g. `requestAnimationFrame`.
* @return {object} Returns itself, so calls can be chained.
*/
tracking.TrackerTask.prototype.stop = function() {
if (!this.inRunning()) {
return;
}
this.setRunning(false);
this.emit('stop');
this.tracker_.removeListener('track', this.reemitTrackEvent_);
return this;
};
}());