
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.
Tiny JavaScript library to handle event callback registration.
Highlights:
Install the library:
npm install abonnement --save
Use it in any JavaScript object:
// Create a new context
const events = abonnement();
// Get an registering function
const onNewData = events.getRegisterHandler('newData');
// Subscribe to "newData" events
onNewData(data => console.log(data));
// Trigger a newData event
events.trigger('newData');
The main purpose of abonnement is to simplify modular architecture in an ES5 context.
The event handler pattern allow us to connect modules without having explicit dependencies.
// First, I create one module that will handle some data
function createBack() {
const events = abonnement();
setTimeout(() => events.trigger('end'), 3000);
return {
onEnd: events.getRegisterHandler('end')
};
}
// Then, I create another module that will handle the output
function createFront() {
function display(message) {
console.log(message);
}
return {
display
};
}
// Finally, I create the App that will links the modules together
const back = createBack();
const front = createFront();
back.onEnd(function() {
front.display("Time out!");
});
const events = abonnement();
// Trigger an event
events.trigger('end');
// Trigger an event with data
events.trigger('newData', { id: 'john' });
const events = abonnement();
// Subscribe to an event
const onEnd = events.getRegisterHandler('end');
onEnd(() => console.log('Time out!'));
// Treat event data
const onNewData = events.getRegisterHandler('newData');
onNewData(data => console.log(`New user connected: ${data.id}`));
// Filtering events by the data
onNewData({ id: 'john' }, data => console.log('John is connected'));
// Filtering events by id
onNewData('john', data => console.log('John is connected'));
// Declare a custom id field
const onNewData = events.getRegisterHandler('newData', 'name');
onNewData('John', data => console.log('John is connected'));
events.trigger('newData', { id: 76, name: 'John' });
MIT. Copyright (c) Thomas Zilliox.
FAQs
A JavaScript mixin to handle callback registration.
The npm package abonnement receives a total of 2 weekly downloads. As such, abonnement popularity was classified as not popular.
We found that abonnement 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.