alamid-junction
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -9,3 +9,3 @@ "use strict"; | ||
function Junction() { | ||
this._signals = {}; | ||
Junction.prototype.constructor.apply(this, arguments); | ||
} | ||
@@ -22,2 +22,18 @@ | ||
/** | ||
* Signalizes whether the junction has already been disposed. This flag is useful | ||
* if you don't know if it save to call a junction method like signal() without causing a crash. | ||
* | ||
* @type {boolean} | ||
* @readonly | ||
*/ | ||
Junction.prototype.isDisposed = false; | ||
/** | ||
* The Junction's real constructor. You may override this in a plugin to hook into construction. | ||
*/ | ||
Junction.prototype.constructor = function () { | ||
this._signals = {}; | ||
}; | ||
/** | ||
* Set a single or multiple values with one call. | ||
@@ -143,5 +159,27 @@ * | ||
this._signals = null; | ||
this.isDisposed = true; | ||
}; | ||
/** | ||
* Calls the given function with the Junction as first argument and the given config (optionally). Plugins can be used | ||
* to hook into class methods by overriding them. | ||
* | ||
* You may call this function multiple times with the same plugin, the plugin will only be applied once. | ||
* | ||
* @param {Function} plugin | ||
* @param {Object=} config | ||
* @returns {Function} | ||
*/ | ||
Junction.use = function (plugin, config) { | ||
this._plugins = this._plugins || []; | ||
if (this._plugins.indexOf(plugin) === -1) { | ||
plugin(this, config); | ||
this._plugins.push(plugin); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Determines if the given value is a signal and if it was created by this junction. | ||
@@ -148,0 +186,0 @@ * |
{ | ||
"name": "alamid-junction", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Provides convenient methods for setting and retrieving multiple signals", | ||
@@ -34,3 +34,3 @@ "main": "./lib/Junction.js", | ||
"type": "git", | ||
"url": "https://github.com/peerigon/alamid-signal.git" | ||
"url": "https://github.com/peerigon/alamid-junction.git" | ||
}, | ||
@@ -37,0 +37,0 @@ "testling": { |
@@ -14,8 +14,35 @@ "use strict"; | ||
beforeEach(function () { | ||
junction = new Junction(); | ||
}); | ||
describe(".use(plugin, config?)", function () { | ||
var plugin, | ||
config; | ||
it("should be an instance of Junction", function () { | ||
expect(junction).to.be.an.instanceof(Junction); | ||
beforeEach(function () { | ||
plugin = sinon.spy(); | ||
config = {}; | ||
}); | ||
it("should provide a plugin-interface", function () { | ||
Junction.use(plugin, config); | ||
expect(plugin).to.have.been.calledWith(Junction, config); | ||
}); | ||
it("should apply the same plugin only once", function () { | ||
Junction.use(plugin, config); | ||
Junction.use(plugin, config); | ||
expect(plugin).to.have.been.calledOnce; | ||
}); | ||
it("should be usable on other objects too", function () { | ||
var otherObj = { | ||
use: Junction.use | ||
}; | ||
otherObj.use(plugin); | ||
expect(plugin).to.have.been.calledWith(otherObj); | ||
}); | ||
it("should be chainable", function () { | ||
expect(Junction.use(function () {})).to.equal(Junction); | ||
}); | ||
}); | ||
@@ -44,6 +71,43 @@ | ||
beforeEach(function () { | ||
junction = new Junction(); | ||
}); | ||
after(function () { | ||
delete Junction.prototype.Signal; | ||
}); | ||
describe(".constructor()", function () { | ||
it("should be an override-able function", function () { | ||
var constructor = Junction.prototype.constructor; | ||
expect(constructor).to.be.a("function"); | ||
Junction.prototype.constructor = sinon.spy(); | ||
junction = new Junction(); | ||
expect(Junction.prototype.constructor).to.have.been.called; | ||
Junction.prototype.constructor = constructor; | ||
}); | ||
it("should return an instance of Junction", function () { | ||
expect(new Junction()).to.be.an.instanceof(Junction); | ||
}); | ||
}); | ||
describe(".isDisposed", function () { | ||
it("should be false by default", function () { | ||
expect(junction.isDisposed).to.equal(false); | ||
}); | ||
it("should be true after junction.dispose() has been called", function () { | ||
junction.dispose(); | ||
expect(junction.isDisposed).to.equal(true); | ||
}); | ||
}); | ||
describe(".get() before data has been set", function () { | ||
@@ -50,0 +114,0 @@ |
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
15251
358