Compare commits
6 Commits
cfdcdf1def
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ad774185c2 | |||
| c513a54717 | |||
| 7e53db5785 | |||
| f463dec7f1 | |||
| 7f55ae0d4e | |||
| 6f52c56857 |
@@ -1,4 +1,4 @@
|
|||||||
import { Stream } from "stream";
|
import { Stream } from "@brycethorup/stream";
|
||||||
|
|
||||||
export class Interactor {
|
export class Interactor {
|
||||||
#actions = new Stream();
|
#actions = new Stream();
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "interactor",
|
"name": "@brycethorup/interactor",
|
||||||
"version": "1.1.2",
|
"version": "1.1.5",
|
||||||
"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": "interactor.js",
|
"main": "interactor.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"stream": "^1.0.1"
|
"@brycethorup/stream": "^1.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user