Compare commits
2 Commits
1.1.0
...
cfdcdf1def
| Author | SHA1 | Date | |
|---|---|---|---|
| cfdcdf1def | |||
| f8cdfe131f |
@@ -7,9 +7,9 @@ export class Interactor {
|
|||||||
#latestReactions = {};
|
#latestReactions = {};
|
||||||
|
|
||||||
constructor(initialReaction = new Reaction()) {
|
constructor(initialReaction = new Reaction()) {
|
||||||
this.#actions.listen((action) =>
|
this.#actions.listen((action) => {
|
||||||
this[`handle${action.constructor.name}`](action)
|
this[`_handle${action.constructor.name}`](action);
|
||||||
);
|
});
|
||||||
this._react(initialReaction);
|
this._react(initialReaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +45,34 @@ export class Interactor {
|
|||||||
|
|
||||||
export class Action {}
|
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 {
|
export class Reaction {
|
||||||
equals(reaction) {
|
equals(reaction) {
|
||||||
return false;
|
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}`],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "interactor",
|
"name": "interactor",
|
||||||
"version": "1.1.0",
|
"version": "1.1.2",
|
||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user