UNPKG

@bolttech/form-engine

Version:

A form engine based on form events for react projects

53 lines (52 loc) 2.32 kB
import Form from '@core/managers/Form'; import { IObservable, TEvents, TEventsKeys, TObservable, TSchema, TScope } from '@core/types'; import { EEVents } from '@core/constants'; import { TEventPublishPayload, TLoggingEvent } from '@core/events/events.types'; declare class Observer implements IObservable { #private; regexBasedEvents: Record<string, { regex: RegExp; handlers: TObservable[]; }>; events: TEvents; history: { [key in EEVents]?: string; }; namespace: string; enableLogging: boolean; constructor(namespace: string, enableLogging?: boolean); runForRegexBasedEvent(eventName: any, cb: (event: TEventsKeys) => void): boolean; handleRegexSubscription(eventName: any, handler: TObservable): void; /** * This function lets you subscribe to a given event and register one callback to be called when someone published in it * * The callback you redister will, return you the published data and one function to unregister your callback from that event * */ subscribe(eventName: TEventsKeys, handler: TObservable): () => void; unsubscribe(eventName: TEventsKeys, handler: TObservable): void; isAsyncFunction(fn: (...data: any) => any): boolean; /** * Allows to publish data to a given event name * * Will iterate the subscriptions and call their handlers. * * When calling the handler, will also inject the unsubscribe function * * This methods also accepts one regex and will find the matchin events and * publish in them * */ publish(eventName: TEventsKeys, data?: TEventPublishPayload): Promise<{}>; publishForEvents(eventName: TEventsKeys, data: {}, events: TEvents): Promise<{}>; logError(flow: Pick<TLoggingEvent, 'flow'>['flow'], event: string, method: string, error: unknown): void; logInfo(flow: Pick<TLoggingEvent, 'flow'>['flow'], event: string, method: string, extraData?: any): void; } export declare const getFormInstance: (namespace?: string, opts?: { schema?: TSchema; initialScope?: TScope; initialValues?: Record<string, any>; newInstance?: boolean; group?: string; }) => Form, getGroupFormsIds: (group: string) => string[]; export { Observer };