-
Notifications
You must be signed in to change notification settings - Fork 3
/
modules-OneFrameLogger.js
52 lines (43 loc) · 1.21 KB
/
modules-OneFrameLogger.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
(function() {
var ACTIVE_STATUS = {
NOT_STARTED: 0,
RUNNING: 1,
FINISHED: 2
}
var OneFrameLogger = function(options) {
var or = window.force.modules.helpers.or;
options = options || {};
this.startDelay = or(options.startDelay, 10000);
this.autoReport = or(options.autoReport, true);
this.status = ACTIVE_STATUS.NOT_STARTED;
this.logs = [];
};
OneFrameLogger.prototype.frameStart = function() {
if (this.status === ACTIVE_STATUS.FINISHED) {
return;
} else if (this.status === ACTIVE_STATUS.NOT_STARTED) {
var now = Date.now();
if (!this.startTime) {
this.startTime = now;
}
if (now - this.startTime > this.startDelay) {
this.status = ACTIVE_STATUS.RUNNING;
}
} else if (this.status === ACTIVE_STATUS.RUNNING) {
this.status = ACTIVE_STATUS.FINISHED;
if (this.autoReport) {
this.report();
}
}
};
OneFrameLogger.prototype.log = function(msg) {
if (this.status === ACTIVE_STATUS.RUNNING) {
this.logs.push(msg);
}
};
OneFrameLogger.prototype.report = function() {
console.log(this.logs);
};
// expose module
window.force.expose('window.force.modules.OneFrameLogger', OneFrameLogger);
})();