@jdcfe/yep-react
Version:
一套移动端的React组件库
30 lines (27 loc) • 602 B
JavaScript
var TimerService = {
queue: [],
register: function register(fn) {
this.queue.push(fn);
if (!this.timer) {
this.startTimer();
}
},
unregister: function unregister(fn) {
this.queue = this.queue.filter(function (f) {
return f !== fn;
});
if (!this.queue.length) {
clearInterval(this.timer);
this.timer = null;
}
},
startTimer: function startTimer() {
var _this = this;
this.timer = setInterval(function () {
_this.queue.forEach(function (cb) {
return cb();
});
}, 1000);
}
};
export default TimerService;