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: 9 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 (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-14T11:35:47.000Z (about 1 year ago)
- Last Synced: 2025-09-19T00:05:41.552Z (9 months ago)
- Topics: emitter, event, events, listener, subscription
- Language: TypeScript
- Homepage:
- Size: 61.5 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);
```