UNPKG

co-share

Version:

A Javascript framework for easily building shared applications such as chats and games

37 lines (36 loc) 1.66 kB
import { Store, StoreLink } from "."; export declare type ActionIdentifier = string | number; export declare type ActionFunction<S extends Store, Params extends Array<any>> = (this: S, origin: StoreLink | undefined, ...params: Params) => void; export declare type Action<S extends Store, Params extends Array<any>> = ((this: S, ...params: Params) => void) & { publishTo(targetDescription: PublishActionTargetDescription, ...params: Params): void; forwardFrom(origin: StoreLink, ...params: Params): void; identifier: ActionIdentifier; }; export declare type UnboundAction<S extends Store, Params extends Array<any>> = { publishTo(links: Readonly<Array<StoreLink>>, ...params: Params): void; forwardFrom(store: S, origin: StoreLink, ...params: Params): void; identifier: ActionIdentifier; execute: ActionFunction<S, Params>; bindTo(store: S, overwrite?: boolean): Action<S, Params>; }; declare function createUnboundAction<S extends Store, Params extends Array<any>>(identifier: ActionIdentifier, execute: ActionFunction<S, Params>): UnboundAction<S, Params>; export declare const Action: { create: <S extends Store, Params extends any[]>(store: S, identifier: ActionIdentifier, fn: ActionFunction<S, Params>, overwrite?: boolean) => Action<S, Params>; createUnbound: typeof createUnboundAction; }; export declare type PublishActionTargetDescription = { to: "one"; one: StoreLink; } | { to: "all-except-one"; except: StoreLink; } | { to: "all-except-multiple"; except: Array<StoreLink>; } | { to: "all-fiter"; filter: (storeLink: StoreLink) => boolean; } | { to: "all"; }; export {};