import { AnyObject, Maybe, EmptyObject, Class, IsPartial } from 'yummies/types'; 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 { } declare const createCounter: (processValue?: (value: number) => TValue, initial?: number) => Counter; /** * Создает глобальный конфиг, который может быть доступен в любой точке в коде */ declare const createGlobalConfig: (defaultValue: T, accessSymbol?: keyof any) => T; interface GlobalDynamicConfig { get(): TValue; set(value: TValue): TValue; unset(): void; update(value: Partial): void; } declare const createGlobalDynamicConfig: (processFn: (change: Maybe>, current: Maybe) => T, accessSymbol?: keyof any) => GlobalDynamicConfig; type ModuleLoaderConfig = { factory(moduleClass: Class, deps: TDeps): TInstance; } & (TPredefinedDeps extends EmptyObject ? { deps?: TPredefinedDeps; } : { deps: TPredefinedDeps; }); /** * Класс `ModulesFactory` является универсальной фабрикой для создания экземпляров указанного класса с зависимостями. * Он использует объект конфигурации для определения того, как эти экземпляры создаются. * * Важное примечание - эта сущность работает только с классами конструктор которых имеет один параметр * * @template TPredefinedDeps - Тип, расширяющий `AnyObject`, представляющий предопределенные зависимости, которые использует фабрика. * * @example * ``` * const factory = new ModulesFactory({ * factory: (MyClass, deps) => new MyClass(deps), * deps: { someDependency: new Dependency() } * }); * * const instance = factory.create(MyClass, { extraDependency: new ExtraDependency() }); * ``` */ declare class ModulesFactory { private config; /** * Создает новый экземпляр `ModulesFactory`. * * @param config - Объект конфигурации для фабрики, включающий функцию фабрики и необязательные зависимости. */ constructor(config: ModuleLoaderConfig); /** * Создает экземпляр указанного класса, внедряя необходимые зависимости. * * @template TInstance - Тип создаваемого экземпляра. * @template TDeps - Тип зависимостей, необходимых для экземпляра. * * @param Constructor - Конструктор класса для создаваемого экземпляра. * @param args - Необязательные дополнительные зависимости для объединения с предопределенными зависимостями. * * @returns Экземпляр указанного класса с внедренными зависимостями. */ create(Constructor: Class, ...args: IsPartial> extends true ? [extraDeps?: Omit] : [extraDeps: Omit]): TInstance; } 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; } declare const createPubSub: () => PubSub; export { ModulesFactory, createCounter, createGlobalConfig, createGlobalDynamicConfig, createPubSub }; export type { Counter, CounterFn, GlobalDynamicConfig, PubSub, SubFn };