import { AsyncActionGroupBase } from './async-action-utils.js'; import { AppEffect } from './mini-rx.store.js'; export interface LoadingEffectOptions { /** Show modal overlay (default: false) */ modal?: boolean; /** Show small background loader (default: false) */ smallBackground?: boolean; } export interface ErrorToastOptions { /** Custom function to get error message from error code */ getErrorMessage?: (code: number) => string; /** Default error message when code not found */ defaultErrorMessage?: string; /** Toast duration in ms (default: -1 = persistent, user must close manually) */ duration?: number; } export interface SuccessToastOptions { /** Default toast duration in ms (default: 4000) */ defaultDuration?: number; } /** * Creates an effect that adds loading state when async actions start. * * @param groups - Array of async action groups to monitor * @param options - Loading state display options * @returns Effect that dispatches addLoadingState actions * * @example * ```typescript * // Modal loading for specific groups * export const modalLoadingEffect = createLoadingEffect( * [loadProfile, saveProfile], * { modal: true } * ); * * // Background loading for other groups * export const bgLoadingEffect = createLoadingEffect( * [loadEvents, loadRequests], * { smallBackground: true } * ); * ``` */ export declare function createLoadingEffect(groups: AsyncActionGroupBase[], options?: LoadingEffectOptions): AppEffect; /** * Creates an effect that removes loading state when async actions complete. * * @param groups - Array of async action groups to monitor * @returns Effect that dispatches removeLoadingState actions * * @example * ```typescript * export const removeLoadingEffect = createRemoveLoadingEffect([ * loadProfile, saveProfile, loadEvents, loadRequests * ]); * ``` */ export declare function createRemoveLoadingEffect(groups: AsyncActionGroupBase[]): AppEffect; /** * Creates an effect that shows success toast when async actions succeed. * Only shows toast if successTxt is defined and non-empty. * * @param groups - Array of async action groups to monitor * @param options - Toast display options * @returns Non-dispatching effect (uses toastBus directly) * * @example * ```typescript * export const successToastEffect = createSuccessToastEffect([ * saveProfile, // Has successTxt: "Profile saved!" * loadProfile, // Has successTxt: "" (no toast) * ]); * ``` */ export declare function createSuccessToastEffect(groups: AsyncActionGroupBase[], options?: SuccessToastOptions): AppEffect; /** * Creates an effect that shows error toast when async actions fail. * Handles BusinessError to show appropriate error messages. * * @param groups - Array of async action groups to monitor * @param options - Error handling options * @returns Non-dispatching effect (uses toastBus directly) * * @example * ```typescript * export const errorToastEffect = createErrorToastEffect( * [loadProfile, saveProfile], * { * getErrorMessage: (code) => { * const messages: Record = { * [-150]: "Access denied", * [-180]: "Technical error", * }; * return messages[code] || "An error occurred"; * }, * } * ); * ``` */ export declare function createErrorToastEffect(groups: AsyncActionGroupBase[], options?: ErrorToastOptions): AppEffect; /** * Options for creating all loading-related effects at once. */ export interface CreateLoadingEffectsOptions { /** Groups that show modal loading */ modalGroups?: AsyncActionGroupBase[]; /** Groups that show background loading */ backgroundGroups?: AsyncActionGroupBase[]; /** Groups that show success toasts */ successToastGroups?: AsyncActionGroupBase[]; /** All groups for error handling */ errorGroups?: AsyncActionGroupBase[]; /** Error message resolver */ getErrorMessage?: (code: number) => string; /** Default error message */ defaultErrorMessage?: string; } /** * Creates all standard loading-related effects at once. * Returns an object with all effects that can be spread into the effects array. * * @example * ```typescript * const { * modalLoadingEffect, * bgLoadingEffect, * removeLoadingEffect, * successToastEffect, * errorToastEffect * } = createAllLoadingEffects({ * modalGroups: [loadProfile, saveProfile], * backgroundGroups: [loadEvents], * successToastGroups: [saveProfile], * errorGroups: [loadProfile, saveProfile, loadEvents], * getErrorMessage: myErrorMessageFn, * }); * * // In store config: * effects: [ * modalLoadingEffect, * bgLoadingEffect, * removeLoadingEffect, * successToastEffect, * errorToastEffect, * // ... other effects * ] * ``` */ export declare function createAllLoadingEffects(options: CreateLoadingEffectsOptions): { modalLoadingEffect: AppEffect | null; bgLoadingEffect: AppEffect | null; removeLoadingEffect: AppEffect | null; successToastEffect: AppEffect | null; errorToastEffect: AppEffect | null; }; //# sourceMappingURL=async-action-effects.d.ts.map