import { AnyObject, Maybe, EmptyObject, Class, IsPartial } from 'yummies/types'; /** * ---header-docs-section--- * # yummies/complex * * ## Description * * Callable **counter** objects with increment, decrement, and reset for UI steppers, pagination, * and id generators. Values can be mapped on read so the public API stays typed while the internal * tick stays numeric. This file is the `counter` slice of the broader `yummies/complex` entry point. * * ## Usage * * ```ts * import { createCounter } from "yummies/complex"; * ``` */ interface Counter { (): TValue; counter: number; value: TValue; increment(): TValue; decrement(): TValue; reset(): void; } /** * @deprecated use {`Counter`}. Will be removed in next major release */ interface CounterFn extends Counter { } /** * Creates a callable counter object with increment, decrement and reset helpers. * * The returned function increments the internal numeric counter when called and * exposes both the raw counter value and an optionally transformed `value`. * * @template TValue Public value type returned by the counter. * @param processValue Optional mapper that transforms the numeric counter value. * @param initial Initial numeric counter value. * @returns Callable counter with state and control methods. * * @example * ```ts * const counter = createCounter(); * counter.increment(); // 1 * ``` * * @example * ```ts * const idCounter = createCounter((value) => `id-${value}`, 10); * idCounter(); // 'id-11' * ``` */ declare const createCounter: (processValue?: (value: number) => TValue, initial?: number) => Counter; /** * ---header-docs-section--- * # yummies/complex * * ## Description * * **Singleton-style config** backed by either `globalThis` (keyed by symbol) or a module closure. * Use for app-wide feature flags, bootstrapped locale, or SSR-safe defaults without prop-drilling. * Pairs with `createGlobalPoint` for other global handles in the same `yummies/complex` package. * * ## Usage * * ```ts * import { createGlobalConfig } from "yummies/complex"; * ``` */ /** * Creates or reuses a globally accessible config object. * * The config is stored in a global point identified by `accessSymbol`, or in a * local closure when no symbol is provided. * * @template T Config object type. * @param defaultValue Default value used when no config has been created yet. * @param accessSymbol Optional global key used to store the config. * @returns Existing or newly initialized global config object. * * @example * ```ts * const config = createGlobalConfig({ locale: 'en' }, '__app_config__'); * ``` * * @example * ```ts * const config = createGlobalConfig({ debug: false }); * config.debug; * ``` */ declare const createGlobalConfig: (defaultValue: T, accessSymbol?: keyof any) => T; interface GlobalDynamicConfig { get(): TValue; set(value: TValue): TValue; unset(): void; update(value: Partial): void; } /** * Creates a mutable global config manager whose value is produced and updated * through a custom processor function. * * @template T Config object type. * @param processFn Function that builds the next config state from a partial change and current value. * @param accessSymbol Optional global key used to store the config. * @returns API for reading, replacing, resetting and partially updating the config. * * @example * ```ts * const config = createGlobalDynamicConfig( * (change, current) => ({ theme: 'light', ...current, ...change }), * '__theme__', * ); * ``` * * @example * ```ts * const config = createGlobalDynamicConfig((change, current) => ({ ...current, ...change })); * config.update({ locale: 'ru' }); * ``` */ declare const createGlobalDynamicConfig: (processFn: (change: Maybe>, current: Maybe) => T, accessSymbol?: keyof any) => GlobalDynamicConfig; /** * ---header-docs-section--- * # yummies/complex * * ## Description * * **Dependency-injection style factory** for classes that take a single deps object in their * constructor. Merges predefined singletons with per-call overrides so feature modules can be * constructed consistently in apps that avoid heavyweight DI containers. * * ## Usage * * ```ts * import { ModulesFactory } from "yummies/complex"; * ``` */ type ModuleLoaderConfig = { factory(moduleClass: Class, deps: TDeps): TInstance; } & (TPredefinedDeps extends EmptyObject ? { deps?: TPredefinedDeps; } : { deps: TPredefinedDeps; }); /** * Universal factory for creating class instances with predefined and per-call * dependencies. * * Works with classes whose constructor accepts a single dependency object. * * @template TPredefinedDeps Dependency shape that is always injected by the factory. * * @example * ``` * const factory = new ModulesFactory({ * factory: (MyClass, deps) => new MyClass(deps), * deps: { someDependency: new Dependency() } * }); * * const instance = factory.create(MyClass, { extraDependency: new ExtraDependency() }); * ``` * * @example * ```ts * const factory = new ModulesFactory({ * factory: (Module, deps) => new Module(deps), * }); * ``` * * @example * ```ts * const service = factory.create(UserService, { api }); * ``` */ declare class ModulesFactory { private config; /** * Creates a new module factory. * * @param config Factory strategy and predefined dependencies. * * @example * ```ts * const factory = new ModulesFactory({ * factory: (Module, deps) => new Module(deps), * }); * ``` * * @example * ```ts * const factory = new ModulesFactory({ * factory: (Module, deps) => new Module(deps), * deps: { api }, * }); * ``` */ constructor(config: ModuleLoaderConfig); /** * Creates an instance of the provided class by merging predefined and * per-call dependencies. * * @template TInstance Instance type produced by the constructor. * @template TDeps Full dependency object expected by the constructor. * @param Constructor Class constructor receiving a single dependency object. * @param args Additional dependencies merged over predefined ones. * @returns Created class instance. * * @example * ```ts * const service = factory.create(UserService, { logger }); * ``` * * @example * ```ts * const store = factory.create(UserStore); * ``` */ create(Constructor: Class, ...args: IsPartial> extends true ? [extraDeps?: Omit] : [extraDeps: Omit]): TInstance; } /** * ---header-docs-section--- * # yummies/complex * * ## Description * * Tiny **publish–subscribe** bus: subscribers register callbacks, publishers broadcast arguments, and * the last payload remains readable for late subscribers. Simpler than full event emitters when you * only need in-memory fan-out inside a feature or view-model layer. * * ## Usage * * ```ts * import { createPubSub } from "yummies/complex"; * ``` */ type SubFn = (...args: PubArgs) => void; /** * The Publish-Subscribe pattern, which allows objects to interact with each other * through an event system. Subscribers can subscribe to events and receive notifications * when these events occur. The last published data can be accessed through the `data` property. */ interface PubSub { (...args: PubArgs): void; /** * Last published arguments */ lastPub: PubArgs | undefined; /** * An array of subscriber functions (sub) that will be called * when an event is published. Each subscriber must match the type SubFn, * taking the arguments that will be passed to it when the publisher calls pub. */ subs: SubFn[]; /** * A function to unsubscribe from events. When a subscriber function (sub) is passed, * it will be removed from the `subs` array, and will no longer receive notifications. */ unsub(sub: SubFn): void; /** * A function to subscribe to events. When a subscriber function (sub) is passed, * it will be added to the `subs` array, and will receive notifications when the publisher calls pub. * Returns a function that can be used to unsubscribe from events. */ sub(sub: SubFn): VoidFunction; } /** * Creates a simple publish-subscribe dispatcher that stores the last published * arguments and allows subscription management. * * @template PubArgs Argument tuple delivered to subscribers. * @returns Callable publisher with subscribe and unsubscribe helpers. * * @example * ```ts * const pub = createPubSub<[string]>(); * pub('ready'); * ``` * * @example * ```ts * const pub = createPubSub<[number]>(); * const unsub = pub.sub((value) => console.log(value)); * ``` */ declare const createPubSub: () => PubSub; export { ModulesFactory, createCounter, createGlobalConfig, createGlobalDynamicConfig, createPubSub }; export type { Counter, CounterFn, GlobalDynamicConfig, PubSub, SubFn };