From 6f52c56857a68a26b86729807307eeee6f0923b9 Mon Sep 17 00:00:00 2001 From: Bryce Thorup Date: Thu, 6 Nov 2025 18:44:04 -0700 Subject: [PATCH] added better error handling for missing action handlers --- interactor.js | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/interactor.js b/interactor.js index 5c9997f..035094c 100644 --- a/interactor.js +++ b/interactor.js @@ -8,7 +8,10 @@ export class Interactor { constructor(initialReaction = new Reaction()) { this.#actions.listen((action) => { - this[`_handle${action.constructor.name}`](action); + let funcRef = `_handle${action.constructor.name}`; + if (!this[funcRef]) + throw `${this.constructor.name} does not have a handler defined for the action "${action.constructor.name}". Create one by adding a function definition named "${funcRef}" in the ${this.constructor.name} class.`; + this[funcRef](action); }); this._react(initialReaction); } diff --git a/package.json b/package.json index f51c54d..1c44efc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "interactor", - "version": "1.1.2", + "version": "1.1.3", "description": "Cross-element communications and state management utility.", "author": "Bryce Thorup", "type": "module", -- 2.49.1