New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

alamid-junction

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alamid-junction - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

67

lib/Junction.js

@@ -30,2 +30,18 @@ "use strict";

/**
* Stores all values that are no signals.
*
* @type {Object}
* @private
*/
Junction.prototype._values = null;
/**
* Stores all signals that have been created by the junction.
*
* @type {Object}
* @private
*/
Junction.prototype._signals = null;
/**
* The Junction's real constructor. You may override this in a plugin to hook into construction.

@@ -35,2 +51,3 @@ */

this._signals = {};
this._values = {};
};

@@ -74,6 +91,6 @@

if (isSignal.call(this, signal)) {
if (signal) {
signal(value);
} else {
this._signals[key] = value;
this._values[key] = value;
}

@@ -93,4 +110,4 @@ };

if (arguments.length === 0) {
obj = this._signals;
result = {};
obj = this._values;
for (key in obj) {

@@ -118,3 +135,3 @@ if (obj.hasOwnProperty(key)) {

return (isSignal.call(this, signal))? signal() : signal;
return signal? signal() : this._values[key];
};

@@ -129,3 +146,3 @@

Junction.prototype.reset = function (value) {
var obj = this._signals,
var obj = this._values,
key;

@@ -143,2 +160,20 @@

/**
* Removes the given key from the internal value store and sets the signal on undefined.
*
* @param {String} key
* @returns {Junction}
*/
Junction.prototype.unset = function (key) {
var signal;
delete this._values[key];
signal = this._signals[key];
if (signal) {
signal(undefined);
}
return this;
};
/**
* Returns the signal instance to the given key.

@@ -152,6 +187,6 @@ *

if (isSignal.call(this, signal) === false) {
if (!signal) {
signal = new this.Signal();
signal.junction = this;
signal(this.getter(key));
this._signals[key] = signal;

@@ -171,3 +206,2 @@ }

var signals = this._signals,
signal,
key;

@@ -177,6 +211,3 @@

if (signals.hasOwnProperty(key)) {
signal = signals[key];
if (isSignal.call(this, signal)) {
signal.dispose();
}
signals[key].dispose();
}

@@ -186,2 +217,3 @@ }

this._signals = null;
this._values = null;
this.isDisposed = true;

@@ -211,13 +243,2 @@ };

/**
* Determines if the given value is a signal and if it was created by this junction.
*
* @private
* @param {*} value
* @returns {boolean}
*/
function isSignal(value) { /* jshint validthis: true */
return Boolean(value) && value.junction === this;
}
module.exports = Junction;
{
"name": "alamid-junction",
"version": "0.4.0",
"version": "0.5.0",
"description": "Provides convenient methods for setting and retrieving multiple signals",

@@ -5,0 +5,0 @@ "main": "./lib/Junction.js",

@@ -209,2 +209,6 @@ "use strict";

it("should be chainable", function () {
expect(junction.reset()).to.equal(junction);
});
});

@@ -230,2 +234,30 @@

describe(".unset(key)", function () {
beforeEach(function () {
junction.set("greeting", "Ahoy!");
junction.set("age", 34);
});
it("should remove the key from the junction", function () {
junction.unset("greeting");
expect(junction.get()).to.eql({
age: 34
});
});
it("should set the key's signal to undefined", function () {
var signal = junction.signal("greeting");
expect(signal()).to.equal("Ahoy!");
junction.unset("greeting");
expect(signal()).to.equal(undefined);
});
it("should be chainable", function () {
expect(junction.unset("greeting")).to.equal(junction);
});
});
describe(".signal(key)", function () {

@@ -308,2 +340,3 @@

expect(junction._signals).to.equal(null);
expect(junction._values).to.equal(null);
});

@@ -310,0 +343,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc