/** * @file index.ts * * @date 2021-08-16 11:18 */ import React from "react"; import { RendererProps } from "../../../lib/renderer"; import { Schema } from "../../../lib/schema"; declare type WatchName = string; declare type WatchPath = string; declare type WatchCtx = string; declare type Watch = Record; /** * @example * ``` * ctx = { * a: 12, * b: { * b1, b2 * } * } * normalizeFieldPath('./b1', '/a/b/b2') // 'a.b.b1' * normalizeFieldPath('b', '/a/b/b2') // 'b * ``` * @param fieldPath * @param ctxPath * 将字段路径全部转换为绝对路径 */ export declare const normalizeFieldPath: (fieldPath: WatchPath, ctxPath?: WatchCtx) => string; /** * watcher 里维护field 树和effect 列表 */ export declare class Watcher { watchlist: { [effectId: string]: [Watch, Effect, WatchCtx]; }; changePaths: string[]; value: {}; fieldHooks: (() => void)[]; constructor(); appendChangePath(renderPath: string): void; popupChangePath(): void; curPath(): string; addWatch(watch: Watch, effect: Effect, ctx: WatchCtx): string; removeWatch(id: string): void; visit(node: T, name: string): void; effect(effectId: string): void; notifyWatch(changePath: string): void; } declare type EffectFn = (ctx: any, schema: Schema, options: string | number | boolean) => T; export interface IWatchPlugin { effectValue?: EffectFn; effectEnum?: EffectFn<{ value: string; title: string; }[]>; effectSchema?: EffectFn; } export declare const WatcherContext: React.Context<{ watcher?: Watcher | undefined; /** watch plugin */ watchPlugins?: Record | undefined; }>; export declare type Effect = (s: any) => T; export declare type EffectedCustomActions = Record; export declare const useWatchEffect: (props: RendererProps) => RendererProps; export {};