diff --git a/.changeset/smart-eyes-switch.md b/.changeset/smart-eyes-switch.md new file mode 100644 index 0000000..fd940c6 --- /dev/null +++ b/.changeset/smart-eyes-switch.md @@ -0,0 +1,5 @@ +--- +'emitten': minor +--- + +Implement a workaround for calling super on an accessor. diff --git a/docs/examples.md b/docs/examples.md index 5095352..2734d58 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -104,6 +104,12 @@ class ExtendedEmitten extends EmittenProtected { // 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( eventName: TKey, listener: EmittenListener, diff --git a/src/Emitten.ts b/src/Emitten.ts index b9390dc..198f1d1 100644 --- a/src/Emitten.ts +++ b/src/Emitten.ts @@ -3,7 +3,7 @@ import type {EmittenListener} from './types'; export class Emitten extends EmittenProtected { public get activeEvents() { - return super.activeEvents; + return super.getActiveEvents(); } public off( diff --git a/src/EmittenProtected.ts b/src/EmittenProtected.ts index 2e1d8f5..cb88804 100644 --- a/src/EmittenProtected.ts +++ b/src/EmittenProtected.ts @@ -5,6 +5,12 @@ export class EmittenProtected { #singleLibrary: EmittenLibrary = {}; 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);