5 Commits

Author SHA1 Message Date
95f85aedaa Merge pull request 'version bump' (#9) from 1.1.1 into main
All checks were successful
Push to main / publish (push) Successful in 14s
Reviewed-on: #9
2025-11-06 15:54:18 -07:00
5c7cf36cf3 version bump
All checks were successful
Pull request change / publish (pull_request) Successful in 10s
2025-11-06 15:53:51 -07:00
2a84086828 Merge pull request 'force handler functions' (#8) from 1.1.0 into main
Some checks failed
Push to main / publish (push) Failing after 11s
Reviewed-on: #8
2025-11-06 15:51:52 -07:00
1dcdc17436 force handler functions
Some checks failed
Pull request change / publish (pull_request) Failing after 10s
2025-11-06 15:51:16 -07:00
466e95cb14 Merge pull request '1.0.6' (#7) from 1.0.6 into main
All checks were successful
Push to main / publish (push) Successful in 13s
Reviewed-on: #7
2025-11-06 15:00:58 -07:00
2 changed files with 20 additions and 20 deletions

View File

@@ -1,44 +1,44 @@
import { Stream } from 'stream';
import { Stream } from "stream";
export class Interactor {
_actions = new Stream();
_reactions = new Stream();
_latestReaction;
#actions = new Stream();
#reactions = new Stream();
#latestReaction;
#latestReactions = {};
constructor(initialReaction = new Reaction()) {
this._latestReactions = {};
this._actions.listen((action) => this._interaction(action));
this.#actions.listen((action) =>
this[`handle${action.constructor.name}`](action)
);
this._react(initialReaction);
}
act(action) {
if (!(action instanceof Action)) throw 'invalid action';
this._actions.add(action);
if (!(action instanceof Action)) throw "invalid action";
this.#actions.add(action);
}
observe(reactionHandler, provideLatestReaction = true) {
if (provideLatestReaction) reactionHandler(this._latestReaction);
if (provideLatestReaction) reactionHandler(this.#latestReaction);
let listener = (reaction) => {
if (!(reaction instanceof Reaction)) throw 'invalid reaction';
if (!(reaction instanceof Reaction)) throw "invalid reaction";
reactionHandler(reaction);
};
this._reactions.listen(listener);
this.#reactions.listen(listener);
return listener;
}
ignore(listener) {
this._reactions.ignore(listener);
this.#reactions.ignore(listener);
}
_interaction(action) {}
_react(reaction) {
if (!(reaction instanceof Reaction)) throw 'invalid reaction';
let latest = this._latestReactions[reaction.constructor.name];
if (!(reaction instanceof Reaction)) throw "invalid reaction";
let latest = this.#latestReactions[reaction.constructor.name];
if (!reaction.equals(latest)) {
this._latestReaction = reaction;
this._latestReactions[reaction.constructor.name] = reaction;
this._reactions.add(reaction);
this.#latestReaction = reaction;
this.#latestReactions[reaction.constructor.name] = reaction;
this.#reactions.add(reaction);
}
}
}

View File

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