import { Actionable } from "../action/actionable"; import { SerializableData, StringKeyOf } from "../../../util/data"; import { Chained, Proxied } from "../action/chain"; import { ServiceAction } from "../action/serviceAction"; import { ScriptCtx } from "../elements/script"; type ServiceContentType = { [K in string]: any[]; }; export type ServiceHandlerCtx = ScriptCtx & { onAbort: (handler: () => void) => void; }; export type ServiceHandler = (ctx: ServiceHandlerCtx, ...args: Args) => void | Promise; export declare class ServiceSkeleton | null = never> extends Actionable { /** * Register an action handler. * @param key - The action key to handle. * @param handler - Callback invoked when the action fires. * @example * ```ts * this.on("add", (ctx, name) => { * console.log("Adding", name); * }); * ``` */ on>(key: K, handler: ServiceHandler): this; /** * Trigger a registered service action to be executed in a scene. * @param type - Action key registered with `on`. * @param args - Arguments for the action handler. * @example * ```ts * service.trigger("myAction", "foo", 123); * ``` */ trigger>(type: K, ...args: Content[K]): Proxied>; } declare class ServiceSkeletonMask | null = never> extends ServiceSkeleton { private triggerAction; private toData; private fromChained; private chain; private proxy; private combineActions; private push; private getActions; private getSelf; private newChain; private id; private setId; private getId; private reset; private fromData; private construct; private __self; private __actions; } export declare abstract class Service | null = Record> extends ServiceSkeletonMask { /** * Serialize the service to JSON-serializable data. * Return `null` when nothing needs to be saved. */ abstract serialize?(): RawData | null; /** * Restore data previously produced by `serialize`. * @param data - Serialized payload that matches the service storage format. */ abstract deserialize?(data: RawData): void; } export {};