//#region bunja.d.ts interface BunjaFn { (init: () => T): Bunja; withSeed: BunjaWithSeedFn; use: BunjaUseFn; will: BunjaWillFn; effect: BunjaEffectFn; } declare const bunja: BunjaFn; type BunjaWithSeedFn = (defaultSeed: Seed, init: (seed: Seed) => T) => Bunja; type ScopeValuePairs = ScopeValuePair[]; interface BunjaUseFn { (dep: Scope): T; (dep: Bunja): T; (bunja: Bunja, scopeValuePairs: ScopeValuePairs): T; (ref: BunjaRef): T; } interface BunjaWillFn { (dep: Bunja): () => T; (bunja: Bunja, scopeValuePairs: ScopeValuePairs): () => T; (ref: BunjaRef): () => T; } type BunjaEffectFn = (callback: BunjaEffectCallback) => void; type BunjaEffectCallback = () => (() => void) | void; interface BunjaRef extends BunjaRefBase { seed?: [Seed] extends [undefined] ? never : Seed; } type BunjaGetRef = BunjaRef; interface BunjaPrebakeRef extends BunjaRefBase { seed?: never; } interface BunjaRefBase { bunja: Bunja; with?: ScopeValuePairs; } declare function createScope(hash?: HashFn): Scope; interface CreateBunjaStoreConfig { wrapInstance?: WrapInstanceFn; } declare function createBunjaStore(config?: CreateBunjaStoreConfig): BunjaStore; type Dep = Bunja | Scope; type AnyBunja = Bunja; interface InternalState { bunjas: Record; scopes: Map, Map>; instantiating: boolean; } type AnyNormalizedBunjaRef = NormalizedBunjaRef; interface NormalizedBunjaRef { bunja: Bunja; scopeValuePairs: ScopeValuePairs; } interface ActiveDependencyRecipe { ref: AnyNormalizedBunjaRef; seed: unknown; } interface BunjaInstanceRecipe { activeDependencies: ActiveDependencyRecipe[]; } type WrapInstanceFn = (fn: (dispose: () => void) => T) => T; declare class BunjaStore { #private; private static counter; readonly id: string; wrapInstance: WrapInstanceFn; constructor(); get _internalState(): InternalState | undefined; dispose(): void; get(bunjaOrRef: Bunja | BunjaGetRef, readScope: ReadScope): BunjaStoreGetResult; prebake(bunjaOrRef: Bunja | BunjaPrebakeRef, readScope: ReadScope): BunjaStorePrebakeResult; } type ReadScope = (scope: Scope) => T; declare function createReadScopeFn(scopeValuePairs: ScopeValuePair[], readScope: ReadScope): ReadScope; interface BunjaStoreGetResult { value: T; mount: () => () => void; deps: unknown[]; bunjaInstance?: BunjaInstance; } interface BunjaStorePrebakeResult { relatedBunjas: Bunja[]; requiredScopes: Scope[]; } declare function delayUnmount(mount: () => () => void, ms?: number): () => () => void; declare class Bunja { #private; init: (seed: Seed) => T; defaultSeed: Seed; private static counter; readonly id: string; debugLabel: string; constructor(init: (seed: Seed) => T, defaultSeed: Seed); get baked(): boolean; get requiredBunjas(): AnyBunja[]; get optionalBunjas(): AnyBunja[]; get requiredBunjaRefs(): AnyNormalizedBunjaRef[]; get optionalBunjaRefs(): AnyNormalizedBunjaRef[]; get expandedRequiredBunjas(): AnyBunja[]; get relatedBunjas(): AnyBunja[]; get requiredScopes(): Scope[]; addRequiredBunjaRef(ref: AnyNormalizedBunjaRef): void; addOptionalBunjaRef(ref: AnyNormalizedBunjaRef): void; addScope(scope: Scope): void; bake(): void; calcBaseInstanceId(scopeInstanceMap: Map, ScopeInstance>): string; calcInstanceId(scopeInstanceMap: Map, ScopeInstance>, activeDependencyIds?: Iterable): string; toString(): string; } declare class Scope { readonly hash: HashFn; private static counter; readonly id: string; debugLabel: string; constructor(hash?: HashFn); private static identity; bind(value: T): ScopeValuePair; toString(): string; } type HashFn = (value: T) => unknown; type ScopeValuePair = [Scope, T]; declare abstract class RefCounter { #private; abstract dispose(): void; add(): void; sub(): void; } declare class BunjaInstance extends RefCounter { #private; readonly id: string; readonly baseId: string; readonly value: unknown; private readonly dependencyMounts; private readonly effects; readonly recipe: BunjaInstanceRecipe; private readonly _dispose; constructor(id: string, baseId: string, value: unknown, dependencyMounts: (() => () => void)[], effects: BunjaEffectCallback[], recipe: BunjaInstanceRecipe, _dispose: () => void); dispose(): void; add(): void; } declare class ScopeInstance extends RefCounter { readonly value: unknown; readonly dispose: () => void; private static counter; readonly id: string; constructor(value: unknown, dispose: () => void); } interface BunjaDevtoolsGlobalHook { bunjas: Record>; scopes: Record>; listeners: Record void>>; emit(type: T, event: BunjaDevtoolsEvent[T]): void; on(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void; } interface BunjaDevtoolsEvent { bunjaCreated: { bunjaId: string; }; scopeCreated: { scopeId: string; }; storeCreated: { storeId: string; }; storeDisposed: { storeId: string; }; getCalled: { storeId: string; bunjaInstanceId: string; }; bunjaInstanceMounted: { storeId: string; bunjaInstanceId: string; }; bunjaInstanceUnmounted: { storeId: string; bunjaInstanceId: string; }; scopeInstanceMounted: { storeId: string; scope: Scope; key: unknown; }; scopeInstanceUnmounted: { storeId: string; scope: Scope; key: unknown; }; } type BunjaDevtoolsEventType = keyof BunjaDevtoolsEvent; //#endregion export { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaGetRef, BunjaPrebakeRef, BunjaRef, BunjaStore, BunjaStoreGetResult, BunjaStorePrebakeResult, BunjaUseFn, BunjaWillFn, BunjaWithSeedFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, ScopeValuePairs, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount };