alamid-list
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -27,3 +27,3 @@ "use strict"; | ||
* | ||
* @type {{emit: Function, on: Function, removeListener: Function}} | ||
* @type {{emit: Function, on: Function, removeListener: Function, removeAllListeners: Function}} | ||
*/ | ||
@@ -33,3 +33,4 @@ List.prototype.config = { | ||
on: throwMethodMissingError("on"), | ||
removeListener: throwMethodMissingError("removeListener") | ||
removeListener: throwMethodMissingError("removeListener"), | ||
removeAllListeners: throwMethodMissingError("removeAllListeners") | ||
}; | ||
@@ -217,2 +218,7 @@ | ||
List.prototype.dispose = function () { | ||
delete this._elements; | ||
this.config.removeAllListeners.call(this); | ||
}; | ||
["concat", "join", "slice", "indexOf", "lastIndexOf", "toString", "forEach", "every", "some", "filter", "map", "reduce", "reduceRight"] | ||
@@ -226,9 +232,4 @@ .forEach(function (method) { | ||
List.configure = function (newConfig) { | ||
var config = List.prototype.config, | ||
key; | ||
this.prototype.config = newConfig; | ||
for (key in newConfig) { /* jshint forin:false */ | ||
config[key] = newConfig[key]; | ||
} | ||
return this; | ||
@@ -235,0 +236,0 @@ }; |
{ | ||
"name": "alamid-list", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Simple observable arrays", | ||
@@ -5,0 +5,0 @@ "main": "./lib/List.js", |
@@ -14,2 +14,3 @@ "use strict"; | ||
config.removeListener = proto.removeListener; | ||
config.removeAllListeners = proto.removeAllListeners; | ||
@@ -16,0 +17,0 @@ for (key in proto) { /* jshint forin: false */ |
@@ -6,4 +6,10 @@ "use strict"; | ||
function watch(List) { | ||
var dispose = List.prototype.dispose; | ||
List.prototype.watch = instance.watch; | ||
List.prototype.unwatch = instance.unwatch; | ||
List.prototype.dispose = function () { | ||
this.unwatch(); | ||
dispose.call(this); | ||
}; | ||
} | ||
@@ -10,0 +16,0 @@ |
@@ -17,2 +17,3 @@ "use strict"; | ||
function removeListener() {} | ||
function removeAllListeners() {} | ||
@@ -23,3 +24,4 @@ it("should set the given config", function () { | ||
on: on, | ||
removeListener: removeListener | ||
removeListener: removeListener, | ||
removeAllListeners: removeAllListeners | ||
}); | ||
@@ -30,2 +32,3 @@ | ||
expect(List.prototype.config.removeListener).to.equal(removeListener); | ||
expect(List.prototype.config.removeAllListeners).to.equal(removeAllListeners); | ||
}); | ||
@@ -468,2 +471,22 @@ | ||
}); | ||
describe(".dispose()", function () { | ||
it("should call removeAllListeners() on the set", function () { | ||
var removeAllListeners; | ||
list.config = Object.create(list.config); | ||
list.config.removeAllListeners = removeAllListeners = sinon.spy(); | ||
list.dispose(); | ||
expect(removeAllListeners).to.have.been.calledOnce; | ||
}); | ||
it("should clear the _elements reference", function () { | ||
list.dispose(); | ||
expect(list._elements).to.not.be.ok; | ||
}); | ||
}); | ||
@@ -470,0 +493,0 @@ describe(".concat()", function () { |
@@ -22,2 +22,3 @@ "use strict"; | ||
expect(list.config.removeListener).to.equal(emitter.removeListener); | ||
expect(list.config.removeAllListeners).to.equal(emitter.removeAllListeners); | ||
}); | ||
@@ -24,0 +25,0 @@ |
"use strict"; | ||
var chai = require("chai"), | ||
sinon = require("sinon"), | ||
List = require("../lib/List.js"), | ||
@@ -21,9 +22,9 @@ emitter = require("events").EventEmitter.prototype, | ||
Slave.use = List.use; | ||
Slave.configure = List.configure; | ||
Slave.prototype = Object.create(List.prototype); | ||
Slave.use(watch); | ||
Slave.configure({ | ||
List.configure({ | ||
emit: emitter.emit, | ||
on: emitter.on, | ||
removeListener: emitter.removeListener | ||
removeListener: emitter.removeListener, | ||
removeAllListeners: emitter.removeAllListeners | ||
}); | ||
@@ -141,5 +142,31 @@ }); | ||
}); | ||
describe(".dispose()", function () { | ||
it("should call .unwatch()", function () { | ||
var unwatch; | ||
slave.watch(master); | ||
slave.unwatch = unwatch = sinon.spy(); | ||
slave.dispose(); | ||
expect(unwatch).to.have.been.calledOnce; | ||
}); | ||
it("should also call List.prototype.dispose()", function () { | ||
slave.watch(master); | ||
slave.dispose(); | ||
// we cannot just monkey-patch List.prototype.dispose because the | ||
// original reference has already been stored by calling | ||
// List.use() | ||
// That's why we're checking for a side-effect of dispose() | ||
expect(slave._elements).to.not.be.ok; | ||
}); | ||
}); | ||
}); | ||
}); |
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
49895
1233