32 lines
775 B
TypeScript
32 lines
775 B
TypeScript
|
|
import {Context} from "./context";
|
|||
|
|
import {Command} from "../utils/command";
|
|||
|
|
import {effect} from "@preact/signals-core";
|
|||
|
|
|
|||
|
|
export type RuleContext<T> = Context & {
|
|||
|
|
actions: Command[];
|
|||
|
|
handledActions: number;
|
|||
|
|
invocations: RuleContext<unknown>[];
|
|||
|
|
resolution?: T;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function invokeRuleContext<T>(pushContext: (context: Context) => void, type: string, rule: Generator<string, T, Command>){
|
|||
|
|
const ctx: RuleContext<T> = {
|
|||
|
|
type,
|
|||
|
|
actions: [],
|
|||
|
|
handledActions: 0,
|
|||
|
|
invocations: [],
|
|||
|
|
resolution: undefined,
|
|||
|
|
}
|
|||
|
|
const dispose = effect(() => {
|
|||
|
|
if(ctx.resolution) {
|
|||
|
|
dispose();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
pushContext(rule);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function* rule(){
|
|||
|
|
const play: Command = yield 'play';
|
|||
|
|
}
|