source: trip-planner-front/node_modules/are-we-there-yet/tracker.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 826 bytes
RevLine 
[6a3a178]1'use strict'
2var util = require('util')
3var TrackerBase = require('./tracker-base.js')
4
5var Tracker = module.exports = function (name, todo) {
6 TrackerBase.call(this, name)
7 this.workDone = 0
8 this.workTodo = todo || 0
9}
10util.inherits(Tracker, TrackerBase)
11
12Tracker.prototype.completed = function () {
13 return this.workTodo === 0 ? 0 : this.workDone / this.workTodo
14}
15
16Tracker.prototype.addWork = function (work) {
17 this.workTodo += work
18 this.emit('change', this.name, this.completed(), this)
19}
20
21Tracker.prototype.completeWork = function (work) {
22 this.workDone += work
23 if (this.workDone > this.workTodo) this.workDone = this.workTodo
24 this.emit('change', this.name, this.completed(), this)
25}
26
27Tracker.prototype.finish = function () {
28 this.workTodo = this.workDone = 1
29 this.emit('change', this.name, 1, this)
30}
Note: See TracBrowser for help on using the repository browser.