Skip to content

Commit

Permalink
🐛 [Fix] Avoid calling super on an accessor (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi authored Jan 27, 2023
1 parent ecc54de commit a98bdbc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/smart-eyes-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'emitten': minor
---

Implement a workaround for calling super on an accessor.
6 changes: 6 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class ExtendedEmitten extends EmittenProtected<ExtendedEventMap> {
// Otherwise, if you want all members to be `public`, you can
// extend the `Emitten` class instead.

public get activeEvents() {
// Must use the `method`, since `super` cannot
// be called on an accessor.
return super.getActiveEvents();
}

public on<TKey extends keyof ExtendedEventMap>(
eventName: TKey,
listener: EmittenListener<ExtendedEventMap[TKey]>,
Expand Down
2 changes: 1 addition & 1 deletion src/Emitten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {EmittenListener} from './types';

export class Emitten<TEventMap> extends EmittenProtected<TEventMap> {
public get activeEvents() {
return super.activeEvents;
return super.getActiveEvents();
}

public off<TKey extends keyof TEventMap>(
Expand Down
6 changes: 6 additions & 0 deletions src/EmittenProtected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export class EmittenProtected<TEventMap> {
#singleLibrary: EmittenLibrary<TEventMap> = {};

protected get activeEvents() {
// This redundant getter + method are required
// because you cannot call `super` on an accessor.
return this.getActiveEvents();
}

protected getActiveEvents() {
const multiKeys = Object.keys(this.#multiLibrary);
const singleKeys = Object.keys(this.#singleLibrary);

Expand Down

0 comments on commit a98bdbc

Please sign in to comment.