![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
short-signal
Advanced tools
short-signal is a lightweight version of js-signals which is heavily inspired by Robert Penner’s AS3-Signals. Signal is an alternative to Events
/Promises
/Callbacks
. To know more about the differences, you can check out the Wiki page of js-signals.
Unlike other trimmed version js-signals, short-signal preserves some useful features like priorty and arguments injection which comes in handy during the development.
Dispatch the same signal within the signal callback is not recommended. If it happens the new signal execution will kick in and stop the unfinished execution.
Example of using the basic functions: add()
, dispatch()
and remove()
with short-signal
var onStarted = new ShortSignal();
function callback(param1, param2) {
console.log(param1 + ' ' + param2);
}
onStarted.add(callback); // add listener
onStarted.dispatch('foo', 'bar'); // dispatch signal passing custom parameters
onStarted.remove(callback); // remove a signle listener
If you the callback to be dispatched only once, you can use addOnce()
.
var onStarted = new ShortSignal();
function callback() {
console.log('hello');
}
onStarted.addOnce(callback);
onStarted.dispatch(); // log : hello
onStarted.dispatch(); // do nothing
The first argument of the add()
and addOnce()
is the priority, the higher it is, the earlier it will be dispatched. The default value is 0, and order by first comes first served principle.
var onStarted = new ShortSignal();
function callback1() {
console.log('1');
}
function callback2() {
console.log('1');
}
function callback3() {
console.log('3');
}
onStarted.add(callback1);
onStarted.add(callback2);
onStarted.add(callback3, null, 10);
onStarted.dispatch(); // log : 3, 1, 2
Like function binding, you can provide the context for the callback binding. Same context with the same function will be ignored.
var onStarted = new ShortSignal();
function callback() {
console.log(this.id);
}
var a = {id: 'a'};
var b = {id: 'b'};
onStarted.add(callback, a);
onStarted.add(callback, a);
onStarted.add(callback, b);
onStarted.dispatch(); // log : a, b
You can also add argument prefix with the add()
and addOnce()
like in Function.bind()
. One thing you need to keep in mind is that, for the duplicated callback checking, it only checks the funtion and the context, same function with the same context with new argument prefix will be rejected instead of overridden.
var onStarted = new ShortSignal();
function callback(param1, param2, param3, param4) {
console.log(param1 + param2 + param3 + param4);
}
onStarted.add(callback, null, 0, 'a', 'b');
onStarted.dispatch('c', 'd'); // log : abcd
You can stop propagation by returning false
in the callback function. By stopping propagation, in the dispatch()
call it will return the listener which triggered the stop propagation.
var onStarted = new ShortSignal();
onStarted.add(function(){
return false; // returns "false" to stop propagation
});
onStarted.add(function(){
console.log('wont be triggered'); // this function won't be trigger
});
onStarted.dispatch(); // log : {...} // will return the listener that stopped the propagation
Download short-signal here.
Check out the npm page here.
run npm run test
to run the test suite.
FAQs
lightweight signal with priority support.
The npm package short-signal receives a total of 1 weekly downloads. As such, short-signal popularity was classified as not popular.
We found that short-signal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.