From f8cdfe131f3f7aef34482e2b972498e2ec662d99 Mon Sep 17 00:00:00 2001 From: Bryce Thorup Date: Thu, 6 Nov 2025 18:33:33 -0700 Subject: [PATCH] 1.1.2 --- interactor.js | 32 +++++++++++++++++++++++++++++--- package.json | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/interactor.js b/interactor.js index e11afeb..5c9997f 100644 --- a/interactor.js +++ b/interactor.js @@ -7,9 +7,9 @@ export class Interactor { #latestReactions = {}; constructor(initialReaction = new Reaction()) { - this.#actions.listen((action) => - this[`handle${action.constructor.name}`](action) - ); + this.#actions.listen((action) => { + this[`_handle${action.constructor.name}`](action); + }); this._react(initialReaction); } @@ -45,8 +45,34 @@ export class Interactor { export class Action {} +export class ActionBundle { + add(action) { + if (!(action.prototype instanceof Action)) { + throw "Only classes extended by `Action` can be added to a `ActionBundle`"; + } + let actionName = action.name; + this[`#${actionName}`] = action; + Object.defineProperty(this, actionName, { + get: () => this[`#${actionName}`], + }); + } +} + export class Reaction { equals(reaction) { return false; } } + +export class ReactionBundle { + add(reaction) { + if (!(reaction.prototype instanceof Reaction)) { + throw "Only classes extended by `Reaction` can be added to a `ReactionBundle`"; + } + let reactionName = reaction.name; + this[`#${reactionName}`] = reaction; + Object.defineProperty(this, reactionName, { + get: () => this[`#${reactionName}`], + }); + } +} diff --git a/package.json b/package.json index 7744cd8..f51c54d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "interactor", - "version": "1.1.0", + "version": "1.1.2", "description": "Cross-element communications and state management utility.", "author": "Bryce Thorup", "type": "module",