bunja 2.1.1 → 3.0.0-alpha.4
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/README.md +135 -4
- package/bunja.ts +831 -215
- package/deno.json +1 -1
- package/dist/{bunja-BvZKLiEP.d.ts → bunja-BxbzuHdH.d.cts} +73 -18
- package/dist/bunja-C_hneAUK.cjs +685 -0
- package/dist/bunja-D0Qa6gsc.js +637 -0
- package/dist/{bunja-CPUl4ZRK.d.cts → bunja-DEFeIlpt.d.ts} +73 -18
- package/dist/bunja.cjs +1 -1
- package/dist/bunja.d.cts +2 -2
- package/dist/bunja.d.ts +2 -2
- package/dist/bunja.js +1 -1
- package/dist/react.cjs +16 -4
- package/dist/react.d.cts +3 -2
- package/dist/react.d.ts +3 -2
- package/dist/react.js +17 -4
- package/dist/solid.cjs +1 -1
- package/dist/solid.d.cts +2 -2
- package/dist/solid.d.ts +2 -2
- package/dist/solid.js +1 -1
- package/package.json +2 -2
- package/react.ts +34 -8
- package/solid.ts +4 -3
- package/test.ts +533 -4
- package/dist/bunja-Ce8RwebF.cjs +0 -437
- package/dist/bunja-DhBgerdn.js +0 -389
package/deno.json
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
//#region bunja.d.ts
|
|
2
2
|
interface BunjaFn {
|
|
3
|
-
<T>(init: () => T): Bunja<T>;
|
|
3
|
+
<T>(init: () => T): Bunja<T, NoSeed>;
|
|
4
|
+
withSeed: BunjaWithSeedFn;
|
|
4
5
|
use: BunjaUseFn;
|
|
5
|
-
|
|
6
|
+
will: BunjaWillFn;
|
|
6
7
|
effect: BunjaEffectFn;
|
|
7
8
|
}
|
|
8
9
|
declare const bunja: BunjaFn;
|
|
9
|
-
|
|
10
|
-
type
|
|
10
|
+
declare const NO_SEED: unique symbol;
|
|
11
|
+
type NoSeed = typeof NO_SEED;
|
|
12
|
+
type BunjaWithSeedFn = <Seed, T>(defaultSeed: Seed, init: (seed: Seed) => T) => Bunja<T, Seed>;
|
|
13
|
+
type ScopeValuePairs = ScopeValuePair<any>[];
|
|
14
|
+
type BunjaRefBase<T, Seed> = {
|
|
15
|
+
bunja: Bunja<T, Seed>;
|
|
16
|
+
with?: ScopeValuePairs;
|
|
17
|
+
};
|
|
18
|
+
type BunjaGetRef<T, Seed = NoSeed> = BunjaRefBase<T, Seed> & ([Seed] extends [NoSeed] ? {
|
|
19
|
+
seed?: never;
|
|
20
|
+
} : {
|
|
21
|
+
seed?: Seed;
|
|
22
|
+
});
|
|
23
|
+
type BunjaRef<T, Seed = NoSeed> = BunjaGetRef<T, Seed>;
|
|
24
|
+
type BunjaPrebakeRef<T, Seed = NoSeed> = BunjaRefBase<T, Seed> & {
|
|
25
|
+
seed?: never;
|
|
26
|
+
};
|
|
27
|
+
interface BunjaUseFn {
|
|
28
|
+
<T>(dep: Scope<T>): T;
|
|
29
|
+
<T, Seed>(dep: Bunja<T, Seed>): T;
|
|
30
|
+
<T, Seed>(bunja: Bunja<T, Seed>, scopeValuePairs: ScopeValuePairs): T;
|
|
31
|
+
<T, Seed>(ref: BunjaRef<T, Seed>): T;
|
|
32
|
+
}
|
|
33
|
+
interface BunjaWillFn {
|
|
34
|
+
<T, Seed>(dep: Bunja<T, Seed>): () => T;
|
|
35
|
+
<T, Seed>(bunja: Bunja<T, Seed>, scopeValuePairs: ScopeValuePairs): () => T;
|
|
36
|
+
<T, Seed>(ref: BunjaRef<T, Seed>): () => T;
|
|
37
|
+
}
|
|
11
38
|
type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
|
|
12
39
|
type BunjaEffectCallback = () => (() => void) | void;
|
|
13
40
|
declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
|
|
@@ -15,12 +42,25 @@ interface CreateBunjaStoreConfig {
|
|
|
15
42
|
wrapInstance?: WrapInstanceFn;
|
|
16
43
|
}
|
|
17
44
|
declare function createBunjaStore(config?: CreateBunjaStoreConfig): BunjaStore;
|
|
18
|
-
type Dep<T> = Bunja<T> | Scope<T>;
|
|
45
|
+
type Dep<T> = Bunja<T, any> | Scope<T>;
|
|
46
|
+
type AnyBunja = Bunja<any, any>;
|
|
19
47
|
interface InternalState {
|
|
20
48
|
bunjas: Record<string, BunjaInstance>;
|
|
21
49
|
scopes: Map<Scope<unknown>, Map<unknown, ScopeInstance>>;
|
|
22
50
|
instantiating: boolean;
|
|
23
51
|
}
|
|
52
|
+
type AnyNormalizedBunjaRef = NormalizedBunjaRef<any, any>;
|
|
53
|
+
interface NormalizedBunjaRef<T, Seed> {
|
|
54
|
+
bunja: Bunja<T, Seed>;
|
|
55
|
+
scopeValuePairs: ScopeValuePairs;
|
|
56
|
+
}
|
|
57
|
+
interface ActiveDependencyRecipe {
|
|
58
|
+
ref: AnyNormalizedBunjaRef;
|
|
59
|
+
seed: unknown;
|
|
60
|
+
}
|
|
61
|
+
interface BunjaInstanceRecipe {
|
|
62
|
+
activeDependencies: ActiveDependencyRecipe[];
|
|
63
|
+
}
|
|
24
64
|
type WrapInstanceFn = <T>(fn: (dispose: () => void) => T) => T;
|
|
25
65
|
declare class BunjaStore {
|
|
26
66
|
#private;
|
|
@@ -30,7 +70,8 @@ declare class BunjaStore {
|
|
|
30
70
|
constructor();
|
|
31
71
|
get _internalState(): InternalState | undefined;
|
|
32
72
|
dispose(): void;
|
|
33
|
-
get<T>(
|
|
73
|
+
get<T, Seed>(bunjaOrRef: Bunja<T, Seed> | BunjaGetRef<T, Seed>, readScope: ReadScope): BunjaStoreGetResult<T>;
|
|
74
|
+
prebake<T, Seed>(bunjaOrRef: Bunja<T, Seed> | BunjaPrebakeRef<T, Seed>, readScope: ReadScope): BunjaStorePrebakeResult;
|
|
34
75
|
}
|
|
35
76
|
type ReadScope = <T>(scope: Scope<T>) => T;
|
|
36
77
|
declare function createReadScopeFn(scopeValuePairs: ScopeValuePair<any>[], readScope: ReadScope): ReadScope;
|
|
@@ -40,22 +81,33 @@ interface BunjaStoreGetResult<T> {
|
|
|
40
81
|
deps: unknown[];
|
|
41
82
|
bunjaInstance?: BunjaInstance;
|
|
42
83
|
}
|
|
84
|
+
interface BunjaStorePrebakeResult {
|
|
85
|
+
relatedBunjas: Bunja<any, any>[];
|
|
86
|
+
requiredScopes: Scope<unknown>[];
|
|
87
|
+
}
|
|
43
88
|
declare function delayUnmount(mount: () => () => void, ms?: number): () => () => void;
|
|
44
|
-
declare class Bunja<T> {
|
|
89
|
+
declare class Bunja<T, Seed = NoSeed> {
|
|
45
90
|
#private;
|
|
46
|
-
init: () => T;
|
|
91
|
+
init: (seed: Seed) => T;
|
|
92
|
+
defaultSeed: Seed;
|
|
47
93
|
private static counter;
|
|
48
94
|
readonly id: string;
|
|
49
95
|
debugLabel: string;
|
|
50
|
-
constructor(init: () => T);
|
|
96
|
+
constructor(init: (seed: Seed) => T, defaultSeed: Seed);
|
|
51
97
|
get baked(): boolean;
|
|
52
|
-
get
|
|
53
|
-
get
|
|
54
|
-
get
|
|
55
|
-
|
|
98
|
+
get requiredBunjas(): AnyBunja[];
|
|
99
|
+
get optionalBunjas(): AnyBunja[];
|
|
100
|
+
get requiredBunjaRefs(): AnyNormalizedBunjaRef[];
|
|
101
|
+
get optionalBunjaRefs(): AnyNormalizedBunjaRef[];
|
|
102
|
+
get expandedRequiredBunjas(): AnyBunja[];
|
|
103
|
+
get relatedBunjas(): AnyBunja[];
|
|
104
|
+
get requiredScopes(): Scope<unknown>[];
|
|
105
|
+
addRequiredBunjaRef(ref: AnyNormalizedBunjaRef): void;
|
|
106
|
+
addOptionalBunjaRef(ref: AnyNormalizedBunjaRef): void;
|
|
56
107
|
addScope(scope: Scope<unknown>): void;
|
|
57
108
|
bake(): void;
|
|
58
|
-
|
|
109
|
+
calcBaseInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>): string;
|
|
110
|
+
calcInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>, activeDependencyIds?: Iterable<string>): string;
|
|
59
111
|
toString(): string;
|
|
60
112
|
}
|
|
61
113
|
declare class Scope<T> {
|
|
@@ -79,10 +131,13 @@ declare abstract class RefCounter {
|
|
|
79
131
|
declare class BunjaInstance extends RefCounter {
|
|
80
132
|
#private;
|
|
81
133
|
readonly id: string;
|
|
134
|
+
readonly baseId: string;
|
|
82
135
|
readonly value: unknown;
|
|
83
|
-
readonly
|
|
136
|
+
private readonly dependencyMounts;
|
|
137
|
+
private readonly effects;
|
|
138
|
+
readonly recipe: BunjaInstanceRecipe;
|
|
84
139
|
private readonly _dispose;
|
|
85
|
-
constructor(id: string, value: unknown,
|
|
140
|
+
constructor(id: string, baseId: string, value: unknown, dependencyMounts: (() => () => void)[], effects: BunjaEffectCallback[], recipe: BunjaInstanceRecipe, _dispose: () => void);
|
|
86
141
|
dispose(): void;
|
|
87
142
|
add(): void;
|
|
88
143
|
}
|
|
@@ -94,7 +149,7 @@ declare class ScopeInstance extends RefCounter {
|
|
|
94
149
|
constructor(value: unknown, dispose: () => void);
|
|
95
150
|
}
|
|
96
151
|
interface BunjaDevtoolsGlobalHook {
|
|
97
|
-
bunjas: Record<string, Bunja<any>>;
|
|
152
|
+
bunjas: Record<string, Bunja<any, any>>;
|
|
98
153
|
scopes: Record<string, Scope<any>>;
|
|
99
154
|
listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
|
|
100
155
|
emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
|
|
@@ -138,4 +193,4 @@ interface BunjaDevtoolsEvent {
|
|
|
138
193
|
}
|
|
139
194
|
type BunjaDevtoolsEventType = keyof BunjaDevtoolsEvent;
|
|
140
195
|
//#endregion
|
|
141
|
-
export { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn,
|
|
196
|
+
export { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaGetRef, BunjaRef, BunjaStore, BunjaStoreGetResult, BunjaStorePrebakeResult, BunjaUseFn, BunjaWillFn, BunjaWithSeedFn, CreateBunjaStoreConfig, Dep, HashFn, NoSeed, ReadScope, Scope, ScopeValuePair, ScopeValuePairs, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount };
|