https://github.com/neki-dev/make-event
🧩 Easy pattern to create events with subscriptions
https://github.com/neki-dev/make-event
emitter event events listener subscription
Last synced: 2 months ago
JSON representation
🧩 Easy pattern to create events with subscriptions
- Host: GitHub
- URL: https://github.com/neki-dev/make-event
- Owner: neki-dev
- License: mit
- Created: 2024-11-23T23:27:48.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-24T12:23:45.000Z (8 months ago)
- Last Synced: 2025-04-27T02:34:16.631Z (2 months ago)
- Topics: emitter, event, events, listener, subscription
- Language: TypeScript
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 🧩 Make event
[](https://npmjs.com/package/make-event)
[](https://github.com/neki-dev/make-event/blob/master/dist/index.js)
[](https://github.com/neki-dev/make-event/actions/workflows/test.yml)
[](https://github.com/neki-dev/make-event/actions/workflows/build.yml)Easy pattern to create events with subscriptions
.
## Install
```sh
npm i make-event
```.
## Usage
### Subscribe to event
```ts
const onUpdate = Events.make();onUpdate((value) => {
console.log(value);
});
```### Unsubcsribe from event
```ts
const onUpdate = Events.make();// method 1
const unsubscribe = onUpdate(() => {
});unsubscribe();
// method 2
const handler = () => {
console.log(true);
}onUpdate(handler);
onUpdate.unsubscribe(handler);
```### Invoke event
```ts
const onUpdate = Events.make();onUpdate.invoke(10);
```### Remove all handlers
```ts
const onUpdate = Events.make();onUpdate.clear();
```.
## Example
```ts
import { Events } from 'make-event';class Player {
public readonly onJump = Events.make();public jump(height: number) {
this.onJump.invoke(height);
}
}// ...
const player = new Player();
player.onJump((height) => {
console.log('onJump1', height);
});const unsubscribe = player.onJump((height) => {
console.log('onJump2', height);
});unsubscribe();
player.jump(10);
```