Skip to content

Commit

Permalink
✨ [Emitten] New EmittenCommon for easier extension (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi authored Jan 30, 2023
1 parent 591f16d commit 5664e08
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 180 deletions.
16 changes: 9 additions & 7 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,25 @@ type ExtendedEventMap = {
};

class ExtendedEmitten extends EmittenProtected<ExtendedEventMap> {
// This example extends `EmittenProtected`, which protects all members.
// If required, you can selectively expose any `protected` members.
// Otherwise, if you want all members to be `public`, you can
// extend the `Emitten` class instead.
// If you only want `off/on/once` and `activeEvents`, you can
// extend from `EmittenCommon`. Otherwise, if you want ALL
// members to be `public`, you can extend from `Emitten`.

public on<K extends keyof ExtendedEventMap>(
public off<K extends keyof ExtendedEventMap>(
eventName: K,
listener: ExtendedEventMap[K],
) {
const dispose = super.on(eventName, listener);
return dispose;
super.off(eventName, listener);
}

public off<K extends keyof ExtendedEventMap>(
public on<K extends keyof ExtendedEventMap>(
eventName: K,
listener: ExtendedEventMap[K],
) {
super.off(eventName, listener);
const dispose = super.on(eventName, listener);
return dispose;
}

public emit<K extends keyof ExtendedEventMap>(
Expand Down
Loading

0 comments on commit 5664e08

Please sign in to comment.