namespace-emitter

WebJar for namespace-emitter

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

namespace-emitter
Last Version

Last Version

2.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

namespace-emitter
WebJar for namespace-emitter
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/sethvincent/namespace-emitter

Download namespace-emitter

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/namespace-emitter/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>namespace-emitter</artifactId>
    <version>2.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/namespace-emitter/
implementation 'org.webjars.npm:namespace-emitter:2.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/namespace-emitter/
implementation ("org.webjars.npm:namespace-emitter:2.0.1")
'org.webjars.npm:namespace-emitter:jar:2.0.1'
<dependency org="org.webjars.npm" name="namespace-emitter" rev="2.0.1">
  <artifact name="namespace-emitter" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='namespace-emitter', version='2.0.1')
)
libraryDependencies += "org.webjars.npm" % "namespace-emitter" % "2.0.1"
[org.webjars.npm/namespace-emitter "2.0.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

namespace-emitter

A small event emitter with namespaces.

Not meant as a replacement for node's events module, but as a small component for browser js.

Install

npm install --save namespace-emitter

Example

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

API

createNamespaceEmitter

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

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 namespace
  • data ...Any – data variables that will be passed as arguments to the event listener

Examples

emitter.emit('example')
emitter.emit('demo:test')
emitter.emit('data', { example: true}, 'a string', 1)

off

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 String
  • fn [Function] – the specific handler

Examples

emitter.off('example')
emitter.off('demo', function () {})

on

Create en event listener.

Parameters

  • event String
  • fn Function

Examples

emitter.on('example', function () {})
emitter.on('demo', function () {})

once

Create en event listener that fires once.

Parameters

  • event String
  • fn Function

Examples

emitter.once('example', function () {})
emitter.once('demo', function () {})

License

MIT

Versions

Version
2.0.1
1.0.0