import React, { ReactElement } from 'react'; declare type ValueType> = T extends BlocBase ? U : never; declare type BlocClass = new (...args: never[]) => T; declare type BlocHookData> = [ value: ValueType, instance: T ]; interface BlocOptions { persistKey?: string; persistData?: boolean; } interface ChangeEvent { currentState: T; nextState: T; } interface TransitionEvent { currentState: T; event: E; nextState: T; } interface BlocObserverOptions { onChange?: (bloc: BlocBase, event: ChangeEvent) => void; onTransition?: (bloc: BlocBase, event: TransitionEvent) => void; } declare class BlocObserver { onChange: (bloc: BlocBase, event: ChangeEvent) => void; onTransition: (bloc: BlocBase, event: TransitionEvent) => void; constructor(methods?: BlocObserverOptions); readonly addChange: (bloc: BlocBase, state: any) => void; readonly addTransition: (bloc: BlocBase, state: any, event: any) => void; readonly addBlocAdded: (bloc: BlocBase) => void; readonly addBlocRemoved: (bloc: BlocBase) => void; private readonly defaultAction; onBlocAdded: (bloc: BlocBase) => void; onBlocRemoved: (bloc: BlocBase) => void; private createTransitionEvent; private createChangeEvent; } declare type BlocObserverScope = "local" | "global" | "all"; interface ProviderItem { id: string; parent?: string; bloc: BlocBase; } interface ConsumerOptions { observer?: BlocObserver; } declare class BlacConsumer { observer: BlocObserver; mocksEnabled: boolean; providerList: ProviderItem[]; private blocListGlobal; private blocChangeObservers; private blocValueChangeObservers; private mockBlocs; constructor(blocs: BlocBase[], options?: ConsumerOptions); notifyChange(bloc: BlocBase, state: any): void; notifyValueChange(bloc: BlocBase): void; notifyTransition(bloc: BlocBase, state: any, event: any): void; addBlocChangeObserver>(blocClass: BlocClass, callback: (bloc: T, event: ChangeEvent>) => unknown, scope?: BlocObserverScope): void; addBlocValueChangeObserver>(blocClass: BlocClass, callback: (bloc: T) => unknown, scope?: BlocObserverScope): void; addLocalBloc(item: ProviderItem): void; removeLocalBloc(id: string, bloc: BlocBase): void; addBlocMock(bloc: BlocBase): void; resetMocks(): void; getGlobalBloc(blocClass: BlocClass): undefined | BlocBase; getLocalBlocForProvider(id: string, blocClass: BlocClass): BlocBase | undefined; protected getGlobalBlocInstance(global: BlocBase[], blocClass: BlocClass): BlocBase | undefined; } interface Observer { next: (v: any) => void; } interface Subscription { unsubscribe: () => void; } declare type RemoveMethods = () => void; declare class StreamAbstraction { isClosed: boolean; removeListeners: Array; protected readonly _options: BlocOptions; private _subject; constructor(initialValue: T, blocOptions?: BlocOptions); get state(): T; readonly removeRemoveListener: (index: number) => void; readonly addRemoveListener: (method: RemoveMethods) => () => void; subscribe: (observer: Observer) => Subscription; complete: () => void; clearCache: () => void; jsonToState(state: string): T; stateToJson(state: T): string; protected next: (value: T) => void; protected getCachedValue: () => T | Error; protected updateCache: () => void; } interface BlocMeta { scope: 'unknown' | 'local' | 'global'; } declare type ChangeMethod = (change: ChangeEvent, bloc: BlocBase) => void; declare type RegisterMethod = (consumer: BlacConsumer, bloc: BlocBase) => void; declare type ValueChangeMethod = (value: T, bloc: BlocBase) => void; declare class BlocBase extends StreamAbstraction { id: string; createdAt: Date; meta: BlocMeta; changeListeners: ChangeMethod[]; registerListeners: RegisterMethod[]; valueChangeListeners: ValueChangeMethod[]; consumer: BlacConsumer | null; constructor(initialValue: T, blocOptions?: BlocOptions); readonly removeChangeListener: (index: number) => void; readonly addChangeListener: (method: ChangeMethod) => () => void; readonly removeValueChangeListener: (index: number) => void; readonly addValueChangeListener: (method: ValueChangeMethod) => () => void; readonly removeRegisterListener: (index: number) => void; readonly addRegisterListener: (method: RegisterMethod) => () => void; readonly notifyChange: (state: T) => void; readonly notifyValueChange: () => void; } declare type EventHandler = (event: E, emit: (state: T) => void) => void | Promise; declare class Bloc extends BlocBase { onTransition: null | ((change: { currentState: T; event: E; nextState: T; }) => void); /** * @deprecated The method is deprecated. Use `on` to add your event handlers instead. */ protected mapEventToState: null | ((event: E) => T); eventHandlers: [E, EventHandler][]; constructor(initialState: T, options?: BlocOptions); add: (event: E) => void; private emit; /** * Add a listener to the Bloc for when a new event is added. There can only be one handler for each event. * @param event The event that was added to the Bloc * @param handler A method that receives the event and a `emit` function that can be used to update the state */ readonly on: (event: E, handler: EventHandler) => void; protected notifyTransition: (state: T, event: E) => void; } declare class Cubit extends BlocBase { emit: (value: T) => void; } interface BlocHookOptions> { subscribe?: boolean; shouldUpdate?: (event: ChangeEvent>) => boolean; create?: () => T; } declare class BlacReact extends BlacConsumer { private readonly _blocsGlobal; private _contextLocalProviderKey; constructor(blocs: BlocBase[], options?: ConsumerOptions); useBloc: >(blocClass: BlocClass, options?: BlocHookOptions) => BlocHookData; BlocBuilder>(props: { blocClass: BlocClass; builder: (data: BlocHookData) => ReactElement; shouldUpdate?: (event: ChangeEvent>) => boolean; }): ReactElement | null; BlocProvider>(props: { children?: ReactElement | ReactElement[] | false; bloc: T | ((id: string) => T); }): ReactElement; withBlocProvider:

(bloc: BlocBase | (() => BlocBase)) => (Component: React.ComponentType

) => React.ComponentType

; } export { BlacReact, Bloc, BlocObserver, Cubit };