https://github.com/vonage/js-nameless-events
https://github.com/vonage/js-nameless-events
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/vonage/js-nameless-events
- Owner: Vonage
- License: mit
- Created: 2022-09-12T09:41:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-12T12:59:26.000Z (almost 3 years ago)
- Last Synced: 2025-01-03T08:47:33.533Z (6 months ago)
- Language: TypeScript
- Size: 51.8 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# js-nameless-events
Pick badges here: https://poser.pugx.org/Library providing nameless events features.
## Table of content
- [Installation](#installation)
- [Usage](#Usage)
- [License](#license)
- [Links](#links)## Installation
### Installation
``` bash
# Install dependencies
npm install @vonage/js-nameless-events
```### Running tests
``` bash
# Running the tests
npm run test# Running the test coverage
npm run coverage
```# Usage
Event without data :
```ts
const onSomethingHappen = new EventEmitter();
onSomethingHappen.register(()=>console.log('Fire'));
onSomethingHappen.fire();
```Event with data:
```ts
const onSomethingHappen = new EventEmitter<(a:number, b:number)=>void>();
onSomethingHappen.register((a:number, b:number)=>console.log(a, b));
onSomethingHappen.fire(1, 2); // 1, 2
```Asynchronous event:
```ts
const onSomethingHappen = new EventEmitter<()=>Promise>();
onSomethingHappen.register(async ()=> await somethingAsynchronous());
onSomethingHappen.fireAsync(); // Promise
```Cancelling registration:
```ts
const onSomethingHappen = new EventEmitter();
const registration = onSomethingHappen.register(async ()=> console.log("will never being called"));
registration.cancel();
onSomethingHappen.fire(); // do nothing
```## License
This project is licensed under the terms of the [MIT license](https://opensource.org/licenses/MIT) and is available for free.
## Links
* [Documentation](https://github.com/Vonage/js-nameless-events/wiki)
* [Source code](https://github.com/Vonage/js-nameless-events)