create-pubsub
Version:
A tiny Event Emitter and Observable Store.
17 lines (13 loc) • 623 B
TypeScript
import { Draft } from 'immer';
type SubscriptionHandler<T = void> = (data: T, previousData: T) => void;
type UnsubscribeFunction = () => void;
type GetFunction<T> = () => T;
type SubscribeFunction<T> = (handler: SubscriptionHandler<T>) => UnsubscribeFunction;
type DraftFunction<T> = (draft: Draft<T>) => void;
type PublishImmerFunction<T> = (draftFunction: DraftFunction<T>) => void;
declare function createImmerPubSub<T>(storedData: T): [
publish: PublishImmerFunction<T>,
subscribe: SubscribeFunction<T>,
getStoredData: GetFunction<T>
];
export { DraftFunction, PublishImmerFunction, createImmerPubSub };