8 Commits

Author SHA1 Message Date
2102e9c8cf Merge pull request '1.0.4' (#5) from 1.0.4 into main
All checks were successful
Push to main / publish (push) Successful in 12s
Reviewed-on: #5
2025-11-06 14:19:07 -07:00
020299f82a added stream dep
All checks were successful
Pull request change / publish (pull_request) Successful in 13s
2025-11-06 14:18:49 -07:00
bac3b409d2 add code ya know 2025-11-06 14:09:13 -07:00
442f6055f6 Merge pull request 'runner worx??A?!?!?' (#4) from 1.0.3 into main
All checks were successful
Push to main / publish (push) Successful in 11s
Reviewed-on: #4
2025-11-06 13:53:40 -07:00
bd96c56445 runner worx??A?!?!?
All checks were successful
Pull request change / publish (pull_request) Successful in 10s
2025-11-06 13:53:22 -07:00
9978667571 Merge pull request 'b' (#3) from b into main
Some checks failed
Push to main / publish (push) Failing after 11s
Reviewed-on: #3
2025-11-06 13:51:20 -07:00
66173ac4f7 b
All checks were successful
Pull request change / publish (pull_request) Successful in 10s
2025-11-06 13:51:00 -07:00
85fbdce1d5 Merge pull request 'a' (#2) from a into main
Some checks failed
Push to main / publish (push) Failing after 12s
Reviewed-on: #2
2025-11-06 13:43:30 -07:00
5 changed files with 79 additions and 4 deletions

View File

@@ -17,4 +17,4 @@ jobs:
uses: https://git.thorup.us/actions/npm_publish@v1 uses: https://git.thorup.us/actions/npm_publish@v1
with: with:
npm_repo_key: ${{ secrets.NPM_REPO_KEY }} npm_repo_key: ${{ secrets.NPM_REPO_KEY }}
npm_repo_domain: "npm.thorup.us" npm_repo_domain: ${{ vars.NPM_REPO_DOMAIN }}

View File

@@ -1,2 +1,2 @@
import { Interactor, Action, Reaction } from "./src/interactor.js"; import { Interactor, Action, Reaction } from "./interactor.js";
export { Interactor, Action, Reaction }; export { Interactor, Action, Reaction };

52
interactor.js Normal file
View File

@@ -0,0 +1,52 @@
import { Stream } from './stream.js';
export class Interactor {
_actions = new Stream();
_reactions = new Stream();
_latestReaction;
constructor(initialReaction = new Reaction()) {
this._latestReactions = {};
this._actions.listen((action) => this._interaction(action));
this._react(initialReaction);
}
act(action) {
if (!(action instanceof Action)) throw 'invalid action';
this._actions.add(action);
}
observe(reactionHandler, provideLatestReaction = true) {
if (provideLatestReaction) reactionHandler(this._latestReaction);
let listener = (reaction) => {
if (!(reaction instanceof Reaction)) throw 'invalid reaction';
reactionHandler(reaction);
};
this._reactions.listen(listener);
return listener;
}
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.equals(latest)) {
this._latestReaction = reaction;
this._latestReactions[reaction.constructor.name] = reaction;
this._reactions.add(reaction);
}
}
}
export class Action {}
export class Reaction {
equals(reaction) {
return false;
}
}

20
package-lock.json generated Normal file
View File

@@ -0,0 +1,20 @@
{
"name": "interactor",
"version": "1.0.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "interactor",
"version": "1.0.4",
"dependencies": {
"stream": "^1.0.0"
}
},
"node_modules/stream": {
"version": "1.0.0",
"resolved": "https://git.thorup.us/api/packages/bryce/npm/stream/-/1.0.0/stream-1.0.0.tgz",
"integrity": "sha512-JGDjmgbnZcPCiQUxsboU7UufAryyivajDR3sCD790N/xfGpzlfl7OpPXf7EodDc43ojE+8dU8c3MOGbsH/Er4g=="
}
}
}

View File

@@ -1,8 +1,11 @@
{ {
"name": "interactor", "name": "interactor",
"version": "1.0.1", "version": "1.0.4",
"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",
"main": "index.js" "main": "index.js",
"dependencies": {
"stream": "^1.0.0"
}
} }