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 +214 -2
- package/dist/bunja.js +780 -3
- package/dist/react.d.ts +7 -13
- package/dist/react.js +7 -10
- package/dist/solid/v1-compat.d.ts +11 -0
- package/dist/solid/v1-compat.js +69 -0
- package/dist/solid.d.ts +9 -12
- package/dist/solid.js +28 -22
- package/package.json +31 -45
- package/bunja.ts +0 -1199
- package/deno.json +0 -17
- package/dist/bunja-B81fiP3K.d.cts +0 -192
- package/dist/bunja-BmPnlAec.js +0 -636
- package/dist/bunja-DJPGfe5j.cjs +0 -684
- package/dist/bunja-pdetyCM3.d.ts +0 -192
- package/dist/bunja.cjs +0 -10
- package/dist/bunja.d.cts +0 -2
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/react.cjs +0 -74
- package/dist/react.d.cts +0 -15
- package/dist/solid.cjs +0 -68
- package/dist/solid.d.cts +0 -14
- package/react.ts +0 -113
- package/solid.ts +0 -115
- package/solid_test.ts +0 -166
- package/test.ts +0 -868
- package/tsconfig.json +0 -13
- package/tsdown.config.ts +0 -10
package/dist/bunja-pdetyCM3.d.ts
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
//#region bunja.d.ts
|
|
2
|
-
interface BunjaFn {
|
|
3
|
-
<T>(init: () => T): Bunja<T, undefined>;
|
|
4
|
-
withSeed: BunjaWithSeedFn;
|
|
5
|
-
use: BunjaUseFn;
|
|
6
|
-
will: BunjaWillFn;
|
|
7
|
-
effect: BunjaEffectFn;
|
|
8
|
-
}
|
|
9
|
-
declare const bunja: BunjaFn;
|
|
10
|
-
type BunjaWithSeedFn = <Seed, T>(defaultSeed: Seed, init: (seed: Seed) => T) => Bunja<T, Seed>;
|
|
11
|
-
type ScopeValuePairs = ScopeValuePair<any>[];
|
|
12
|
-
interface BunjaUseFn {
|
|
13
|
-
<T>(dep: Scope<T>): T;
|
|
14
|
-
<T, Seed>(dep: Bunja<T, Seed>): T;
|
|
15
|
-
<T, Seed>(bunja: Bunja<T, Seed>, scopeValuePairs: ScopeValuePairs): T;
|
|
16
|
-
<T, Seed>(ref: BunjaRef<T, Seed>): T;
|
|
17
|
-
}
|
|
18
|
-
interface BunjaWillFn {
|
|
19
|
-
<T, Seed>(dep: Bunja<T, Seed>): () => T;
|
|
20
|
-
<T, Seed>(bunja: Bunja<T, Seed>, scopeValuePairs: ScopeValuePairs): () => T;
|
|
21
|
-
<T, Seed>(ref: BunjaRef<T, Seed>): () => T;
|
|
22
|
-
}
|
|
23
|
-
type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
|
|
24
|
-
type BunjaEffectCallback = () => (() => void) | void;
|
|
25
|
-
interface BunjaRef<T, Seed = undefined> extends BunjaRefBase<T, Seed> {
|
|
26
|
-
seed?: [Seed] extends [undefined] ? never : Seed;
|
|
27
|
-
}
|
|
28
|
-
type BunjaGetRef<T, Seed = undefined> = BunjaRef<T, Seed>;
|
|
29
|
-
interface BunjaPrebakeRef<T, Seed> extends BunjaRefBase<T, Seed> {
|
|
30
|
-
seed?: never;
|
|
31
|
-
}
|
|
32
|
-
interface BunjaRefBase<T, Seed> {
|
|
33
|
-
bunja: Bunja<T, Seed>;
|
|
34
|
-
with?: ScopeValuePairs;
|
|
35
|
-
}
|
|
36
|
-
declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
|
|
37
|
-
interface CreateBunjaStoreConfig {
|
|
38
|
-
wrapInstance?: WrapInstanceFn;
|
|
39
|
-
}
|
|
40
|
-
declare function createBunjaStore(config?: CreateBunjaStoreConfig): BunjaStore;
|
|
41
|
-
type Dep<T> = Bunja<T, any> | Scope<T>;
|
|
42
|
-
type AnyBunja = Bunja<any, any>;
|
|
43
|
-
interface InternalState {
|
|
44
|
-
bunjas: Record<string, BunjaInstance>;
|
|
45
|
-
scopes: Map<Scope<unknown>, Map<unknown, ScopeInstance>>;
|
|
46
|
-
instantiating: boolean;
|
|
47
|
-
}
|
|
48
|
-
type AnyNormalizedBunjaRef = NormalizedBunjaRef<any, any>;
|
|
49
|
-
interface NormalizedBunjaRef<T, Seed> {
|
|
50
|
-
bunja: Bunja<T, Seed>;
|
|
51
|
-
scopeValuePairs: ScopeValuePairs;
|
|
52
|
-
}
|
|
53
|
-
interface ActiveDependencyRecipe {
|
|
54
|
-
ref: AnyNormalizedBunjaRef;
|
|
55
|
-
seed: unknown;
|
|
56
|
-
}
|
|
57
|
-
interface BunjaInstanceRecipe {
|
|
58
|
-
activeDependencies: ActiveDependencyRecipe[];
|
|
59
|
-
}
|
|
60
|
-
type WrapInstanceFn = <T>(fn: (dispose: () => void) => T) => T;
|
|
61
|
-
declare class BunjaStore {
|
|
62
|
-
#private;
|
|
63
|
-
private static counter;
|
|
64
|
-
readonly id: string;
|
|
65
|
-
wrapInstance: WrapInstanceFn;
|
|
66
|
-
constructor();
|
|
67
|
-
get _internalState(): InternalState | undefined;
|
|
68
|
-
dispose(): void;
|
|
69
|
-
get<T, Seed>(bunjaOrRef: Bunja<T, Seed> | BunjaGetRef<T, Seed>, readScope: ReadScope): BunjaStoreGetResult<T>;
|
|
70
|
-
prebake<T, Seed>(bunjaOrRef: Bunja<T, Seed> | BunjaPrebakeRef<T, Seed>, readScope: ReadScope): BunjaStorePrebakeResult;
|
|
71
|
-
}
|
|
72
|
-
type ReadScope = <T>(scope: Scope<T>) => T;
|
|
73
|
-
declare function createReadScopeFn(scopeValuePairs: ScopeValuePair<any>[], readScope: ReadScope): ReadScope;
|
|
74
|
-
interface BunjaStoreGetResult<T> {
|
|
75
|
-
value: T;
|
|
76
|
-
mount: () => () => void;
|
|
77
|
-
deps: unknown[];
|
|
78
|
-
bunjaInstance?: BunjaInstance;
|
|
79
|
-
}
|
|
80
|
-
interface BunjaStorePrebakeResult {
|
|
81
|
-
relatedBunjas: Bunja<any, any>[];
|
|
82
|
-
requiredScopes: Scope<unknown>[];
|
|
83
|
-
}
|
|
84
|
-
declare function delayUnmount(mount: () => () => void, ms?: number): () => () => void;
|
|
85
|
-
declare class Bunja<T, Seed = undefined> {
|
|
86
|
-
#private;
|
|
87
|
-
init: (seed: Seed) => T;
|
|
88
|
-
defaultSeed: Seed;
|
|
89
|
-
private static counter;
|
|
90
|
-
readonly id: string;
|
|
91
|
-
debugLabel: string;
|
|
92
|
-
constructor(init: (seed: Seed) => T, defaultSeed: Seed);
|
|
93
|
-
get baked(): boolean;
|
|
94
|
-
get requiredBunjas(): AnyBunja[];
|
|
95
|
-
get optionalBunjas(): AnyBunja[];
|
|
96
|
-
get requiredBunjaRefs(): AnyNormalizedBunjaRef[];
|
|
97
|
-
get optionalBunjaRefs(): AnyNormalizedBunjaRef[];
|
|
98
|
-
get expandedRequiredBunjas(): AnyBunja[];
|
|
99
|
-
get relatedBunjas(): AnyBunja[];
|
|
100
|
-
get requiredScopes(): Scope<unknown>[];
|
|
101
|
-
addRequiredBunjaRef(ref: AnyNormalizedBunjaRef): void;
|
|
102
|
-
addOptionalBunjaRef(ref: AnyNormalizedBunjaRef): void;
|
|
103
|
-
addScope(scope: Scope<unknown>): void;
|
|
104
|
-
bake(): void;
|
|
105
|
-
calcBaseInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>): string;
|
|
106
|
-
calcInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>, activeDependencyIds?: Iterable<string>): string;
|
|
107
|
-
toString(): string;
|
|
108
|
-
}
|
|
109
|
-
declare class Scope<T> {
|
|
110
|
-
readonly hash: HashFn<T>;
|
|
111
|
-
private static counter;
|
|
112
|
-
readonly id: string;
|
|
113
|
-
debugLabel: string;
|
|
114
|
-
constructor(hash?: HashFn<T>);
|
|
115
|
-
private static identity;
|
|
116
|
-
bind(value: T): ScopeValuePair<T>;
|
|
117
|
-
toString(): string;
|
|
118
|
-
}
|
|
119
|
-
type HashFn<T> = (value: T) => unknown;
|
|
120
|
-
type ScopeValuePair<T> = [Scope<T>, T];
|
|
121
|
-
declare abstract class RefCounter {
|
|
122
|
-
#private;
|
|
123
|
-
abstract dispose(): void;
|
|
124
|
-
add(): void;
|
|
125
|
-
sub(): void;
|
|
126
|
-
}
|
|
127
|
-
declare class BunjaInstance extends RefCounter {
|
|
128
|
-
#private;
|
|
129
|
-
readonly id: string;
|
|
130
|
-
readonly baseId: string;
|
|
131
|
-
readonly value: unknown;
|
|
132
|
-
private readonly dependencyMounts;
|
|
133
|
-
private readonly effects;
|
|
134
|
-
readonly recipe: BunjaInstanceRecipe;
|
|
135
|
-
private readonly _dispose;
|
|
136
|
-
constructor(id: string, baseId: string, value: unknown, dependencyMounts: (() => () => void)[], effects: BunjaEffectCallback[], recipe: BunjaInstanceRecipe, _dispose: () => void);
|
|
137
|
-
dispose(): void;
|
|
138
|
-
add(): void;
|
|
139
|
-
}
|
|
140
|
-
declare class ScopeInstance extends RefCounter {
|
|
141
|
-
readonly value: unknown;
|
|
142
|
-
readonly dispose: () => void;
|
|
143
|
-
private static counter;
|
|
144
|
-
readonly id: string;
|
|
145
|
-
constructor(value: unknown, dispose: () => void);
|
|
146
|
-
}
|
|
147
|
-
interface BunjaDevtoolsGlobalHook {
|
|
148
|
-
bunjas: Record<string, Bunja<any, any>>;
|
|
149
|
-
scopes: Record<string, Scope<any>>;
|
|
150
|
-
listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
|
|
151
|
-
emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
|
|
152
|
-
on<T extends BunjaDevtoolsEventType>(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void;
|
|
153
|
-
}
|
|
154
|
-
interface BunjaDevtoolsEvent {
|
|
155
|
-
bunjaCreated: {
|
|
156
|
-
bunjaId: string;
|
|
157
|
-
};
|
|
158
|
-
scopeCreated: {
|
|
159
|
-
scopeId: string;
|
|
160
|
-
};
|
|
161
|
-
storeCreated: {
|
|
162
|
-
storeId: string;
|
|
163
|
-
};
|
|
164
|
-
storeDisposed: {
|
|
165
|
-
storeId: string;
|
|
166
|
-
};
|
|
167
|
-
getCalled: {
|
|
168
|
-
storeId: string;
|
|
169
|
-
bunjaInstanceId: string;
|
|
170
|
-
};
|
|
171
|
-
bunjaInstanceMounted: {
|
|
172
|
-
storeId: string;
|
|
173
|
-
bunjaInstanceId: string;
|
|
174
|
-
};
|
|
175
|
-
bunjaInstanceUnmounted: {
|
|
176
|
-
storeId: string;
|
|
177
|
-
bunjaInstanceId: string;
|
|
178
|
-
};
|
|
179
|
-
scopeInstanceMounted: {
|
|
180
|
-
storeId: string;
|
|
181
|
-
scope: Scope<unknown>;
|
|
182
|
-
key: unknown;
|
|
183
|
-
};
|
|
184
|
-
scopeInstanceUnmounted: {
|
|
185
|
-
storeId: string;
|
|
186
|
-
scope: Scope<unknown>;
|
|
187
|
-
key: unknown;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
type BunjaDevtoolsEventType = keyof BunjaDevtoolsEvent;
|
|
191
|
-
//#endregion
|
|
192
|
-
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 };
|
package/dist/bunja.cjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const require_bunja = require('./bunja-DJPGfe5j.cjs');
|
|
2
|
-
|
|
3
|
-
exports.Bunja = require_bunja.Bunja;
|
|
4
|
-
exports.BunjaStore = require_bunja.BunjaStore;
|
|
5
|
-
exports.Scope = require_bunja.Scope;
|
|
6
|
-
exports.bunja = require_bunja.bunja;
|
|
7
|
-
exports.createBunjaStore = require_bunja.createBunjaStore;
|
|
8
|
-
exports.createReadScopeFn = require_bunja.createReadScopeFn;
|
|
9
|
-
exports.createScope = require_bunja.createScope;
|
|
10
|
-
exports.delayUnmount = require_bunja.delayUnmount;
|
package/dist/bunja.d.cts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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-B81fiP3K.cjs";
|
|
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 };
|
package/dist/chunk-CUT6urMc.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(exports, '__toESM', {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return __toESM;
|
|
29
|
-
}
|
|
30
|
-
});
|
package/dist/react.cjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
5
|
-
const require_bunja = require('./bunja-DJPGfe5j.cjs');
|
|
6
|
-
let react = require("react");
|
|
7
|
-
react = require_chunk.__toESM(react);
|
|
8
|
-
|
|
9
|
-
//#region react.ts
|
|
10
|
-
const __DEV__ = process.env.NODE_ENV !== "production";
|
|
11
|
-
const reactUse = react.use;
|
|
12
|
-
const BunjaStoreContext = (0, react.createContext)(require_bunja.createBunjaStore());
|
|
13
|
-
function BunjaStoreProvider({ children }) {
|
|
14
|
-
const [value] = (0, react.useState)(require_bunja.createBunjaStore);
|
|
15
|
-
(0, react.useEffect)(() => () => value.dispose(), [value]);
|
|
16
|
-
return (0, react.createElement)(BunjaStoreContext.Provider, {
|
|
17
|
-
value,
|
|
18
|
-
children
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
const scopeContextMap = /* @__PURE__ */ new Map();
|
|
22
|
-
let scopeContextMapLocked = false;
|
|
23
|
-
function bindScope(scope, context) {
|
|
24
|
-
if (__DEV__ && !reactUse && scopeContextMapLocked) throw new Error("`bindScope` must be called before rendering when using React 18.");
|
|
25
|
-
scopeContextMap.set(scope, context);
|
|
26
|
-
}
|
|
27
|
-
function createScopeFromContext(context, hash) {
|
|
28
|
-
const scope = require_bunja.createScope(hash);
|
|
29
|
-
bindScope(scope, context);
|
|
30
|
-
return scope;
|
|
31
|
-
}
|
|
32
|
-
function useScopeContextValues() {
|
|
33
|
-
if (reactUse) return void 0;
|
|
34
|
-
scopeContextMapLocked = true;
|
|
35
|
-
return new Map(Array.from(scopeContextMap, ([scope, context]) => [scope, (0, react.useContext)(context)]));
|
|
36
|
-
}
|
|
37
|
-
function useBunja(bunja, scopeValuePairs) {
|
|
38
|
-
const store = (0, react.useContext)(BunjaStoreContext);
|
|
39
|
-
const scopeContextValues = useScopeContextValues();
|
|
40
|
-
const defaultReadScope = (scope) => {
|
|
41
|
-
const context = scopeContextMap.get(scope);
|
|
42
|
-
if (!context) throw new Error("Scope is not bound to a React context.");
|
|
43
|
-
if (reactUse) return reactUse(context);
|
|
44
|
-
return scopeContextValues.get(scope);
|
|
45
|
-
};
|
|
46
|
-
const readScope = scopeValuePairs ? require_bunja.createReadScopeFn(scopeValuePairs, defaultReadScope) : defaultReadScope;
|
|
47
|
-
if (__DEV__) {
|
|
48
|
-
if (store._internalState?.instantiating) throw new Error("`useBunja` cannot be called inside a bunja init function.");
|
|
49
|
-
const { value, mount, deps, bunjaInstance } = store.get(bunja, readScope);
|
|
50
|
-
(0, react.useEffect)(require_bunja.delayUnmount(mount), deps);
|
|
51
|
-
(0, react.useMemo)(() => ({
|
|
52
|
-
bunja,
|
|
53
|
-
scopeValuePairs,
|
|
54
|
-
bunjaInstance
|
|
55
|
-
}), [
|
|
56
|
-
bunja,
|
|
57
|
-
scopeValuePairs,
|
|
58
|
-
bunjaInstance
|
|
59
|
-
]);
|
|
60
|
-
return value;
|
|
61
|
-
} else {
|
|
62
|
-
const { value, mount, deps } = store.get(bunja, readScope);
|
|
63
|
-
(0, react.useEffect)(require_bunja.delayUnmount(mount), deps);
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
exports.BunjaStoreContext = BunjaStoreContext;
|
|
70
|
-
exports.BunjaStoreProvider = BunjaStoreProvider;
|
|
71
|
-
exports.bindScope = bindScope;
|
|
72
|
-
exports.createScopeFromContext = createScopeFromContext;
|
|
73
|
-
exports.scopeContextMap = scopeContextMap;
|
|
74
|
-
exports.useBunja = useBunja;
|
package/dist/react.d.cts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja-B81fiP3K.cjs";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { Context, PropsWithChildren } from "react";
|
|
4
|
-
|
|
5
|
-
//#region react.d.ts
|
|
6
|
-
declare const BunjaStoreContext: Context<BunjaStore>;
|
|
7
|
-
declare function BunjaStoreProvider({
|
|
8
|
-
children
|
|
9
|
-
}: PropsWithChildren): React.JSX.Element;
|
|
10
|
-
declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
|
|
11
|
-
declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
|
|
12
|
-
declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
|
|
13
|
-
declare function useBunja<T, Seed>(bunja: Bunja<T, Seed> | BunjaGetRef<T, Seed>, scopeValuePairs?: ScopeValuePairs): T;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
|
package/dist/solid.cjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_bunja = require('./bunja-DJPGfe5j.cjs');
|
|
3
|
-
let solid_js = require("solid-js");
|
|
4
|
-
solid_js = require_chunk.__toESM(solid_js);
|
|
5
|
-
|
|
6
|
-
//#region solid.ts
|
|
7
|
-
function access(maybeAccessor) {
|
|
8
|
-
if (typeof maybeAccessor !== "function") return maybeAccessor;
|
|
9
|
-
return maybeAccessor();
|
|
10
|
-
}
|
|
11
|
-
const BunjaStoreContext = (0, solid_js.createContext)(require_bunja.createBunjaStore({ wrapInstance: solid_js.createRoot }));
|
|
12
|
-
function BunjaStoreProvider(props) {
|
|
13
|
-
const owner = (0, solid_js.getOwner)();
|
|
14
|
-
const bunjaStore = require_bunja.createBunjaStore({ wrapInstance: (impl) => (0, solid_js.createRoot)(impl, owner) });
|
|
15
|
-
(0, solid_js.onCleanup)(() => bunjaStore.dispose());
|
|
16
|
-
return (0, solid_js.createComponent)(BunjaStoreContext.Provider, {
|
|
17
|
-
get value() {
|
|
18
|
-
return bunjaStore;
|
|
19
|
-
},
|
|
20
|
-
get children() {
|
|
21
|
-
return props.children;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
const scopeContextMap = /* @__PURE__ */ new Map();
|
|
26
|
-
function bindScope(scope, context) {
|
|
27
|
-
scopeContextMap.set(scope, context);
|
|
28
|
-
}
|
|
29
|
-
function createScopeFromContext(context, hash) {
|
|
30
|
-
const scope = require_bunja.createScope(hash);
|
|
31
|
-
bindScope(scope, context);
|
|
32
|
-
return scope;
|
|
33
|
-
}
|
|
34
|
-
function useBunja(bunja, scopeValuePairs) {
|
|
35
|
-
const owner = (0, solid_js.getOwner)();
|
|
36
|
-
const store = (0, solid_js.useContext)(BunjaStoreContext);
|
|
37
|
-
const defaultReadScope = (scope) => {
|
|
38
|
-
const context = scopeContextMap.get(scope);
|
|
39
|
-
return access((0, solid_js.runWithOwner)(owner, () => (0, solid_js.useContext)(context)));
|
|
40
|
-
};
|
|
41
|
-
const readScope = (0, solid_js.createMemo)(() => {
|
|
42
|
-
const pairs = access(scopeValuePairs);
|
|
43
|
-
return pairs ? require_bunja.createReadScopeFn(pairs, defaultReadScope) : defaultReadScope;
|
|
44
|
-
});
|
|
45
|
-
const entry = (0, solid_js.createMemo)(() => {
|
|
46
|
-
const read = readScope();
|
|
47
|
-
const scopes = /* @__PURE__ */ new Set();
|
|
48
|
-
const result = store.get(access(bunja), (scope) => {
|
|
49
|
-
scopes.add(scope);
|
|
50
|
-
return read(scope);
|
|
51
|
-
});
|
|
52
|
-
for (const scope of scopes) read(scope);
|
|
53
|
-
return result;
|
|
54
|
-
});
|
|
55
|
-
(0, solid_js.createEffect)(() => {
|
|
56
|
-
const cleanup = entry().mount();
|
|
57
|
-
(0, solid_js.onCleanup)(() => setTimeout(cleanup));
|
|
58
|
-
});
|
|
59
|
-
return () => entry().value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
exports.BunjaStoreContext = BunjaStoreContext;
|
|
64
|
-
exports.BunjaStoreProvider = BunjaStoreProvider;
|
|
65
|
-
exports.bindScope = bindScope;
|
|
66
|
-
exports.createScopeFromContext = createScopeFromContext;
|
|
67
|
-
exports.scopeContextMap = scopeContextMap;
|
|
68
|
-
exports.useBunja = useBunja;
|
package/dist/solid.d.cts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja-B81fiP3K.cjs";
|
|
2
|
-
import { Accessor, Context, JSX, ParentProps } from "solid-js";
|
|
3
|
-
|
|
4
|
-
//#region solid.d.ts
|
|
5
|
-
type MaybeAccessor<T> = T | Accessor<T>;
|
|
6
|
-
type AccessedValue<T> = T extends Accessor<infer U> ? U : T;
|
|
7
|
-
declare const BunjaStoreContext: Context<BunjaStore>;
|
|
8
|
-
declare function BunjaStoreProvider(props: ParentProps): JSX.Element;
|
|
9
|
-
declare const scopeContextMap: Map<Scope<unknown>, Context<MaybeAccessor<unknown>>>;
|
|
10
|
-
declare function bindScope<T>(scope: Scope<T>, context: Context<MaybeAccessor<T>>): void;
|
|
11
|
-
declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<AccessedValue<T>>): Scope<AccessedValue<T>>;
|
|
12
|
-
declare function useBunja<T>(bunja: MaybeAccessor<Bunja<T, any> | BunjaGetRef<T, any>>, scopeValuePairs?: MaybeAccessor<ScopeValuePairs>): Accessor<T>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
|
package/react.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type Context,
|
|
5
|
-
createContext,
|
|
6
|
-
createElement,
|
|
7
|
-
type PropsWithChildren,
|
|
8
|
-
useContext,
|
|
9
|
-
useEffect,
|
|
10
|
-
useMemo,
|
|
11
|
-
useState,
|
|
12
|
-
} from "react";
|
|
13
|
-
import {
|
|
14
|
-
type Bunja,
|
|
15
|
-
type BunjaGetRef,
|
|
16
|
-
type BunjaStore,
|
|
17
|
-
createBunjaStore,
|
|
18
|
-
createReadScopeFn,
|
|
19
|
-
createScope,
|
|
20
|
-
delayUnmount,
|
|
21
|
-
type HashFn,
|
|
22
|
-
type ReadScope,
|
|
23
|
-
type Scope,
|
|
24
|
-
type ScopeValuePairs,
|
|
25
|
-
} from "./bunja.ts";
|
|
26
|
-
import * as React from "react";
|
|
27
|
-
|
|
28
|
-
// @ts-ignore dev
|
|
29
|
-
// deno-lint-ignore no-process-global
|
|
30
|
-
const __DEV__ = process.env.NODE_ENV !== "production";
|
|
31
|
-
const reactUse = (React as unknown as {
|
|
32
|
-
use?: <T>(usable: Context<T>) => T;
|
|
33
|
-
}).use;
|
|
34
|
-
|
|
35
|
-
export const BunjaStoreContext: Context<BunjaStore> = createContext(
|
|
36
|
-
createBunjaStore(),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
export function BunjaStoreProvider(
|
|
40
|
-
{ children }: PropsWithChildren,
|
|
41
|
-
): React.JSX.Element {
|
|
42
|
-
const [value] = useState(createBunjaStore);
|
|
43
|
-
useEffect(() => () => value.dispose(), [value]);
|
|
44
|
-
return createElement(BunjaStoreContext.Provider, { value, children });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const scopeContextMap: Map<Scope<unknown>, Context<unknown>> = new Map();
|
|
48
|
-
let scopeContextMapLocked = false;
|
|
49
|
-
export function bindScope<T>(scope: Scope<T>, context: Context<T>): void {
|
|
50
|
-
if (__DEV__ && !reactUse && scopeContextMapLocked) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
"`bindScope` must be called before rendering when using React 18.",
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
scopeContextMap.set(scope as Scope<unknown>, context as Context<unknown>);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function createScopeFromContext<T>(
|
|
59
|
-
context: Context<T>,
|
|
60
|
-
hash?: HashFn<T>,
|
|
61
|
-
): Scope<T> {
|
|
62
|
-
const scope = createScope<T>(hash);
|
|
63
|
-
bindScope(scope, context);
|
|
64
|
-
return scope;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function useScopeContextValues(): Map<Scope<unknown>, unknown> | undefined {
|
|
68
|
-
if (reactUse) return undefined;
|
|
69
|
-
scopeContextMapLocked = true;
|
|
70
|
-
return new Map(
|
|
71
|
-
Array.from(scopeContextMap, ([scope, context]) => [
|
|
72
|
-
scope,
|
|
73
|
-
useContext(context),
|
|
74
|
-
]),
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function useBunja<T, Seed>(
|
|
79
|
-
bunja: Bunja<T, Seed> | BunjaGetRef<T, Seed>,
|
|
80
|
-
scopeValuePairs?: ScopeValuePairs,
|
|
81
|
-
): T {
|
|
82
|
-
const store = useContext(BunjaStoreContext);
|
|
83
|
-
const scopeContextValues = useScopeContextValues();
|
|
84
|
-
const defaultReadScope: ReadScope = <T>(scope: Scope<T>) => {
|
|
85
|
-
const context = scopeContextMap.get(scope as Scope<unknown>) as
|
|
86
|
-
| Context<T>
|
|
87
|
-
| undefined;
|
|
88
|
-
if (!context) throw new Error("Scope is not bound to a React context.");
|
|
89
|
-
if (reactUse) return reactUse(context);
|
|
90
|
-
return scopeContextValues!.get(scope as Scope<unknown>) as T;
|
|
91
|
-
};
|
|
92
|
-
const readScope = scopeValuePairs
|
|
93
|
-
? createReadScopeFn(scopeValuePairs, defaultReadScope)
|
|
94
|
-
: defaultReadScope;
|
|
95
|
-
if (__DEV__) {
|
|
96
|
-
if (store._internalState?.instantiating) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
"`useBunja` cannot be called inside a bunja init function.",
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
const { value, mount, deps, bunjaInstance } = store.get(bunja, readScope);
|
|
102
|
-
useEffect(delayUnmount(mount), deps);
|
|
103
|
-
useMemo(
|
|
104
|
-
() => ({ bunja, scopeValuePairs, bunjaInstance }),
|
|
105
|
-
[bunja, scopeValuePairs, bunjaInstance],
|
|
106
|
-
);
|
|
107
|
-
return value;
|
|
108
|
-
} else {
|
|
109
|
-
const { value, mount, deps } = store.get(bunja, readScope);
|
|
110
|
-
useEffect(delayUnmount(mount), deps);
|
|
111
|
-
return value;
|
|
112
|
-
}
|
|
113
|
-
}
|
package/solid.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Accessor,
|
|
3
|
-
type Context,
|
|
4
|
-
createComponent,
|
|
5
|
-
createContext,
|
|
6
|
-
createEffect,
|
|
7
|
-
createMemo,
|
|
8
|
-
createRoot,
|
|
9
|
-
getOwner,
|
|
10
|
-
type JSX,
|
|
11
|
-
onCleanup,
|
|
12
|
-
type ParentProps,
|
|
13
|
-
runWithOwner,
|
|
14
|
-
useContext,
|
|
15
|
-
} from "solid-js";
|
|
16
|
-
import {
|
|
17
|
-
type Bunja,
|
|
18
|
-
type BunjaGetRef,
|
|
19
|
-
type BunjaStore,
|
|
20
|
-
createBunjaStore,
|
|
21
|
-
createReadScopeFn,
|
|
22
|
-
createScope,
|
|
23
|
-
type HashFn,
|
|
24
|
-
type ReadScope,
|
|
25
|
-
type Scope,
|
|
26
|
-
type ScopeValuePairs,
|
|
27
|
-
} from "./bunja.ts";
|
|
28
|
-
|
|
29
|
-
type MaybeAccessor<T> = T | Accessor<T>;
|
|
30
|
-
type AccessedValue<T> = T extends Accessor<infer U> ? U : T;
|
|
31
|
-
function access<T>(maybeAccessor: MaybeAccessor<T>): T {
|
|
32
|
-
if (typeof maybeAccessor !== "function") return maybeAccessor;
|
|
33
|
-
return (maybeAccessor as Accessor<T>)();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const BunjaStoreContext: Context<BunjaStore> = createContext(
|
|
37
|
-
createBunjaStore({ wrapInstance: createRoot }),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
export function BunjaStoreProvider(
|
|
41
|
-
props: ParentProps,
|
|
42
|
-
): JSX.Element {
|
|
43
|
-
const owner = getOwner();
|
|
44
|
-
const bunjaStore = createBunjaStore({
|
|
45
|
-
wrapInstance: (impl) => createRoot(impl, owner),
|
|
46
|
-
});
|
|
47
|
-
onCleanup(() => bunjaStore.dispose());
|
|
48
|
-
return createComponent(BunjaStoreContext.Provider, {
|
|
49
|
-
get value() {
|
|
50
|
-
return bunjaStore;
|
|
51
|
-
},
|
|
52
|
-
get children() {
|
|
53
|
-
return props.children;
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const scopeContextMap: Map<
|
|
59
|
-
Scope<unknown>,
|
|
60
|
-
Context<MaybeAccessor<unknown>>
|
|
61
|
-
> = new Map();
|
|
62
|
-
export function bindScope<T>(
|
|
63
|
-
scope: Scope<T>,
|
|
64
|
-
context: Context<MaybeAccessor<T>>,
|
|
65
|
-
): void {
|
|
66
|
-
scopeContextMap.set(
|
|
67
|
-
scope as Scope<unknown>,
|
|
68
|
-
context as Context<MaybeAccessor<unknown>>,
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function createScopeFromContext<T>(
|
|
73
|
-
context: Context<T>,
|
|
74
|
-
hash?: HashFn<AccessedValue<T>>,
|
|
75
|
-
): Scope<AccessedValue<T>> {
|
|
76
|
-
const scope = createScope<AccessedValue<T>>(hash);
|
|
77
|
-
bindScope(scope, context as Context<MaybeAccessor<AccessedValue<T>>>);
|
|
78
|
-
return scope;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function useBunja<T>(
|
|
82
|
-
bunja: MaybeAccessor<Bunja<T, any> | BunjaGetRef<T, any>>,
|
|
83
|
-
scopeValuePairs?: MaybeAccessor<ScopeValuePairs>,
|
|
84
|
-
): Accessor<T> {
|
|
85
|
-
const owner = getOwner();
|
|
86
|
-
const store = useContext(BunjaStoreContext);
|
|
87
|
-
const defaultReadScope: ReadScope = <T>(scope: Scope<T>) => {
|
|
88
|
-
const context = scopeContextMap.get(scope as Scope<unknown>)!;
|
|
89
|
-
// Restore the consumer context without untracking its accessor.
|
|
90
|
-
return access(runWithOwner(owner, () => useContext(context))) as T;
|
|
91
|
-
};
|
|
92
|
-
const readScope = createMemo(() => {
|
|
93
|
-
const pairs = access(scopeValuePairs);
|
|
94
|
-
return pairs
|
|
95
|
-
? createReadScopeFn(pairs, defaultReadScope)
|
|
96
|
-
: defaultReadScope;
|
|
97
|
-
});
|
|
98
|
-
const entry = createMemo(() => {
|
|
99
|
-
const read = readScope();
|
|
100
|
-
const scopes = new Set<Scope<unknown>>();
|
|
101
|
-
const result = store.get(access(bunja), (scope) => {
|
|
102
|
-
scopes.add(scope as Scope<unknown>);
|
|
103
|
-
return read(scope);
|
|
104
|
-
});
|
|
105
|
-
// Initial scope discovery can run inside the instance's untracked root.
|
|
106
|
-
// Subscribe here as well, including scopes reached through dependencies.
|
|
107
|
-
for (const scope of scopes) read(scope);
|
|
108
|
-
return result;
|
|
109
|
-
});
|
|
110
|
-
createEffect(() => {
|
|
111
|
-
const cleanup = entry().mount();
|
|
112
|
-
onCleanup(() => setTimeout(cleanup));
|
|
113
|
-
});
|
|
114
|
-
return () => entry().value;
|
|
115
|
-
}
|