bunja 3.0.2 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bunja.d.ts CHANGED
@@ -1,2 +1,214 @@
1
- import { 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 } from "./bunja-pdetyCM3.js";
2
- 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 };
1
+ export interface BunjaFn {
2
+ <T>(init: () => T): Bunja<T, undefined>;
3
+ withSeed: BunjaWithSeedFn;
4
+ use: BunjaUseFn;
5
+ will: BunjaWillFn;
6
+ effect: BunjaEffectFn;
7
+ }
8
+ export declare const bunja: BunjaFn;
9
+ export type BunjaWithSeedFn = <Seed, T>(defaultSeed: Seed, init: (seed: Seed) => T) => Bunja<T, Seed>;
10
+ export type ScopeValuePairs = ScopeValuePair<any>[];
11
+ export interface BunjaUseFn {
12
+ <T>(dep: Scope<T>): T;
13
+ <T, Seed>(dep: Bunja<T, Seed>): T;
14
+ <T, Seed>(bunja: Bunja<T, Seed>, scopeValuePairs: ScopeValuePairs): T;
15
+ <T, Seed>(ref: BunjaRef<T, Seed>): T;
16
+ }
17
+ export interface BunjaWillFn {
18
+ <T, Seed>(dep: Bunja<T, Seed>): () => T;
19
+ <T, Seed>(bunja: Bunja<T, Seed>, scopeValuePairs: ScopeValuePairs): () => T;
20
+ <T, Seed>(ref: BunjaRef<T, Seed>): () => T;
21
+ }
22
+ export type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
23
+ export type BunjaEffectCallback = () => (() => void) | void;
24
+ export interface BunjaRef<T, Seed = undefined> extends BunjaRefBase<T, Seed> {
25
+ seed?: [Seed] extends [undefined] ? never : Seed;
26
+ }
27
+ export type BunjaGetRef<T, Seed = undefined> = BunjaRef<T, Seed>;
28
+ export interface BunjaPrebakeRef<T, Seed> extends BunjaRefBase<T, Seed> {
29
+ seed?: never;
30
+ }
31
+ interface BunjaRefBase<T, Seed> {
32
+ bunja: Bunja<T, Seed>;
33
+ with?: ScopeValuePairs;
34
+ }
35
+ export declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
36
+ export interface BunjaOverride {
37
+ readonly target: Bunja<any, any>;
38
+ readonly init: (seed: any) => any;
39
+ }
40
+ export declare function override<T, Seed>(target: Bunja<T, Seed>, init: (seed: NoInfer<Seed>) => NoInfer<T>): BunjaOverride;
41
+ export interface CreateBunjaStoreConfig {
42
+ wrapInstance?: WrapInstanceFn;
43
+ overrides?: readonly BunjaOverride[];
44
+ }
45
+ export declare function createBunjaStore(config?: CreateBunjaStoreConfig): BunjaStore;
46
+ export type Dep<T> = Bunja<T, any> | Scope<T>;
47
+ type AnyBunja = Bunja<any, any>;
48
+ interface InternalState {
49
+ bunjas: Record<string, BunjaInstance>;
50
+ scopes: Map<Scope<unknown>, Map<unknown, ScopeInstance>>;
51
+ instantiating: boolean;
52
+ }
53
+ type AnyNormalizedBunjaRef = NormalizedBunjaRef<any, any>;
54
+ interface NormalizedBunjaRef<T, Seed> {
55
+ bunja: Bunja<T, Seed>;
56
+ scopeValuePairs: ScopeValuePairs;
57
+ }
58
+ interface ActiveDependencyRecipe {
59
+ ref: AnyNormalizedBunjaRef;
60
+ seed: unknown;
61
+ }
62
+ interface BunjaInstanceRecipe {
63
+ activeDependencyIds: string[];
64
+ activeDependencies: ActiveDependencyRecipe[];
65
+ }
66
+ export type WrapInstanceFn = <T>(fn: (dispose: () => void) => T) => T;
67
+ export declare class BunjaStore {
68
+ #private;
69
+ private static counter;
70
+ readonly id: string;
71
+ inspect(bunja: AnyBunja): BunjaGraphSnapshot;
72
+ snapshot(): BunjaStoreSnapshot;
73
+ wrapInstance: WrapInstanceFn;
74
+ constructor({ wrapInstance, overrides }?: CreateBunjaStoreConfig);
75
+ get _internalState(): InternalState | undefined;
76
+ dispose(): void;
77
+ get<T, Seed>(bunjaOrRef: Bunja<T, Seed> | BunjaGetRef<T, Seed>, readScope: ReadScope): BunjaStoreGetResult<T>;
78
+ prebake<T, Seed>(bunjaOrRef: Bunja<T, Seed> | BunjaPrebakeRef<T, Seed>, readScope: ReadScope): BunjaStorePrebakeResult;
79
+ }
80
+ export type ReadScope = <T>(scope: Scope<T>) => T;
81
+ export declare function createReadScopeFn(scopeValuePairs: ScopeValuePair<any>[], readScope: ReadScope): ReadScope;
82
+ export interface BunjaStoreGetResult<T> {
83
+ value: T;
84
+ mount: () => () => void;
85
+ deps: unknown[];
86
+ bunjaInstance?: BunjaInstance;
87
+ }
88
+ export interface BunjaStorePrebakeResult {
89
+ relatedBunjas: Bunja<any, any>[];
90
+ requiredScopes: Scope<unknown>[];
91
+ }
92
+ export declare function delayUnmount(mount: () => () => void, ms?: number): () => () => void;
93
+ export declare class Bunja<T, Seed = undefined> {
94
+ init: (seed: Seed) => T;
95
+ defaultSeed: Seed;
96
+ private static counter;
97
+ readonly id: string;
98
+ debugLabel: string;
99
+ constructor(init: (seed: Seed) => T, defaultSeed: Seed);
100
+ toString(): string;
101
+ }
102
+ export declare class Scope<T> {
103
+ readonly hash: HashFn<T>;
104
+ private static counter;
105
+ readonly id: string;
106
+ debugLabel: string;
107
+ constructor(hash?: HashFn<T>);
108
+ private static identity;
109
+ bind(value: T): ScopeValuePair<T>;
110
+ toString(): string;
111
+ }
112
+ export type HashFn<T> = (value: T) => unknown;
113
+ export type ScopeValuePair<T> = [Scope<T>, T];
114
+ declare abstract class RefCounter {
115
+ #private;
116
+ abstract dispose(): void;
117
+ add(): void;
118
+ sub(): void;
119
+ }
120
+ declare class BunjaInstance extends RefCounter {
121
+ #private;
122
+ readonly id: string;
123
+ readonly baseId: string;
124
+ readonly value: unknown;
125
+ private readonly dependencyMounts;
126
+ private readonly effects;
127
+ readonly recipe: BunjaInstanceRecipe;
128
+ private readonly _dispose;
129
+ constructor(id: string, baseId: string, value: unknown, dependencyMounts: (() => () => void)[], effects: BunjaEffectCallback[], recipe: BunjaInstanceRecipe, _dispose: () => void);
130
+ dispose(): void;
131
+ add(): void;
132
+ }
133
+ declare class ScopeInstance extends RefCounter {
134
+ readonly value: unknown;
135
+ readonly dispose: () => void;
136
+ private static counter;
137
+ readonly id: string;
138
+ constructor(value: unknown, dispose: () => void);
139
+ }
140
+ export interface BunjaGraphSnapshot {
141
+ readonly storeId: string;
142
+ readonly bunjaId: string;
143
+ readonly baked: boolean;
144
+ readonly scopes: readonly Scope<unknown>[];
145
+ readonly requiredScopes: readonly Scope<unknown>[];
146
+ readonly expandedRequiredBunjas: readonly AnyBunja[];
147
+ readonly relatedBunjas: readonly AnyBunja[];
148
+ readonly requiredBunjaRefs: readonly BunjaGraphRefSnapshot[];
149
+ readonly optionalBunjaRefs: readonly BunjaGraphRefSnapshot[];
150
+ }
151
+ export interface BunjaGraphRefSnapshot {
152
+ readonly bunja: AnyBunja;
153
+ readonly scopeValuePairs: readonly (readonly [Scope<any>, any])[];
154
+ }
155
+ export interface BunjaStoreSnapshot {
156
+ readonly storeId: string;
157
+ readonly graphs: readonly BunjaGraphSnapshot[];
158
+ readonly instances: readonly {
159
+ readonly id: string;
160
+ readonly bunjaId: string;
161
+ readonly activeDependencyIds: readonly string[];
162
+ }[];
163
+ }
164
+ export interface BunjaDevtoolsGlobalHook {
165
+ stores: Map<string, WeakRef<BunjaStore>>;
166
+ snapshot(): readonly BunjaStoreSnapshot[];
167
+ bunjas: Record<string, Bunja<any, any>>;
168
+ scopes: Record<string, Scope<any>>;
169
+ listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
170
+ emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
171
+ on<T extends BunjaDevtoolsEventType>(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void;
172
+ }
173
+ export interface BunjaDevtoolsEvent {
174
+ graphChanged: {
175
+ storeId: string;
176
+ bunjaId: string;
177
+ };
178
+ bunjaCreated: {
179
+ bunjaId: string;
180
+ };
181
+ scopeCreated: {
182
+ scopeId: string;
183
+ };
184
+ storeCreated: {
185
+ storeId: string;
186
+ };
187
+ storeDisposed: {
188
+ storeId: string;
189
+ };
190
+ getCalled: {
191
+ storeId: string;
192
+ bunjaInstanceId: string;
193
+ };
194
+ bunjaInstanceMounted: {
195
+ storeId: string;
196
+ bunjaInstanceId: string;
197
+ };
198
+ bunjaInstanceUnmounted: {
199
+ storeId: string;
200
+ bunjaInstanceId: string;
201
+ };
202
+ scopeInstanceMounted: {
203
+ storeId: string;
204
+ scope: Scope<unknown>;
205
+ key: unknown;
206
+ };
207
+ scopeInstanceUnmounted: {
208
+ storeId: string;
209
+ scope: Scope<unknown>;
210
+ key: unknown;
211
+ };
212
+ }
213
+ export type BunjaDevtoolsEventType = keyof BunjaDevtoolsEvent;
214
+ export {};