0.0.105 • Published 3 years ago

@anic/events v0.0.105

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@anic/events

Events for JavaScript

Install

$ yarn add @anic/events

Usage

import createEmitter, { EventEmitter } from '@anic/events';

// create
const emitter = createEmitter();

// or extends
class MyEmitter extends EventEmitter {
    // todo something;
}

// create listener
let listener = (...args) => {
    // todo something with args;
    // or `throw error` stop follow listeners
}

// add or remove listener
emitter.on('data', listener);
emitter.once('data', listener);
emitter.next('data', listener);
emitter.off('data', listener);

// emit data
emitter.emit('data', 1, 2, 3);

Class: EventEmitter

on(name, listener): this

add listener, return this;

once(name, listener): this

add once listener, return this;

next(name, listener): Promise

add once listener, return a promise as the listener resolved;

off(name, listener)

remove listener, return this;

emit(name, ...args)

emit listener, return false as task stoped by throw error or true;

Event: $emit

Emitted when emit some listener by emit function

Event: $error

Emitted when some listener throw error;

0.0.105

3 years ago

0.0.104

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago

0.0.1

3 years ago