1.0.17 • Published 5 years ago

o-emitter v1.0.17

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

o-emitter

Event emitter library.

Install

npm

npm install o-emitter --save

Usage

var Emitter = require('o-emitter').Emitter;
let emitter = new Emitter('async');
emitter.hook(function (arg1,arg2){
    //
});

emitter.emit('hello world','from emitter');

İf you want to emit data synchronously. Can use

var Emitter = require('o-emitter').Emitter;
let emitter = new Emitter('sync');
emitter.hook(function (arg1,arg2){
    console.log('calling 1');
});

emitter.hook(function (arg1,arg2){
    console.log('calling 2');
})

emitter.emit('hello world','from emitter');
//output : calling 1
//output : calling 2

You can cut off emitting from hook callback function.

emitter.hook(function () {
 console.log('calling 1');
 return false;
});

emitter.hook(function () {
 console.log('calling 2');
});

//output : calling 1

set type as 'pipe' if you want to get changed emitted value.

let emitter = new Emitter('pipe');
emitter.hook(function () {
 return value * 2;
});

emitter.hook(function (value) {
  return value * 3;
});

let result = emitter.emit(1);
console.log(result);
//output 6

you can catch async result from hooks in mode pipe.

let emitter = new Emitter('pipe');
emitter.hook(function () {
 return value * 2;
});

emitter.hook(async function (value) {
  return value * 3;
});

emitter.emit(1).then((result)=>{
    console.log(result);
});
//output 6
1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago