1.0.0 • Published 1 year ago

@ohae/events v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@ohae/events

This package contained event system (implements a SimpleEventEmitter and ...)

!!! IN DEVELOPING !!!

Installation

npm install @ohae/events --save

Usage

javascript commonjs modules

const { SimpleEventEmitter, EventListener } = require('@ohae/events');
const emitter = new SimpleEventEmitter();

emitter.on("event1", function (data){
	console.log(data); // {value1: 1, value2: "1111"}
});
emitter.emit("event1", {value1: 1, value2: "1111"});


emitter.once("event2", function (data){
	console.log(data); // {value1: "1111", value2: false}
});
emitter.emit("event2", {value1: "1111", value2: false});

javascript es modules

import { SimpleEventEmitter } from '@ohae/events';
const emitter = new SimpleEventEmitter();

emitter.on("event1", function (data){
	console.log(data); // {value1: 1, value2: "1111"}
});
emitter.emit("event1", {value1: 1, value2: "1111"});


emitter.once("event2", function (data){
	console.log(data); // {value1: "1111", value2: false}
});
emitter.emit("event2", {value1: "1111", value2: false});

typecript

import { SimpleEventEmitter } from '@ohae/events';
const emitter: SimpleEventEmitter = new SimpleEventEmitter();

interface Data1 {
	value1: number,
	value2: string,
};

declare type Data2 = {
	value1: string,
	value3: any,
};

emitter.on("event1", function (data: Data1){
	console.log(data); // {value1: 1, value2: "1111"}
});
emitter.emit("event1", {value1: 1, value2: "1111"} as Data1);


emitter.once("event2", function (data: Data2){
	console.log(data); // {value1: "1111", value2: false}
});
emitter.emit("event2", {value1: "1111", value2: false} as Data2);

License

MIT

1.0.0

1 year ago