Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
namespace-emitter
Advanced tools
A small event emitter with namespaces.
Not meant as a replacement for node's events module, but as a small component for browser js.
npm install --save namespace-emitter
var emitter = require('namespace-emitter')()
emitter.on('*', function () {
console.log('all events emitted', this.event)
})
emitter.on('example', function () {
console.log('example event emitted')
})
emitter.emit('example')
// -> example event emitted
// -> all events emitted example
emitter.on('demo', function () {
console.log('multiple events with `demo` namespace emitted', this.event)
})
emitter.emit('demo:cool')
// -> all events emitted demo:cool
// -> multiple events with `demo` namespace emitted demo:cool
emitter.emit('demo:awesome')
// -> all events emitted demo:awesome
// -> multiple events with `demo` namespace emitted demo:awesome
emitter.emit('demo:great')
// -> all events emitted demo:great
// -> multiple events with `demo` namespace emitted demo:great
Create an event emitter with namespaces
Examples
var emitter = require('./index')()
emitter.on('*', function () {
console.log('all events emitted', this.event)
})
emitter.on('example', function () {
console.log('example event emitted')
})
Emit an event. Optionally namespace the event. Handlers are fired in the order in which they were added with exact matches taking precedence. Separate the namespace and event with a :
Parameters
event
String – the name of the event, with optional namespacedata
...Any – data variables that will be passed as arguments to the event listenerExamples
emitter.emit('example')
emitter.emit('demo:test')
emitter.emit('data', { example: true}, 'a string', 1)
Stop listening to an event. Stop all listeners on an event by only passing the event name. Stop a single listener by passing that event handler as a callback.
You must be explicit about what will be unsubscribed: emitter.off('demo')
will unsubscribe an emitter.on('demo')
listener,
emitter.off('demo:example')
will unsubscribe an emitter.on('demo:example')
listener
Parameters
event
Stringfn
[Function] – the specific handlerExamples
emitter.off('example')
emitter.off('demo', function () {})
Create en event listener.
Parameters
event
Stringfn
FunctionExamples
emitter.on('example', function () {})
emitter.on('demo', function () {})
Create en event listener that fires once.
Parameters
event
Stringfn
FunctionExamples
emitter.once('example', function () {})
emitter.once('demo', function () {})
FAQs
tiny event emitter with namespaces
The npm package namespace-emitter receives a total of 193,485 weekly downloads. As such, namespace-emitter popularity was classified as popular.
We found that namespace-emitter 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.