Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mablay/events
simplified dependency free ES6 version of NodeJS events
https://github.com/mablay/events
Last synced: 8 days ago
JSON representation
simplified dependency free ES6 version of NodeJS events
- Host: GitHub
- URL: https://github.com/mablay/events
- Owner: mablay
- Created: 2021-12-19T19:36:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-20T09:35:09.000Z (almost 3 years ago)
- Last Synced: 2024-10-30T00:37:30.487Z (18 days ago)
- Language: JavaScript
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Events
Simplified dependency free [EventEmitter](https://nodejs.org/api/events.html) as ES6 module with ~60 well readable LOC and ~0.7kb minified footprint for the browser.
## Usage
```js
import { EventEmitter } from '@occami/events'const observable = new EventEmitter()
observable.on('message', console.log)
observable.emit('message', 'foo', 'bar')
// => foo bar
```## API - supported methods
```ts
declare type Listener = (...args: any[]) => voidaddListener(eventName: string, listener: Listener): EventEmitter
on(eventName: string, listener: Listener): EventEmitter
once(eventName: string, listener: Listener): EventEmitter
emit(eventName: string, ...args: any[]): boolean
removeListener(eventName: string, listener: Listener): EventEmitter
off(eventName: string, listener: Listener): EventEmitter
removeAllListeners(eventName: string): EventEmitter
eventNames(): string[]
listenerCount(eventName: string): number
```
Behaviour as specified in NodeJS [EventEmitter](https://nodejs.org/api/events.html)See [events](https://www.npmjs.com/package/events) if you're missing out functionality from the original spec.
---
## What is Occami?
A collection of modules with these characteristics:
* as simple as possible
* few dependencies (mostly none)
* easy to read & review
* small footprint
* require an ES6 compliant runtime
* not minified, assuming you're bundling anyways
* type definitions included