events-helper
v0.1.0
Published
## Installation
Downloads
4
Readme
Events Helper
Installation
From npmjs.com (recommended) - choose one of the options:
npm install events-helper
yarn add events-helper
From Adrosar/priv-fields - downloads the entire contents of the repository:
npm install bitbucket:Adrosar/events-helper
How to use
Example 1:
import { EventEmitter } from "events-helper";
const target = new EventEmitter();
target.addEventListener('myEventName', (event: Event) => {
console.log("--->", event);
});
target.emitEvent('myEventName');
Example 2:
import { createEvent, EventWithData, EventEmitter } from "events-helper";
const target = new EventEmitter();
interface MyData {
boo: string;
foo: number;
}
target.addEventListener('myEventName', (event: EventWithData<MyData>) => {
const data: MyData | undefined = event.data;
if (data) {
console.log("--->", data.boo);
console.log("--->", data.foo);
}
});
target.dispatchEvent(createEvent('myEventName', { boo: 'Boo123', foo: 456 }));
Development
Running the tests:
For browser:
- Run in terminal
npm run rollup:test && npm run browserify:test
- Run server (in terminal)
npm run server
- Open first link test.browserify.html
- Open second link test.rollup.html
Versioning
I use the versioning system SemVer (2.0.0)
Author
- Adrian Gargula
License
This project is licensed under the ISC License - see the wiki/ISC_license
Other
This project is based on Adrosar/ts-startek-kit (version 2.0.0)