Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-signals

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

typed-signals - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

44

dist/src/Signal.js

@@ -37,6 +37,4 @@ "use strict";

this.callback = null;
if (this.next)
this.next.prev = this.prev;
if (this.prev)
this.prev.next = this.next;
this.next.prev = this.prev;
this.prev.next = this.next;
};

@@ -162,6 +160,4 @@ SignalLink.prototype.insert = function (callback, order) {

Signal.prototype.disconnectAll = function () {
if (this.head) {
while (this.head.next !== this.head) {
this.head.next.unlink();
}
while (this.head.next !== this.head) {
this.head.next.unlink();
}

@@ -213,10 +209,2 @@ };

}
/**
* Process the results of a handler invocation.
*
* @param result true to continue processing handlers.
*/
Collector.prototype.handleResult = function (result) {
return true;
};
return Collector;

@@ -243,2 +231,8 @@ }());

};
/**
* Reset the result
*/
CollectorLast.prototype.reset = function () {
delete this.result;
};
return CollectorLast;

@@ -267,2 +261,8 @@ }(Collector));

};
/**
* Reset the result
*/
CollectorUntil0.prototype.reset = function () {
this.result = false;
};
return CollectorUntil0;

@@ -291,2 +291,8 @@ }(Collector));

};
/**
* Reset the result
*/
CollectorWhile0.prototype.reset = function () {
this.result = false;
};
return CollectorWhile0;

@@ -315,2 +321,8 @@ }(Collector));

};
/**
* Reset the result
*/
CollectorArray.prototype.reset = function () {
this.result.length = 0;
};
return CollectorArray;

@@ -317,0 +329,0 @@ }(Collector));

@@ -190,2 +190,16 @@ "use strict";

};
SignalTests.prototype.disconnect_all = function () {
var sig = new Signal_1.Signal();
var count1 = 0;
var count2 = 0;
sig.connect(function () { return count1++; });
sig.connect(function () { return count2++; });
sig.emit();
chai_1.assert.strictEqual(1, count1);
chai_1.assert.strictEqual(1, count2);
sig.disconnectAll();
sig.emit();
chai_1.assert.strictEqual(1, count1);
chai_1.assert.strictEqual(1, count2);
};
SignalTests.prototype.signal_connections = function () {

@@ -266,14 +280,35 @@ var dummy = new Dummy();

};
SignalTests.prototype.collector_array = function () {
var sig_array = new Signal_1.Signal();
sig_array.connect(TestCollectorArray.handler777);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler1);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler777);
var collector = new Signal_1.CollectorArray(sig_array);
SignalTests.prototype.disable_disconnected = function () {
var sig = new Signal_1.Signal();
var connection = sig.connect(function () { });
connection.disconnect();
chai_1.assert.doesNotThrow(function () { return connection.enabled = false; });
};
SignalTests.prototype.collector_last = function () {
var sig = new Signal_1.Signal();
sig.connect(function () { return 0; });
sig.connect(function () { return 1; });
sig.connect(function () { return 2; });
sig.connect(function () { return 3; });
sig.connect(function () { return 4; });
sig.connect(function () { return 5; });
var collector = new Signal_1.CollectorLast(sig);
collector.emit();
var result = collector.getResult();
chai_1.assert.sameOrderedMembers(result, [777, 42, 1, 42, 777]);
chai_1.assert.strictEqual(5, collector.getResult());
collector.reset();
chai_1.assert.isUndefined(collector.getResult());
};
SignalTests.prototype.collector_disabled = function () {
var sig = new Signal_1.Signal();
sig.connect(function () { return 23; });
var connection = sig.connect(function () { return 42; });
var collector = new Signal_1.CollectorLast(sig);
collector.emit();
chai_1.assert.strictEqual(42, collector.getResult());
collector.reset();
chai_1.assert.isUndefined(collector.getResult());
connection.enabled = false;
collector.emit();
chai_1.assert.strictEqual(23, collector.getResult());
};
SignalTests.prototype.collector_until_0 = function () {

@@ -292,2 +327,4 @@ var self = new TestCollector();

chai_1.assert.isTrue(self.check2);
collector.reset();
chai_1.assert.isFalse(collector.getResult());
};

@@ -307,3 +344,19 @@ SignalTests.prototype.collector_while_0 = function () {

chai_1.assert.isTrue(self.check2);
collector.reset();
chai_1.assert.isFalse(collector.getResult());
};
SignalTests.prototype.collector_array = function () {
var sig_array = new Signal_1.Signal();
sig_array.connect(TestCollectorArray.handler777);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler1);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler777);
var collector = new Signal_1.CollectorArray(sig_array);
collector.emit();
var result = collector.getResult();
chai_1.assert.sameOrderedMembers(result, [777, 42, 1, 42, 777]);
collector.reset();
chai_1.assert.isEmpty(collector.getResult());
};
__decorate([

@@ -329,2 +382,5 @@ mocha_typescript_1.test

mocha_typescript_1.test
], SignalTests.prototype, "disconnect_all", null);
__decorate([
mocha_typescript_1.test
], SignalTests.prototype, "signal_connections", null);

@@ -342,5 +398,11 @@ __decorate([

mocha_typescript_1.test
], SignalTests.prototype, "collector_array", null);
], SignalTests.prototype, "disable_disconnected", null);
__decorate([
mocha_typescript_1.test
], SignalTests.prototype, "collector_last", null);
__decorate([
mocha_typescript_1.test
], SignalTests.prototype, "collector_disabled", null);
__decorate([
mocha_typescript_1.test
], SignalTests.prototype, "collector_until_0", null);

@@ -350,2 +412,5 @@ __decorate([

], SignalTests.prototype, "collector_while_0", null);
__decorate([
mocha_typescript_1.test
], SignalTests.prototype, "collector_array", null);
SignalTests = __decorate([

@@ -352,0 +417,0 @@ mocha_typescript_1.suite

{
"name": "typed-signals",
"version": "1.0.0",
"version": "1.0.1",
"description": "A type checked signal library for TypeScript (and JavaScript)",

@@ -32,4 +32,21 @@ "keywords": [

"pretest": "tsc",
"test": "mocha --require source-map-support/register \"./dist/test/**/*.js\""
"test": "nyc mocha --require source-map-support/register \"./dist/test/**/*.js\"",
"coveralls": "cat ./coverage/lcov.info | coveralls"
},
"nyc": {
"extension": [
".ts",
".tsx"
],
"exclude": [
"coverage/**/*",
"test/**/*",
"dist/test/**/*",
"**/*.d.ts"
],
"reporter": [
"lcov"
],
"all": true
},
"devDependencies": {

@@ -41,4 +58,6 @@ "@types/chai": "^4.0.4",

"chai": "^4.1.2",
"coveralls": "^3.0.0",
"mocha": "^4.0.1",
"mocha-typescript": "^1.1.11",
"nyc": "^11.2.1",
"source-map-loader": "^0.2.2",

@@ -48,2 +67,2 @@ "source-map-support": "^0.5.0",

}
}
}
## Typed-Signals
[![Build Status](https://travis-ci.org/Lusito/typed-signals.svg?branch=master)](https://travis-ci.org/Lusito/typed-signals)
[![Build Status](https://travis-ci.org/Lusito/typed-signals.svg?branch=develop)](https://travis-ci.org/Lusito/typed-signals)
[![Code Coverage](https://coveralls.io/repos/github/Lusito/typed-signals/badge.svg?branch=develop)](https://coveralls.io/github/Lusito/typed-signals)
A type-checked signal library written in TypeScript, usable from plain JavaScript as well. This is a TypeScript port of this excellent C++11 version:
A type-checked [signal](https://en.wikipedia.org/wiki/Signals_and_slots) library written in TypeScript, usable from plain JavaScript as well. This is a TypeScript port of this excellent C++11 version:
[Performance of a C++11 Signal System](https://testbit.eu/cpp11-signal-system-performance/).
Of course, some changes have been made to make it work with TypeScript.
The original unit tests and additional ones are running automatically on [Travis-CI](https://travis-ci.org/)
The original unit tests and additional ones are running automatically on
### Why Typed-Signals?
- Arbitrary arguments lists
- Type checking
- Support for priorities
- Add and remove listeners anytime, even during callbacks
- Signals can have return values, which can be collected
- No dependencies
- Automated [unit tests](https://travis-ci.org/Lusito/typed-signals) with 100% [code coverage](https://coveralls.io/github/Lusito/typed-signals).
- Liberal license: [CC0 Public Domain](http://creativecommons.org/publicdomain/zero/1.0/)
### Installation via NPM

@@ -12,0 +24,0 @@

@@ -30,8 +30,4 @@ // CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0/

this.callback = null;
if (this.next)
this.next.prev = this.prev;
if (this.prev)
this.prev.next = this.next;
this.next.prev = this.prev;
this.prev.next = this.next;
}

@@ -166,6 +162,4 @@

public disconnectAll() {
if (this.head) {
while (this.head.next !== this.head) {
this.head.next.unlink();
}
while (this.head.next !== this.head) {
this.head.next.unlink();
}

@@ -212,3 +206,3 @@ }

*/
export class Collector<CB extends Function, RT> {
export abstract class Collector<CB extends Function, RT> {
/**

@@ -236,5 +230,3 @@ * Publish the bound signal event (call all handlers) to start the collection process.

*/
public handleResult(result: RT): boolean {
return true;
}
public abstract handleResult(result: RT): boolean;
}

@@ -259,2 +251,9 @@

}
/**
* Reset the result
*/
public reset(): void {
delete this.result;
}
}

@@ -279,2 +278,9 @@

}
/**
* Reset the result
*/
public reset(): void {
this.result = false;
}
}

@@ -299,2 +305,9 @@

}
/**
* Reset the result
*/
public reset(): void {
this.result = false;
}
}

@@ -319,2 +332,9 @@

}
/**
* Reset the result
*/
public reset(): void {
this.result.length = 0;
}
}

@@ -5,3 +5,3 @@ // CC0 Public Domain: http://creativecommons.org/publicdomain/zero/1.0/

import { assert } from "chai";
import { Signal, SignalConnections, CollectorArray, CollectorUntil0, CollectorWhile0 } from "../src/Signal";
import { Signal, SignalConnections, CollectorLast, CollectorUntil0, CollectorWhile0, CollectorArray } from "../src/Signal";

@@ -98,3 +98,3 @@ class Dummy {

}
@test disabled_connections() {

@@ -119,3 +119,3 @@ let dummy = new Dummy();

assert.strictEqual(listener2.count, 2);
con1.enabled = true;

@@ -209,2 +209,17 @@ assert.isTrue(con1.enabled);

@test disconnect_all() {
let sig = new Signal<() => void>();
let count1 = 0;
let count2 = 0;
sig.connect(() => count1++);
sig.connect(() => count2++);
sig.emit();
assert.strictEqual(1, count1);
assert.strictEqual(1, count2);
sig.disconnectAll();
sig.emit();
assert.strictEqual(1, count1);
assert.strictEqual(1, count2);
}
@test signal_connections() {

@@ -268,3 +283,3 @@ let dummy = new Dummy();

@test basic_signal_test() {
let result:string[] = [];
let result: string[] = [];
let sig1 = new Signal<(result: string[], f: number, i: number, s: string) => void>();

@@ -304,15 +319,38 @@ let id1 = sig1.connect(float_callback);

@test collector_array() {
let sig_array = new Signal<() => number>();
sig_array.connect(TestCollectorArray.handler777);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler1);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler777);
let collector = new CollectorArray<() => number, number>(sig_array);
@test disable_disconnected() {
let sig = new Signal<() => void>();
let connection = sig.connect(() => { });
connection.disconnect();
assert.doesNotThrow(() => connection.enabled = false);
}
@test collector_last() {
let sig = new Signal<() => number>();
sig.connect(() => 0);
sig.connect(() => 1);
sig.connect(() => 2);
sig.connect(() => 3);
sig.connect(() => 4);
sig.connect(() => 5);
let collector = new CollectorLast<() => number, number>(sig);
collector.emit();
let result = collector.getResult();
assert.sameOrderedMembers(result, [777, 42, 1, 42, 777]);
assert.strictEqual(5, collector.getResult());
collector.reset();
assert.isUndefined(collector.getResult());
}
@test collector_disabled() {
let sig = new Signal<() => number>();
sig.connect(() => 23);
let connection = sig.connect(() => 42);
let collector = new CollectorLast<() => number, number>(sig);
collector.emit();
assert.strictEqual(42, collector.getResult());
collector.reset();
assert.isUndefined(collector.getResult());
connection.enabled = false;
collector.emit();
assert.strictEqual(23, collector.getResult());
}
@test collector_until_0() {

@@ -331,2 +369,4 @@ let self = new TestCollector();

assert.isTrue(self.check2);
collector.reset();
assert.isFalse(collector.getResult());
}

@@ -347,3 +387,20 @@

assert.isTrue(self.check2);
collector.reset();
assert.isFalse(collector.getResult());
}
@test collector_array() {
let sig_array = new Signal<() => number>();
sig_array.connect(TestCollectorArray.handler777);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler1);
sig_array.connect(TestCollectorArray.handler42);
sig_array.connect(TestCollectorArray.handler777);
let collector = new CollectorArray<() => number, number>(sig_array);
collector.emit();
let result = collector.getResult();
assert.sameOrderedMembers(result, [777, 42, 1, 42, 777]);
collector.reset();
assert.isEmpty(collector.getResult());
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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