zustand-duck
Version:
Simple reducer writing and cross-process state sharing.
24 lines (23 loc) • 949 B
TypeScript
import { type ActionKeyToPayload, type DuckOptions } from '../duck';
import { SharedDuckChannels } from './shared-duck-channel';
export type SharedDuckPortMessage = {
portId: string;
event: string;
channel: string;
name: string;
data: any;
};
export type SharedDuckPortMessageHandler = (message: SharedDuckPortMessage) => void;
export interface SharedDuckPort {
id: string;
send: (id: string, message: SharedDuckPortMessage) => void;
onMessage: (handler: SharedDuckPortMessageHandler) => () => void;
}
export type SharedDuckOptions<S, KTP extends ActionKeyToPayload> = DuckOptions<S, KTP> & {
name: string;
port: SharedDuckPort;
channel?: string;
channels?: SharedDuckChannels;
};
export declare const MASTER_PORT_ID = "master";
export declare const sharedDuck: <S, KTP extends ActionKeyToPayload>(options: SharedDuckOptions<S, KTP>) => import("zustand").StateCreator<S, [], [["zustand/duck", KTP]]>;