@ryo-98/react-api-bridge
Version:
A registry for component imperative api
53 lines (52 loc) • 7.16 kB
TypeScript
import React, { DependencyList } from "react";
import { APIParams, BaseOptions, BoundaryAPI, BoundaryContextValue, BoundaryProps, GetAPIAsyncOptions, GetAPIOptions, GetUpperAPIOptions, UpperOptions } from "./types";
type PayloadParameter<T> = undefined extends T ? [payload?: T] : [payload: T];
declare const createBridge: <A extends APIParams, P extends unknown = any>(...args: PayloadParameter<P>) => (<O extends Partial<Record<keyof A, import("./types").APIOptions>>>(options?: O) => {
Boundary: React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithChildren<BoundaryProps<A, P, O>>> & React.RefAttributes<BoundaryAPI<A, O, P>>>;
initCbMap: WeakMap<import("./types").ConditionByIsMulti<O, keyof A, React.RefObject<A[keyof A]>[], React.RefObject<A[keyof A]>>, {
onInit: Function;
hookId: HookId;
}[]>;
initializedCallbacksMap: Map<React.RefObject<A[keyof A]>, HookId[]>;
getAPI<N extends keyof A>(name: N, contextValue?: BoundaryContextValue<A, P, O>): import("./types").ConditionByIsMulti<O, N, React.RefObject<A[N]>[], React.RefObject<A[N]>>;
getAPIAsync<N_1 extends keyof A>(name: N_1, options?: GetAPIAsyncOptions<A, O, P> | undefined): Promise<import("./types").ConditionByIsMulti<O, N_1, React.RefObject<A[N_1]>[], React.RefObject<A[N_1]>>>;
useAPI: <N_2 extends keyof A>(name: N_2, hookOptions?: GetAPIOptions<A, N_2, O, any> | undefined) => import("./types").ConditionByIsMulti<O, N_2, React.RefObject<A[N_2]>[], React.RefObject<A[N_2]>>;
useBoundaryPayload: (hookOptions?: BaseOptions<A, O, P> | undefined) => P;
useBoundaryRef: () => React.RefObject<BoundaryAPI<A, O, P>>;
useContextValue: (...args: PayloadParameter<P>) => BoundaryContextValue<A, P, O>;
useRegister: <N_3 extends keyof A, T extends A[N_3]>(name: N_3, init: () => T, deps?: DependencyList, hookOptions?: BaseOptions<A, O, any> | undefined) => void;
useTools: (hookOptions?: BaseOptions<A, O, P> | undefined) => {
getAPI: <N1 extends keyof A>(_name: N1, options?: BaseOptions<A, O, P> | undefined) => import("./types").ConditionByIsMulti<O, N1, React.RefObject<A[N1]>[], React.RefObject<A[N1]>>;
getBoundaryPayload: (options?: BaseOptions<A, O, P> | undefined) => P;
getUpperAPI: <N1_1 extends keyof A>(_name: N1_1, options?: GetUpperAPIOptions<A, N1_1, O, P> | undefined) => import("./types").ConditionByIsMulti<O, N1_1, React.RefObject<A[N1_1]>[], React.RefObject<A[N1_1]>> | undefined;
getUpperBoundaryPayload: (options?: UpperOptions<A, O, P> | undefined) => P | undefined;
getAPIAsync: <N1_2 extends keyof A>(_name: N1_2, options?: GetAPIAsyncOptions<A, O, P> | undefined) => Promise<import("./types").ConditionByIsMulti<O, N1_2, React.RefObject<A[N1_2]>[], React.RefObject<A[N1_2]>>>;
};
useUpperAPI: <N_4 extends keyof A>(name: N_4, hookOptions?: GetUpperAPIOptions<A, N_4, O, P> | undefined) => import("./types").ConditionByIsMulti<O, N_4, React.RefObject<A[N_4]>[], React.RefObject<A[N_4]>> | undefined;
useUpperBoundaryPayload: (hookOptions?: UpperOptions<A, O, P> | undefined) => P | undefined;
}) & {
Boundary: React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithChildren<BoundaryProps<A, P, Partial<Record<keyof A, import("./types").APIOptions>>>>> & React.RefAttributes<BoundaryAPI<A, Partial<Record<keyof A, import("./types").APIOptions>>, P>>>;
initCbMap: WeakMap<import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, keyof A, React.RefObject<A[keyof A]>[], React.RefObject<A[keyof A]>>, {
onInit: Function;
hookId: HookId;
}[]>;
initializedCallbacksMap: Map<React.RefObject<A[keyof A]>, HookId[]>;
getAPI<N_5 extends keyof A>(name: N_5, contextValue?: BoundaryContextValue<A, P, Partial<Record<keyof A, import("./types").APIOptions>>>): import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N_5, React.RefObject<A[N_5]>[], React.RefObject<A[N_5]>>;
getAPIAsync<N_6 extends keyof A>(name: N_6, options?: GetAPIAsyncOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined): Promise<import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N_6, React.RefObject<A[N_6]>[], React.RefObject<A[N_6]>>>;
useAPI: <N_7 extends keyof A>(name: N_7, hookOptions?: GetAPIOptions<A, N_7, Partial<Record<keyof A, import("./types").APIOptions>>, any> | undefined) => import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N_7, React.RefObject<A[N_7]>[], React.RefObject<A[N_7]>>;
useBoundaryPayload: (hookOptions?: BaseOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => P;
useBoundaryRef: () => React.RefObject<BoundaryAPI<A, Partial<Record<keyof A, import("./types").APIOptions>>, P>>;
useContextValue: (...args: PayloadParameter<P>) => BoundaryContextValue<A, P, Partial<Record<keyof A, import("./types").APIOptions>>>;
useRegister: <N_8 extends keyof A, T_1 extends A[N_8]>(name: N_8, init: () => T_1, deps?: DependencyList, hookOptions?: BaseOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, any> | undefined) => void;
useTools: (hookOptions?: BaseOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => {
getAPI: <N1_3 extends keyof A>(_name: N1_3, options?: BaseOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N1_3, React.RefObject<A[N1_3]>[], React.RefObject<A[N1_3]>>;
getBoundaryPayload: (options?: BaseOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => P;
getUpperAPI: <N1_4 extends keyof A>(_name: N1_4, options?: GetUpperAPIOptions<A, N1_4, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N1_4, React.RefObject<A[N1_4]>[], React.RefObject<A[N1_4]>> | undefined;
getUpperBoundaryPayload: (options?: UpperOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => P | undefined;
getAPIAsync: <N1_5 extends keyof A>(_name: N1_5, options?: GetAPIAsyncOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => Promise<import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N1_5, React.RefObject<A[N1_5]>[], React.RefObject<A[N1_5]>>>;
};
useUpperAPI: <N_9 extends keyof A>(name: N_9, hookOptions?: GetUpperAPIOptions<A, N_9, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => import("./types").ConditionByIsMulti<Partial<Record<keyof A, import("./types").APIOptions>>, N_9, React.RefObject<A[N_9]>[], React.RefObject<A[N_9]>> | undefined;
useUpperBoundaryPayload: (hookOptions?: UpperOptions<A, Partial<Record<keyof A, import("./types").APIOptions>>, P> | undefined) => P | undefined;
};
export default createBridge;
type HookId = string | symbol;