@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
44 lines (43 loc) • 1.65 kB
TypeScript
import { Path, Value } from "@yamada-ui/utils";
//#region src/utils/store.d.ts
interface Subscribe {
(listener: () => void): () => void;
}
interface Store<Y> {
ref: {
current: Y;
};
get: () => Y;
queue: Map<string, (() => void)[]>;
set: (nextState: ((prevState: Y) => Y) | Y, key?: string | string[]) => void;
update: (key?: string | string[]) => void;
key?: string;
}
type IndexOrPath<Y> = Y extends any[] ? number : Y extends object ? Path<Y> : undefined;
type ReturnArrayValue<Y extends any[], D$1> = D$1 extends number ? undefined | Y[D$1] : Y;
type ReturnObjectValue<Y extends object, D$1> = D$1 extends string ? Value<Y, D$1> : Y;
type ReturnValue<Y, D$1> = Y extends any[] ? ReturnArrayValue<Y, D$1> : Y extends object ? ReturnObjectValue<Y, D$1> : Y;
interface UseStore<Y> {
<D$1 extends IndexOrPath<Y>>(path?: D$1, key?: string): ReturnValue<Y, D$1>;
}
interface CreateMethod<Y, M extends Function> {
(store: Store<Y>): M;
}
type Methods<Y, M extends CustomMethods<Y>> = { [D in keyof M]: ReturnType<M[D]> } & {
get: () => Y;
set: (nextState: ((prevState: Y) => Y) | Y, key?: string | string[]) => void;
update: () => void;
};
interface CustomMethods<Y> {
[key: string]: CreateMethod<Y, (...args: any[]) => Promise<void> | void>;
}
interface CreateStoreOptions<Y> {
proxyHandler?: ProxyHandler<{
current: Y;
}>;
subscribe?: CreateMethod<Y, Subscribe>;
}
declare function createStore<Y, M extends CustomMethods<Y>>(initialState: (() => Y) | Y, additionalMethods?: M, options?: CreateStoreOptions<Y>): [UseStore<Y>, Methods<Y, M>];
//#endregion
export { createStore };
//# sourceMappingURL=store.d.ts.map