Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanve/energy
Universal JavaScript event emitter
https://github.com/ryanve/energy
cross-platform event-emitter event-listener eventemitter javascript
Last synced: about 1 month ago
JSON representation
Universal JavaScript event emitter
- Host: GitHub
- URL: https://github.com/ryanve/energy
- Owner: ryanve
- License: unlicense
- Created: 2013-11-14T03:22:43.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-04-15T15:34:42.000Z (over 1 year ago)
- Last Synced: 2024-09-30T02:08:09.538Z (about 1 month ago)
- Topics: cross-platform, event-emitter, event-listener, eventemitter, javascript
- Language: JavaScript
- Homepage: https://npm.im/energy/
- Size: 70.3 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# energy
#### simple [cross-platform](#platforms) event emitter based on [`EventEmitter`](http://nodejs.org/api/events.html)## API
#### Create an emitter instance
```js
const energy = require("energy")
const emitter = energy()
```Or use `new` if you prefer. Either way works :)
```js
const energy = require("energy")
const emitter = new energy
```#### Methods
- [emitter.on(event, listener)](#emitter-on)
- [emitter.off(event?, listener?, quota?)](#emitter-off)
- [emitter.emit(event, ...args)](#emitter-emit)
- [emitter.once(event, listener)](#emitter-once)
- [emitter.clone()](#emitter-clone)
- [emitter.listeners(event)](#emitter-listeners)
- [emitter.init()](#emitter-init)
- [emitter.to(target)](#emitter-to)
- [energy.to(target)](#energy-to)#### Parameters
- emitter refers to an `energy()` object
- event refers to an event name
- listener refers to a function that listens to an event
#### `emitter.on(event, listener)`
- Add listener for event
- @return emitter
#### `emitter.off(event?, listener?, quota?)`
- Remove listener(s)
- `.off()` removes all listeners for all events
- `.off(event)` removes all event listeners
- `.off(event, listener)` removes all occurrences of event listener
- `.off(event, listener, quota)` remove quota occurrences of event listener
- @return emitter
#### `emitter.emit(event, ...args)`
- Fire event listeners (in sequence) with the supplied arguments
- Listeners run in the context of emitter
- @return number of invoked listeners
#### `emitter.once(event, listener)`
- Add a one-time event listener
- @return emitter
#### `emitter.clone()`
- Clone an emitter at its current state
- @return a new emitter
#### `emitter.listeners(event)`
- Access the listeners array for the specified event
- @return array (reference)
#### `emitter.init()`
- Reinitialize an emitter
- @return emitter
#### `emitter.to(target)`
- Make target [emitter-like](../../issues/3) based on `emitter` as the source.
- @return emitter
#### `energy.to(target)`
- Make target emitter-like based on a `energy()` object as the source
- @return target with emitter methods and propertiesWorks in [node](http://nodejs.org) **and** in any browser. Tested in node, Chrome, FF, Opera, IE8