bunja 2.0.0-alpha.3 → 2.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/deno.json +1 -1
- package/deno.lock +267 -212
- package/dist/bunja-Bj2Zho1e.d.ts +66 -0
- package/dist/{bunja-DGNjfjPa.js → bunja-DsftUL38.js} +10 -11
- package/dist/bunja-WQqJyoyx.d.cts +66 -0
- package/dist/{bunja-RF4EuS_C.cjs → bunja-i3L_5FKm.cjs} +20 -16
- package/dist/bunja.cjs +7 -8
- package/dist/bunja.d.cts +2 -64
- package/dist/bunja.d.ts +2 -64
- package/dist/bunja.js +1 -1
- package/dist/react.cjs +21 -20
- package/dist/react.d.cts +16 -10
- package/dist/react.d.ts +16 -10
- package/dist/react.js +5 -3
- package/package.json +2 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region bunja.d.ts
|
|
2
|
+
interface BunjaFn {
|
|
3
|
+
<T>(init: () => T): Bunja<T>;
|
|
4
|
+
use: BunjaUseFn;
|
|
5
|
+
effect: BunjaEffectFn;
|
|
6
|
+
}
|
|
7
|
+
declare const bunja: BunjaFn;
|
|
8
|
+
type BunjaUseFn = <T>(dep: Dep<T>) => T;
|
|
9
|
+
type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
|
|
10
|
+
type BunjaEffectCallback = () => (() => void) | void;
|
|
11
|
+
declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
|
|
12
|
+
declare function createBunjaStore(): BunjaStore;
|
|
13
|
+
type Dep<T> = Bunja<T> | Scope<T>;
|
|
14
|
+
declare class BunjaStore {
|
|
15
|
+
#private;
|
|
16
|
+
dispose(): void;
|
|
17
|
+
get<T>(bunja: Bunja<T>, readScope: ReadScope): BunjaStoreGetResult<T>;
|
|
18
|
+
}
|
|
19
|
+
type ReadScope = <T>(scope: Scope<T>) => T;
|
|
20
|
+
interface BunjaStoreGetResult<T> {
|
|
21
|
+
value: T;
|
|
22
|
+
mount: () => () => void;
|
|
23
|
+
deps: unknown[];
|
|
24
|
+
}
|
|
25
|
+
declare class Bunja<T> {
|
|
26
|
+
#private;
|
|
27
|
+
init: () => T;
|
|
28
|
+
private static counter;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
debugLabel: string;
|
|
31
|
+
constructor(init: () => T);
|
|
32
|
+
get baked(): boolean;
|
|
33
|
+
get parents(): Bunja<unknown>[];
|
|
34
|
+
get relatedBunjas(): Bunja<unknown>[];
|
|
35
|
+
get relatedScopes(): Scope<unknown>[];
|
|
36
|
+
addParent(bunja: Bunja<unknown>): void;
|
|
37
|
+
addScope(scope: Scope<unknown>): void;
|
|
38
|
+
bake(): void;
|
|
39
|
+
calcInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>): string;
|
|
40
|
+
toString(): string;
|
|
41
|
+
}
|
|
42
|
+
declare class Scope<T> {
|
|
43
|
+
readonly hash: HashFn<T>;
|
|
44
|
+
private static counter;
|
|
45
|
+
readonly id: string;
|
|
46
|
+
debugLabel: string;
|
|
47
|
+
constructor(hash?: HashFn<T>);
|
|
48
|
+
private static identity;
|
|
49
|
+
toString(): string;
|
|
50
|
+
}
|
|
51
|
+
type HashFn<T> = (value: T) => unknown;
|
|
52
|
+
declare abstract class RefCounter {
|
|
53
|
+
#private;
|
|
54
|
+
abstract dispose(): void;
|
|
55
|
+
add(): void;
|
|
56
|
+
sub(): void;
|
|
57
|
+
}
|
|
58
|
+
declare class ScopeInstance extends RefCounter {
|
|
59
|
+
readonly value: unknown;
|
|
60
|
+
readonly dispose: () => void;
|
|
61
|
+
private static counter;
|
|
62
|
+
readonly id: string;
|
|
63
|
+
constructor(value: unknown, dispose: () => void);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { Bunja, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, Dep, HashFn, ReadScope, Scope, bunja, createBunjaStore, createScope };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region bunja.ts
|
|
3
2
|
const bunja = bunjaFn;
|
|
4
3
|
function bunjaFn(init) {
|
|
@@ -20,13 +19,13 @@ function invalidEffect() {
|
|
|
20
19
|
}
|
|
21
20
|
var BunjaStore = class {
|
|
22
21
|
#bunjas = {};
|
|
23
|
-
#scopes = new Map();
|
|
22
|
+
#scopes = /* @__PURE__ */ new Map();
|
|
24
23
|
#bakingContext;
|
|
25
24
|
dispose() {
|
|
26
25
|
for (const instance of Object.values(this.#bunjas)) instance.dispose();
|
|
27
26
|
for (const instanceMap of Object.values(this.#scopes)) for (const instance of instanceMap.values()) instance.dispose();
|
|
28
27
|
this.#bunjas = {};
|
|
29
|
-
this.#scopes = new Map();
|
|
28
|
+
this.#scopes = /* @__PURE__ */ new Map();
|
|
30
29
|
}
|
|
31
30
|
get(bunja$1, readScope) {
|
|
32
31
|
const originalUse = bunjaFn.use;
|
|
@@ -55,7 +54,7 @@ var BunjaStore = class {
|
|
|
55
54
|
}
|
|
56
55
|
#getBaked(bunja$1, readScope) {
|
|
57
56
|
const scopeInstanceMap = new Map(bunja$1.relatedScopes.map((scope) => [scope, this.#getScopeInstance(scope, readScope(scope))]));
|
|
58
|
-
const bunjaInstanceMap = new Map();
|
|
57
|
+
const bunjaInstanceMap = /* @__PURE__ */ new Map();
|
|
59
58
|
bunjaFn.use = (dep) => {
|
|
60
59
|
if (dep instanceof Bunja) return bunjaInstanceMap.get(dep).value;
|
|
61
60
|
if (dep instanceof Scope) return scopeInstanceMap.get(dep).value;
|
|
@@ -70,8 +69,8 @@ var BunjaStore = class {
|
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
#getUnbaked(bunja$1, readScope) {
|
|
73
|
-
const bunjaInstanceMap = new Map();
|
|
74
|
-
const scopeInstanceMap = new Map();
|
|
72
|
+
const bunjaInstanceMap = /* @__PURE__ */ new Map();
|
|
73
|
+
const scopeInstanceMap = /* @__PURE__ */ new Map();
|
|
75
74
|
function getUse(map, addDep, getInstance) {
|
|
76
75
|
return (dep) => {
|
|
77
76
|
const d = dep;
|
|
@@ -101,7 +100,7 @@ var BunjaStore = class {
|
|
|
101
100
|
scopeInstanceMap
|
|
102
101
|
};
|
|
103
102
|
} finally {
|
|
104
|
-
this.#bakingContext =
|
|
103
|
+
this.#bakingContext = void 0;
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
#getBunjaInstance(bunja$1, scopeInstanceMap) {
|
|
@@ -131,7 +130,7 @@ var BunjaStore = class {
|
|
|
131
130
|
}
|
|
132
131
|
#getScopeInstance(scope, value) {
|
|
133
132
|
const key = scope.hash(value);
|
|
134
|
-
const instanceMap = this.#scopes.get(scope) ?? this.#scopes.set(scope, new Map()).get(scope);
|
|
133
|
+
const instanceMap = this.#scopes.get(scope) ?? this.#scopes.set(scope, /* @__PURE__ */ new Map()).get(scope);
|
|
135
134
|
return instanceMap.get(key) ?? instanceMap.set(key, new ScopeInstance(value, () => instanceMap.delete(key))).get(key);
|
|
136
135
|
}
|
|
137
136
|
#createBunjaInstance(id, value, effects) {
|
|
@@ -151,8 +150,8 @@ var Bunja = class Bunja {
|
|
|
151
150
|
debugLabel = "";
|
|
152
151
|
#phase = {
|
|
153
152
|
baked: false,
|
|
154
|
-
parents: new Set(),
|
|
155
|
-
scopes: new Set()
|
|
153
|
+
parents: /* @__PURE__ */ new Set(),
|
|
154
|
+
scopes: /* @__PURE__ */ new Set()
|
|
156
155
|
};
|
|
157
156
|
constructor(init) {
|
|
158
157
|
this.init = init;
|
|
@@ -259,7 +258,7 @@ var ScopeInstance = class ScopeInstance extends RefCounter {
|
|
|
259
258
|
}
|
|
260
259
|
};
|
|
261
260
|
function toposort(nodes) {
|
|
262
|
-
const visited = new Set();
|
|
261
|
+
const visited = /* @__PURE__ */ new Set();
|
|
263
262
|
const result = [];
|
|
264
263
|
function visit(current) {
|
|
265
264
|
if (visited.has(current)) return;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region bunja.d.ts
|
|
2
|
+
interface BunjaFn {
|
|
3
|
+
<T>(init: () => T): Bunja<T>;
|
|
4
|
+
use: BunjaUseFn;
|
|
5
|
+
effect: BunjaEffectFn;
|
|
6
|
+
}
|
|
7
|
+
declare const bunja: BunjaFn;
|
|
8
|
+
type BunjaUseFn = <T>(dep: Dep<T>) => T;
|
|
9
|
+
type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
|
|
10
|
+
type BunjaEffectCallback = () => (() => void) | void;
|
|
11
|
+
declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
|
|
12
|
+
declare function createBunjaStore(): BunjaStore;
|
|
13
|
+
type Dep<T> = Bunja<T> | Scope<T>;
|
|
14
|
+
declare class BunjaStore {
|
|
15
|
+
#private;
|
|
16
|
+
dispose(): void;
|
|
17
|
+
get<T>(bunja: Bunja<T>, readScope: ReadScope): BunjaStoreGetResult<T>;
|
|
18
|
+
}
|
|
19
|
+
type ReadScope = <T>(scope: Scope<T>) => T;
|
|
20
|
+
interface BunjaStoreGetResult<T> {
|
|
21
|
+
value: T;
|
|
22
|
+
mount: () => () => void;
|
|
23
|
+
deps: unknown[];
|
|
24
|
+
}
|
|
25
|
+
declare class Bunja<T> {
|
|
26
|
+
#private;
|
|
27
|
+
init: () => T;
|
|
28
|
+
private static counter;
|
|
29
|
+
readonly id: string;
|
|
30
|
+
debugLabel: string;
|
|
31
|
+
constructor(init: () => T);
|
|
32
|
+
get baked(): boolean;
|
|
33
|
+
get parents(): Bunja<unknown>[];
|
|
34
|
+
get relatedBunjas(): Bunja<unknown>[];
|
|
35
|
+
get relatedScopes(): Scope<unknown>[];
|
|
36
|
+
addParent(bunja: Bunja<unknown>): void;
|
|
37
|
+
addScope(scope: Scope<unknown>): void;
|
|
38
|
+
bake(): void;
|
|
39
|
+
calcInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>): string;
|
|
40
|
+
toString(): string;
|
|
41
|
+
}
|
|
42
|
+
declare class Scope<T> {
|
|
43
|
+
readonly hash: HashFn<T>;
|
|
44
|
+
private static counter;
|
|
45
|
+
readonly id: string;
|
|
46
|
+
debugLabel: string;
|
|
47
|
+
constructor(hash?: HashFn<T>);
|
|
48
|
+
private static identity;
|
|
49
|
+
toString(): string;
|
|
50
|
+
}
|
|
51
|
+
type HashFn<T> = (value: T) => unknown;
|
|
52
|
+
declare abstract class RefCounter {
|
|
53
|
+
#private;
|
|
54
|
+
abstract dispose(): void;
|
|
55
|
+
add(): void;
|
|
56
|
+
sub(): void;
|
|
57
|
+
}
|
|
58
|
+
declare class ScopeInstance extends RefCounter {
|
|
59
|
+
readonly value: unknown;
|
|
60
|
+
readonly dispose: () => void;
|
|
61
|
+
private static counter;
|
|
62
|
+
readonly id: string;
|
|
63
|
+
constructor(value: unknown, dispose: () => void);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { Bunja, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, Dep, HashFn, ReadScope, Scope, bunja, createBunjaStore, createScope };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
|
|
3
2
|
//#region bunja.ts
|
|
4
3
|
const bunja = bunjaFn;
|
|
@@ -21,13 +20,13 @@ function invalidEffect() {
|
|
|
21
20
|
}
|
|
22
21
|
var BunjaStore = class {
|
|
23
22
|
#bunjas = {};
|
|
24
|
-
#scopes = new Map();
|
|
23
|
+
#scopes = /* @__PURE__ */ new Map();
|
|
25
24
|
#bakingContext;
|
|
26
25
|
dispose() {
|
|
27
26
|
for (const instance of Object.values(this.#bunjas)) instance.dispose();
|
|
28
27
|
for (const instanceMap of Object.values(this.#scopes)) for (const instance of instanceMap.values()) instance.dispose();
|
|
29
28
|
this.#bunjas = {};
|
|
30
|
-
this.#scopes = new Map();
|
|
29
|
+
this.#scopes = /* @__PURE__ */ new Map();
|
|
31
30
|
}
|
|
32
31
|
get(bunja$1, readScope) {
|
|
33
32
|
const originalUse = bunjaFn.use;
|
|
@@ -56,7 +55,7 @@ var BunjaStore = class {
|
|
|
56
55
|
}
|
|
57
56
|
#getBaked(bunja$1, readScope) {
|
|
58
57
|
const scopeInstanceMap = new Map(bunja$1.relatedScopes.map((scope) => [scope, this.#getScopeInstance(scope, readScope(scope))]));
|
|
59
|
-
const bunjaInstanceMap = new Map();
|
|
58
|
+
const bunjaInstanceMap = /* @__PURE__ */ new Map();
|
|
60
59
|
bunjaFn.use = (dep) => {
|
|
61
60
|
if (dep instanceof Bunja) return bunjaInstanceMap.get(dep).value;
|
|
62
61
|
if (dep instanceof Scope) return scopeInstanceMap.get(dep).value;
|
|
@@ -71,8 +70,8 @@ var BunjaStore = class {
|
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
72
|
#getUnbaked(bunja$1, readScope) {
|
|
74
|
-
const bunjaInstanceMap = new Map();
|
|
75
|
-
const scopeInstanceMap = new Map();
|
|
73
|
+
const bunjaInstanceMap = /* @__PURE__ */ new Map();
|
|
74
|
+
const scopeInstanceMap = /* @__PURE__ */ new Map();
|
|
76
75
|
function getUse(map, addDep, getInstance) {
|
|
77
76
|
return (dep) => {
|
|
78
77
|
const d = dep;
|
|
@@ -102,7 +101,7 @@ var BunjaStore = class {
|
|
|
102
101
|
scopeInstanceMap
|
|
103
102
|
};
|
|
104
103
|
} finally {
|
|
105
|
-
this.#bakingContext =
|
|
104
|
+
this.#bakingContext = void 0;
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
#getBunjaInstance(bunja$1, scopeInstanceMap) {
|
|
@@ -132,7 +131,7 @@ var BunjaStore = class {
|
|
|
132
131
|
}
|
|
133
132
|
#getScopeInstance(scope, value) {
|
|
134
133
|
const key = scope.hash(value);
|
|
135
|
-
const instanceMap = this.#scopes.get(scope) ?? this.#scopes.set(scope, new Map()).get(scope);
|
|
134
|
+
const instanceMap = this.#scopes.get(scope) ?? this.#scopes.set(scope, /* @__PURE__ */ new Map()).get(scope);
|
|
136
135
|
return instanceMap.get(key) ?? instanceMap.set(key, new ScopeInstance(value, () => instanceMap.delete(key))).get(key);
|
|
137
136
|
}
|
|
138
137
|
#createBunjaInstance(id, value, effects) {
|
|
@@ -152,8 +151,8 @@ var Bunja = class Bunja {
|
|
|
152
151
|
debugLabel = "";
|
|
153
152
|
#phase = {
|
|
154
153
|
baked: false,
|
|
155
|
-
parents: new Set(),
|
|
156
|
-
scopes: new Set()
|
|
154
|
+
parents: /* @__PURE__ */ new Set(),
|
|
155
|
+
scopes: /* @__PURE__ */ new Set()
|
|
157
156
|
};
|
|
158
157
|
constructor(init) {
|
|
159
158
|
this.init = init;
|
|
@@ -260,7 +259,7 @@ var ScopeInstance = class ScopeInstance extends RefCounter {
|
|
|
260
259
|
}
|
|
261
260
|
};
|
|
262
261
|
function toposort(nodes) {
|
|
263
|
-
const visited = new Set();
|
|
262
|
+
const visited = /* @__PURE__ */ new Set();
|
|
264
263
|
const result = [];
|
|
265
264
|
function visit(current) {
|
|
266
265
|
if (visited.has(current)) return;
|
|
@@ -278,27 +277,32 @@ Object.defineProperty(exports, 'Bunja', {
|
|
|
278
277
|
get: function () {
|
|
279
278
|
return Bunja;
|
|
280
279
|
}
|
|
281
|
-
});
|
|
280
|
+
});
|
|
281
|
+
Object.defineProperty(exports, 'BunjaStore', {
|
|
282
282
|
enumerable: true,
|
|
283
283
|
get: function () {
|
|
284
284
|
return BunjaStore;
|
|
285
285
|
}
|
|
286
|
-
});
|
|
286
|
+
});
|
|
287
|
+
Object.defineProperty(exports, 'Scope', {
|
|
287
288
|
enumerable: true,
|
|
288
289
|
get: function () {
|
|
289
290
|
return Scope;
|
|
290
291
|
}
|
|
291
|
-
});
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(exports, 'bunja', {
|
|
292
294
|
enumerable: true,
|
|
293
295
|
get: function () {
|
|
294
296
|
return bunja;
|
|
295
297
|
}
|
|
296
|
-
});
|
|
298
|
+
});
|
|
299
|
+
Object.defineProperty(exports, 'createBunjaStore', {
|
|
297
300
|
enumerable: true,
|
|
298
301
|
get: function () {
|
|
299
302
|
return createBunjaStore;
|
|
300
303
|
}
|
|
301
|
-
});
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(exports, 'createScope', {
|
|
302
306
|
enumerable: true,
|
|
303
307
|
get: function () {
|
|
304
308
|
return createScope;
|
package/dist/bunja.cjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const require_bunja = require('./bunja-RF4EuS_C.cjs');
|
|
1
|
+
const require_bunja = require('./bunja-i3L_5FKm.cjs');
|
|
3
2
|
|
|
4
|
-
exports.Bunja = require_bunja.Bunja
|
|
5
|
-
exports.BunjaStore = require_bunja.BunjaStore
|
|
6
|
-
exports.Scope = require_bunja.Scope
|
|
7
|
-
exports.bunja = require_bunja.bunja
|
|
8
|
-
exports.createBunjaStore = require_bunja.createBunjaStore
|
|
9
|
-
exports.createScope = require_bunja.createScope
|
|
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.createScope = require_bunja.createScope;
|
package/dist/bunja.d.cts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
use: BunjaUseFn;
|
|
4
|
-
effect: BunjaEffectFn;
|
|
5
|
-
}
|
|
6
|
-
export declare const bunja: BunjaFn;
|
|
7
|
-
export type BunjaUseFn = <T>(dep: Dep<T>) => T;
|
|
8
|
-
export type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
|
|
9
|
-
export type BunjaEffectCallback = () => (() => void) | void;
|
|
10
|
-
export declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
|
|
11
|
-
export declare function createBunjaStore(): BunjaStore;
|
|
12
|
-
export type Dep<T> = Bunja<T> | Scope<T>;
|
|
13
|
-
export declare class BunjaStore {
|
|
14
|
-
#private;
|
|
15
|
-
dispose(): void;
|
|
16
|
-
get<T>(bunja: Bunja<T>, readScope: ReadScope): BunjaStoreGetResult<T>;
|
|
17
|
-
}
|
|
18
|
-
export type ReadScope = <T>(scope: Scope<T>) => T;
|
|
19
|
-
export interface BunjaStoreGetResult<T> {
|
|
20
|
-
value: T;
|
|
21
|
-
mount: () => () => void;
|
|
22
|
-
deps: unknown[];
|
|
23
|
-
}
|
|
24
|
-
export declare class Bunja<T> {
|
|
25
|
-
#private;
|
|
26
|
-
init: () => T;
|
|
27
|
-
private static counter;
|
|
28
|
-
readonly id: string;
|
|
29
|
-
debugLabel: string;
|
|
30
|
-
constructor(init: () => T);
|
|
31
|
-
get baked(): boolean;
|
|
32
|
-
get parents(): Bunja<unknown>[];
|
|
33
|
-
get relatedBunjas(): Bunja<unknown>[];
|
|
34
|
-
get relatedScopes(): Scope<unknown>[];
|
|
35
|
-
addParent(bunja: Bunja<unknown>): void;
|
|
36
|
-
addScope(scope: Scope<unknown>): void;
|
|
37
|
-
bake(): void;
|
|
38
|
-
calcInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>): string;
|
|
39
|
-
toString(): string;
|
|
40
|
-
}
|
|
41
|
-
export declare class Scope<T> {
|
|
42
|
-
readonly hash: HashFn<T>;
|
|
43
|
-
private static counter;
|
|
44
|
-
readonly id: string;
|
|
45
|
-
debugLabel: string;
|
|
46
|
-
constructor(hash?: HashFn<T>);
|
|
47
|
-
private static identity;
|
|
48
|
-
toString(): string;
|
|
49
|
-
}
|
|
50
|
-
export type HashFn<T> = (value: T) => unknown;
|
|
51
|
-
declare abstract class RefCounter {
|
|
52
|
-
#private;
|
|
53
|
-
abstract dispose(): void;
|
|
54
|
-
add(): void;
|
|
55
|
-
sub(): void;
|
|
56
|
-
}
|
|
57
|
-
declare class ScopeInstance extends RefCounter {
|
|
58
|
-
readonly value: unknown;
|
|
59
|
-
readonly dispose: () => void;
|
|
60
|
-
private static counter;
|
|
61
|
-
readonly id: string;
|
|
62
|
-
constructor(value: unknown, dispose: () => void);
|
|
63
|
-
}
|
|
64
|
-
export {};
|
|
1
|
+
import { Bunja, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, Dep, HashFn, ReadScope, Scope, bunja, createBunjaStore, createScope } from "./bunja-WQqJyoyx.cjs";
|
|
2
|
+
export { Bunja, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, Dep, HashFn, ReadScope, Scope, bunja, createBunjaStore, createScope };
|
package/dist/bunja.d.ts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
use: BunjaUseFn;
|
|
4
|
-
effect: BunjaEffectFn;
|
|
5
|
-
}
|
|
6
|
-
export declare const bunja: BunjaFn;
|
|
7
|
-
export type BunjaUseFn = <T>(dep: Dep<T>) => T;
|
|
8
|
-
export type BunjaEffectFn = (callback: BunjaEffectCallback) => void;
|
|
9
|
-
export type BunjaEffectCallback = () => (() => void) | void;
|
|
10
|
-
export declare function createScope<T>(hash?: HashFn<T>): Scope<T>;
|
|
11
|
-
export declare function createBunjaStore(): BunjaStore;
|
|
12
|
-
export type Dep<T> = Bunja<T> | Scope<T>;
|
|
13
|
-
export declare class BunjaStore {
|
|
14
|
-
#private;
|
|
15
|
-
dispose(): void;
|
|
16
|
-
get<T>(bunja: Bunja<T>, readScope: ReadScope): BunjaStoreGetResult<T>;
|
|
17
|
-
}
|
|
18
|
-
export type ReadScope = <T>(scope: Scope<T>) => T;
|
|
19
|
-
export interface BunjaStoreGetResult<T> {
|
|
20
|
-
value: T;
|
|
21
|
-
mount: () => () => void;
|
|
22
|
-
deps: unknown[];
|
|
23
|
-
}
|
|
24
|
-
export declare class Bunja<T> {
|
|
25
|
-
#private;
|
|
26
|
-
init: () => T;
|
|
27
|
-
private static counter;
|
|
28
|
-
readonly id: string;
|
|
29
|
-
debugLabel: string;
|
|
30
|
-
constructor(init: () => T);
|
|
31
|
-
get baked(): boolean;
|
|
32
|
-
get parents(): Bunja<unknown>[];
|
|
33
|
-
get relatedBunjas(): Bunja<unknown>[];
|
|
34
|
-
get relatedScopes(): Scope<unknown>[];
|
|
35
|
-
addParent(bunja: Bunja<unknown>): void;
|
|
36
|
-
addScope(scope: Scope<unknown>): void;
|
|
37
|
-
bake(): void;
|
|
38
|
-
calcInstanceId(scopeInstanceMap: Map<Scope<unknown>, ScopeInstance>): string;
|
|
39
|
-
toString(): string;
|
|
40
|
-
}
|
|
41
|
-
export declare class Scope<T> {
|
|
42
|
-
readonly hash: HashFn<T>;
|
|
43
|
-
private static counter;
|
|
44
|
-
readonly id: string;
|
|
45
|
-
debugLabel: string;
|
|
46
|
-
constructor(hash?: HashFn<T>);
|
|
47
|
-
private static identity;
|
|
48
|
-
toString(): string;
|
|
49
|
-
}
|
|
50
|
-
export type HashFn<T> = (value: T) => unknown;
|
|
51
|
-
declare abstract class RefCounter {
|
|
52
|
-
#private;
|
|
53
|
-
abstract dispose(): void;
|
|
54
|
-
add(): void;
|
|
55
|
-
sub(): void;
|
|
56
|
-
}
|
|
57
|
-
declare class ScopeInstance extends RefCounter {
|
|
58
|
-
readonly value: unknown;
|
|
59
|
-
readonly dispose: () => void;
|
|
60
|
-
private static counter;
|
|
61
|
-
readonly id: string;
|
|
62
|
-
constructor(value: unknown, dispose: () => void);
|
|
63
|
-
}
|
|
64
|
-
export {};
|
|
1
|
+
import { Bunja, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, Dep, HashFn, ReadScope, Scope, bunja, createBunjaStore, createScope } from "./bunja-Bj2Zho1e.js";
|
|
2
|
+
export { Bunja, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, Dep, HashFn, ReadScope, Scope, bunja, createBunjaStore, createScope };
|
package/dist/bunja.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Bunja, BunjaStore, Scope, bunja, createBunjaStore, createScope } from "./bunja-
|
|
1
|
+
import { Bunja, BunjaStore, Scope, bunja, createBunjaStore, createScope } from "./bunja-DsftUL38.js";
|
|
2
2
|
|
|
3
3
|
export { Bunja, BunjaStore, Scope, bunja, createBunjaStore, createScope };
|
package/dist/react.cjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
2
4
|
//#region rolldown:runtime
|
|
3
5
|
var __create = Object.create;
|
|
4
6
|
var __defProp = Object.defineProperty;
|
|
@@ -22,21 +24,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
24
|
}) : target, mod));
|
|
23
25
|
|
|
24
26
|
//#endregion
|
|
25
|
-
const require_bunja = require('./bunja-
|
|
26
|
-
const
|
|
27
|
+
const require_bunja = require('./bunja-i3L_5FKm.cjs');
|
|
28
|
+
const react = __toESM(require("react"));
|
|
27
29
|
|
|
28
30
|
//#region react.ts
|
|
29
|
-
|
|
30
|
-
const BunjaStoreContext = createContext(require_bunja.createBunjaStore());
|
|
31
|
+
const BunjaStoreContext = (0, react.createContext)(require_bunja.createBunjaStore());
|
|
31
32
|
function BunjaStoreProvider({ children }) {
|
|
32
|
-
const [value] = useState(require_bunja.createBunjaStore);
|
|
33
|
-
useEffect(() => () => value.dispose(), [value]);
|
|
34
|
-
return createElement(BunjaStoreContext, {
|
|
33
|
+
const [value] = (0, react.useState)(require_bunja.createBunjaStore);
|
|
34
|
+
(0, react.useEffect)(() => () => value.dispose(), [value]);
|
|
35
|
+
return (0, react.createElement)(BunjaStoreContext, {
|
|
35
36
|
value,
|
|
36
37
|
children
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
|
-
const scopeContextMap = new Map();
|
|
40
|
+
const scopeContextMap = /* @__PURE__ */ new Map();
|
|
40
41
|
function bindScope(scope, context) {
|
|
41
42
|
scopeContextMap.set(scope, context);
|
|
42
43
|
}
|
|
@@ -47,12 +48,12 @@ function createScopeFromContext(context, hash) {
|
|
|
47
48
|
}
|
|
48
49
|
const defaultReadScope = (scope) => {
|
|
49
50
|
const context = scopeContextMap.get(scope);
|
|
50
|
-
return use(context);
|
|
51
|
+
return (0, react.use)(context);
|
|
51
52
|
};
|
|
52
53
|
function useBunja(bunja, readScope = defaultReadScope) {
|
|
53
|
-
const store = use(BunjaStoreContext);
|
|
54
|
+
const store = (0, react.use)(BunjaStoreContext);
|
|
54
55
|
const { value, mount, deps } = store.get(bunja, readScope);
|
|
55
|
-
useEffect(mount, deps);
|
|
56
|
+
(0, react.useEffect)(mount, deps);
|
|
56
57
|
return value;
|
|
57
58
|
}
|
|
58
59
|
function inject(overrideTable) {
|
|
@@ -61,15 +62,15 @@ function inject(overrideTable) {
|
|
|
61
62
|
if (map.has(scope)) return map.get(scope);
|
|
62
63
|
const context = scopeContextMap.get(scope);
|
|
63
64
|
if (!context) throw new Error("Unable to read the scope. Please inject the value explicitly or bind scope to the React context.");
|
|
64
|
-
return use(context);
|
|
65
|
+
return (0, react.use)(context);
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
//#endregion
|
|
69
|
-
exports.BunjaStoreContext = BunjaStoreContext
|
|
70
|
-
exports.BunjaStoreProvider = BunjaStoreProvider
|
|
71
|
-
exports.bindScope = bindScope
|
|
72
|
-
exports.createScopeFromContext = createScopeFromContext
|
|
73
|
-
exports.inject = inject
|
|
74
|
-
exports.scopeContextMap = scopeContextMap
|
|
75
|
-
exports.useBunja = useBunja
|
|
70
|
+
exports.BunjaStoreContext = BunjaStoreContext;
|
|
71
|
+
exports.BunjaStoreProvider = BunjaStoreProvider;
|
|
72
|
+
exports.bindScope = bindScope;
|
|
73
|
+
exports.createScopeFromContext = createScopeFromContext;
|
|
74
|
+
exports.inject = inject;
|
|
75
|
+
exports.scopeContextMap = scopeContextMap;
|
|
76
|
+
exports.useBunja = useBunja;
|
package/dist/react.d.cts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Bunja, BunjaStore, HashFn, ReadScope, Scope } from "./bunja-WQqJyoyx.cjs";
|
|
2
|
+
import { Context, PropsWithChildren } from "react";
|
|
3
|
+
|
|
4
|
+
//#region react.d.ts
|
|
5
|
+
declare const BunjaStoreContext: Context<BunjaStore>;
|
|
6
|
+
declare function BunjaStoreProvider({
|
|
7
|
+
children
|
|
8
|
+
}: PropsWithChildren): React.JSX.Element;
|
|
9
|
+
declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
|
|
10
|
+
declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
|
|
11
|
+
declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
|
|
12
|
+
declare function useBunja<T>(bunja: Bunja<T>, readScope?: ReadScope): T;
|
|
13
|
+
type ScopePair<T> = [Scope<T>, T];
|
|
14
|
+
declare function inject<const T extends ScopePair<unknown>[]>(overrideTable: T): ReadScope;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { BunjaStoreContext, BunjaStoreProvider, ScopePair, bindScope, createScopeFromContext, inject, scopeContextMap, useBunja };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Bunja, BunjaStore, HashFn, ReadScope, Scope } from "./bunja-Bj2Zho1e.js";
|
|
2
|
+
import { Context, PropsWithChildren } from "react";
|
|
3
|
+
|
|
4
|
+
//#region react.d.ts
|
|
5
|
+
declare const BunjaStoreContext: Context<BunjaStore>;
|
|
6
|
+
declare function BunjaStoreProvider({
|
|
7
|
+
children
|
|
8
|
+
}: PropsWithChildren): React.JSX.Element;
|
|
9
|
+
declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
|
|
10
|
+
declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
|
|
11
|
+
declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
|
|
12
|
+
declare function useBunja<T>(bunja: Bunja<T>, readScope?: ReadScope): T;
|
|
13
|
+
type ScopePair<T> = [Scope<T>, T];
|
|
14
|
+
declare function inject<const T extends ScopePair<unknown>[]>(overrideTable: T): ReadScope;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { BunjaStoreContext, BunjaStoreProvider, ScopePair, bindScope, createScopeFromContext, inject, scopeContextMap, useBunja };
|
package/dist/react.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { createBunjaStore, createScope } from "./bunja-DsftUL38.js";
|
|
2
5
|
import { createContext, createElement, use, useEffect, useState } from "react";
|
|
3
6
|
|
|
4
7
|
//#region react.ts
|
|
5
|
-
"use client";
|
|
6
8
|
const BunjaStoreContext = createContext(createBunjaStore());
|
|
7
9
|
function BunjaStoreProvider({ children }) {
|
|
8
10
|
const [value] = useState(createBunjaStore);
|
|
@@ -12,7 +14,7 @@ function BunjaStoreProvider({ children }) {
|
|
|
12
14
|
children
|
|
13
15
|
});
|
|
14
16
|
}
|
|
15
|
-
const scopeContextMap = new Map();
|
|
17
|
+
const scopeContextMap = /* @__PURE__ */ new Map();
|
|
16
18
|
function bindScope(scope, context) {
|
|
17
19
|
scopeContextMap.set(scope, context);
|
|
18
20
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunja",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.4",
|
|
5
5
|
"description": "State Lifetime Manager",
|
|
6
6
|
"main": "dist/bunja.cjs",
|
|
7
7
|
"module": "dist/bunja.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/react": "^19",
|
|
53
53
|
"react": "^19",
|
|
54
|
-
"tsdown": "^0.
|
|
54
|
+
"tsdown": "^0.12.7",
|
|
55
55
|
"typescript": "^5.6.3"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|