added better error handling for missing action handlers #11

Merged
bryce merged 1 commits from 1.1.3 into main 2025-11-06 18:47:07 -07:00
2 changed files with 5 additions and 2 deletions

View File

@@ -8,7 +8,10 @@ export class Interactor {
constructor(initialReaction = new Reaction()) { constructor(initialReaction = new Reaction()) {
this.#actions.listen((action) => { 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); this._react(initialReaction);
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "interactor", "name": "interactor",
"version": "1.1.2", "version": "1.1.3",
"description": "Cross-element communications and state management utility.", "description": "Cross-element communications and state management utility.",
"author": "Bryce Thorup", "author": "Bryce Thorup",
"type": "module", "type": "module",