From a98bdbcbe2daee05ae3fbf9b587ba7ce453b57c5 Mon Sep 17 00:00:00 2001 From: Curtis Dulmage Date: Fri, 27 Jan 2023 17:17:37 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20[Fix]=20Avoid=20calling=20`super?= =?UTF-8?q?`=20on=20an=20accessor=20(#11)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/smart-eyes-switch.md | 5 +++++ docs/examples.md | 6 ++++++ src/Emitten.ts | 2 +- src/EmittenProtected.ts | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/smart-eyes-switch.md 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);