Skip to content

Commit

Permalink
1.4.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaotian committed Apr 21, 2024
1 parent cb8d948 commit 98679d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG


### 1.4.0-beta.2

- Refactor: remove `eventemitter3` deps. Thanks @arkatsy ❤️


### 1.4.0-beta.1

- Fix: `persistStore` wronge when cahce data is null
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-one",
"version": "1.4.0-beta.1",
"version": "1.4.0-beta.2",
"license": "MIT",
"packageManager": "pnpm@7.28.0",
"repository": {
Expand Down
10 changes: 5 additions & 5 deletions src/bus.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
type EventHandler = (...args: any[]) => void;

export class EventBus {
private events = new Map<string, EventHandler[]>();
private E = new Map<string, EventHandler[]>();

on(event: string, handler: EventHandler): void {
this.events.set(event, [...(this.events.get(event) || []), handler]);
this.E.set(event, [...(this.E.get(event) || []), handler]);
}

off(event: string, handler?: EventHandler): void {
this.events.set(
this.E.set(
event,
handler ? this.events.get(event)?.filter((h) => h !== handler) || [] : []
handler ? this.E.get(event)?.filter((h) => h !== handler) || [] : []
);
}

emit(event: string, ...args: any[]): void {
this.events.get(event)?.forEach((cb) => cb(...args));
this.E.get(event)?.forEach((cb) => cb(...args));
}
}

0 comments on commit 98679d5

Please sign in to comment.