are-we-there-yet
Advanced tools
Comparing version 1.0.5 to 1.0.6
38
index.js
"use strict" | ||
var stream = require("readable-stream"); | ||
var stream = require("readable-stream") | ||
var EventEmitter = require("events").EventEmitter | ||
@@ -7,2 +7,8 @@ var util = require("util") | ||
function noteChange (trackerGroup) { | ||
return function (name) { | ||
trackerGroup.emit('change', name || trackerGroup.name); | ||
} | ||
} | ||
var TrackerGroup = exports.TrackerGroup = function (name) { | ||
@@ -12,10 +18,4 @@ EventEmitter.call(this) | ||
this.trackGroup = [] | ||
var self = this | ||
this.totalWeight = 0 | ||
var noteChange = this.noteChange = function (name) { | ||
self.emit("change", name || this.name) | ||
}.bind(this) | ||
this.trackGroup.forEach(function(unit) { | ||
unit.on("change", noteChange) | ||
}) | ||
this.noteChange = noteChange(this) | ||
} | ||
@@ -28,5 +28,6 @@ util.inherits(TrackerGroup, EventEmitter) | ||
var completed = 0 | ||
this.trackGroup.forEach(function(T) { | ||
completed += valPerWeight * T.weight * T.completed() | ||
}) | ||
for (var i = 0, len = this.trackGroup.length; i < len; i++){ | ||
var group = this.trackGroup[i]; | ||
completed += valPerWeight * group.weight * group.completed() | ||
} | ||
return completed | ||
@@ -39,2 +40,3 @@ } | ||
this.trackGroup.push(unit) | ||
// Bubble events back up | ||
unit.on("change", this.noteChange) | ||
@@ -58,8 +60,8 @@ if (! noChange) this.emit("change", this.name) | ||
TrackerGroup.prototype.finish = function () { | ||
if (! this.trackGroup.length) { this.addUnit(new Tracker(), 1, true) } | ||
var self = this | ||
this.trackGroup.forEach(function(T) { | ||
T.removeListener("change", self.noteChange) | ||
T.finish() | ||
}) | ||
if (! this.trackGroup.length) this.addUnit(new Tracker(), 1, true) | ||
for (var i = 0, len = this.trackGroup.length; i < len; i++) { | ||
var group = this.trackGroup[i] | ||
group.removeListener("change", this.noteChange) | ||
group.finish() | ||
} | ||
this.emit("change", this.name) | ||
@@ -93,3 +95,3 @@ } | ||
Tracker.prototype.completed = function () { | ||
return this.workTodo==0 ? 0 : this.workDone / this.workTodo | ||
return this.workTodo === 0 ? 0 : this.workDone / this.workTodo | ||
} | ||
@@ -96,0 +98,0 @@ |
{ | ||
"name": "are-we-there-yet", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Keep track of the overall completion of many dispirate processes", | ||
@@ -20,8 +20,8 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tap": "^0.4.13" | ||
"tap": "^5.2.0" | ||
}, | ||
"dependencies": { | ||
"delegates": "^0.1.0", | ||
"delegates": "^1.0.0", | ||
"readable-stream": "^2.0.0 || ^1.1.13" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
295
17923
8
+ Addeddelegates@1.0.0(transitive)
- Removeddelegates@0.1.0(transitive)
Updateddelegates@^1.0.0