lots of stuff

This commit is contained in:
Maze Winther
2026-01-23 15:40:01 +01:00
parent b1701e1b0e
commit c6deceaa89
292 changed files with 28825 additions and 26457 deletions
+33 -33
View File
@@ -1,53 +1,53 @@
import type {
TAction,
TActionFunc,
TActionWithArgs,
TActionWithOptionalArgs,
TActionArgsMap,
TArgOfAction,
TInvocationTrigger,
TBoundActionList,
TAction,
TActionFunc,
TActionWithArgs,
TActionWithOptionalArgs,
TActionArgsMap,
TArgOfAction,
TInvocationTrigger,
TBoundActionList,
} from "./types";
const boundActions: TBoundActionList = {};
export function bindAction<A extends TAction>(
action: A,
handler: TActionFunc<A>,
action: A,
handler: TActionFunc<A>,
) {
if (boundActions[action]) {
boundActions[action]?.push(handler);
} else {
boundActions[action] = [handler] as any;
}
if (boundActions[action]) {
boundActions[action]?.push(handler);
} else {
boundActions[action] = [handler] as any;
}
}
export function unbindAction<A extends TAction>(
action: A,
handler: TActionFunc<A>,
action: A,
handler: TActionFunc<A>,
) {
boundActions[action] = boundActions[action]?.filter(
(x) => x !== handler,
) as any;
boundActions[action] = boundActions[action]?.filter(
(x) => x !== handler,
) as any;
if (boundActions[action]?.length === 0) {
delete boundActions[action];
}
if (boundActions[action]?.length === 0) {
delete boundActions[action];
}
}
type InvokeActionFunc = {
(
action: TActionWithOptionalArgs,
args?: undefined,
trigger?: TInvocationTrigger,
): void;
<A extends TActionWithArgs>(action: A, args: TActionArgsMap[A]): void;
(
action: TActionWithOptionalArgs,
args?: undefined,
trigger?: TInvocationTrigger,
): void;
<A extends TActionWithArgs>(action: A, args: TActionArgsMap[A]): void;
};
export const invokeAction: InvokeActionFunc = <A extends TAction>(
action: A,
args?: TArgOfAction<A>,
trigger?: TInvocationTrigger,
action: A,
args?: TArgOfAction<A>,
trigger?: TInvocationTrigger,
) => {
boundActions[action]?.forEach((handler) => (handler as any)(args, trigger));
boundActions[action]?.forEach((handler) => (handler as any)(args, trigger));
};