bunja 2.0.0-alpha.2 → 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.
@@ -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,12 +54,13 @@ 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(bunja$1.relatedBunjas.map((relatedBunja) => [relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap)]));
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;
62
61
  throw new Error("`bunja.use` can only be used with Bunja or Scope.");
63
62
  };
63
+ for (const relatedBunja of bunja$1.relatedBunjas) bunjaInstanceMap.set(relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap));
64
64
  const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
65
65
  return {
66
66
  bunjaInstance,
@@ -69,8 +69,8 @@ var BunjaStore = class {
69
69
  };
70
70
  }
71
71
  #getUnbaked(bunja$1, readScope) {
72
- const bunjaInstanceMap = new Map();
73
- const scopeInstanceMap = new Map();
72
+ const bunjaInstanceMap = /* @__PURE__ */ new Map();
73
+ const scopeInstanceMap = /* @__PURE__ */ new Map();
74
74
  function getUse(map, addDep, getInstance) {
75
75
  return (dep) => {
76
76
  const d = dep;
@@ -100,7 +100,7 @@ var BunjaStore = class {
100
100
  scopeInstanceMap
101
101
  };
102
102
  } finally {
103
- this.#bakingContext = undefined;
103
+ this.#bakingContext = void 0;
104
104
  }
105
105
  }
106
106
  #getBunjaInstance(bunja$1, scopeInstanceMap) {
@@ -130,7 +130,7 @@ var BunjaStore = class {
130
130
  }
131
131
  #getScopeInstance(scope, value) {
132
132
  const key = scope.hash(value);
133
- 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);
134
134
  return instanceMap.get(key) ?? instanceMap.set(key, new ScopeInstance(value, () => instanceMap.delete(key))).get(key);
135
135
  }
136
136
  #createBunjaInstance(id, value, effects) {
@@ -150,8 +150,8 @@ var Bunja = class Bunja {
150
150
  debugLabel = "";
151
151
  #phase = {
152
152
  baked: false,
153
- parents: new Set(),
154
- scopes: new Set()
153
+ parents: /* @__PURE__ */ new Set(),
154
+ scopes: /* @__PURE__ */ new Set()
155
155
  };
156
156
  constructor(init) {
157
157
  this.init = init;
@@ -258,7 +258,7 @@ var ScopeInstance = class ScopeInstance extends RefCounter {
258
258
  }
259
259
  };
260
260
  function toposort(nodes) {
261
- const visited = new Set();
261
+ const visited = /* @__PURE__ */ new Set();
262
262
  const result = [];
263
263
  function visit(current) {
264
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,12 +55,13 @@ 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(bunja$1.relatedBunjas.map((relatedBunja) => [relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap)]));
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;
63
62
  throw new Error("`bunja.use` can only be used with Bunja or Scope.");
64
63
  };
64
+ for (const relatedBunja of bunja$1.relatedBunjas) bunjaInstanceMap.set(relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap));
65
65
  const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
66
66
  return {
67
67
  bunjaInstance,
@@ -70,8 +70,8 @@ var BunjaStore = class {
70
70
  };
71
71
  }
72
72
  #getUnbaked(bunja$1, readScope) {
73
- const bunjaInstanceMap = new Map();
74
- const scopeInstanceMap = new Map();
73
+ const bunjaInstanceMap = /* @__PURE__ */ new Map();
74
+ const scopeInstanceMap = /* @__PURE__ */ new Map();
75
75
  function getUse(map, addDep, getInstance) {
76
76
  return (dep) => {
77
77
  const d = dep;
@@ -101,7 +101,7 @@ var BunjaStore = class {
101
101
  scopeInstanceMap
102
102
  };
103
103
  } finally {
104
- this.#bakingContext = undefined;
104
+ this.#bakingContext = void 0;
105
105
  }
106
106
  }
107
107
  #getBunjaInstance(bunja$1, scopeInstanceMap) {
@@ -131,7 +131,7 @@ var BunjaStore = class {
131
131
  }
132
132
  #getScopeInstance(scope, value) {
133
133
  const key = scope.hash(value);
134
- 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);
135
135
  return instanceMap.get(key) ?? instanceMap.set(key, new ScopeInstance(value, () => instanceMap.delete(key))).get(key);
136
136
  }
137
137
  #createBunjaInstance(id, value, effects) {
@@ -151,8 +151,8 @@ var Bunja = class Bunja {
151
151
  debugLabel = "";
152
152
  #phase = {
153
153
  baked: false,
154
- parents: new Set(),
155
- scopes: new Set()
154
+ parents: /* @__PURE__ */ new Set(),
155
+ scopes: /* @__PURE__ */ new Set()
156
156
  };
157
157
  constructor(init) {
158
158
  this.init = init;
@@ -259,7 +259,7 @@ var ScopeInstance = class ScopeInstance extends RefCounter {
259
259
  }
260
260
  };
261
261
  function toposort(nodes) {
262
- const visited = new Set();
262
+ const visited = /* @__PURE__ */ new Set();
263
263
  const result = [];
264
264
  function visit(current) {
265
265
  if (visited.has(current)) return;
@@ -277,27 +277,32 @@ Object.defineProperty(exports, 'Bunja', {
277
277
  get: function () {
278
278
  return Bunja;
279
279
  }
280
- });Object.defineProperty(exports, 'BunjaStore', {
280
+ });
281
+ Object.defineProperty(exports, 'BunjaStore', {
281
282
  enumerable: true,
282
283
  get: function () {
283
284
  return BunjaStore;
284
285
  }
285
- });Object.defineProperty(exports, 'Scope', {
286
+ });
287
+ Object.defineProperty(exports, 'Scope', {
286
288
  enumerable: true,
287
289
  get: function () {
288
290
  return Scope;
289
291
  }
290
- });Object.defineProperty(exports, 'bunja', {
292
+ });
293
+ Object.defineProperty(exports, 'bunja', {
291
294
  enumerable: true,
292
295
  get: function () {
293
296
  return bunja;
294
297
  }
295
- });Object.defineProperty(exports, 'createBunjaStore', {
298
+ });
299
+ Object.defineProperty(exports, 'createBunjaStore', {
296
300
  enumerable: true,
297
301
  get: function () {
298
302
  return createBunjaStore;
299
303
  }
300
- });Object.defineProperty(exports, 'createScope', {
304
+ });
305
+ Object.defineProperty(exports, 'createScope', {
301
306
  enumerable: true,
302
307
  get: function () {
303
308
  return createScope;
package/dist/bunja.cjs CHANGED
@@ -1,9 +1,8 @@
1
- "use strict";
2
- const require_bunja = require('./bunja-bUA1rGXy.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
- export interface BunjaFn {
2
- <T>(init: () => T): Bunja<T>;
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
- export interface BunjaFn {
2
- <T>(init: () => T): Bunja<T>;
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-wcx846sL.js";
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 strict";
1
+ "use client";
2
+
3
+
2
4
  //#region rolldown:runtime
3
5
  var __create = Object.create;
4
6
  var __defProp = Object.defineProperty;
@@ -22,20 +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-bUA1rGXy.cjs');
26
- const { createContext, createElement, use, useEffect, useState } = __toESM(require("react"));
27
+ const require_bunja = require('./bunja-i3L_5FKm.cjs');
28
+ const react = __toESM(require("react"));
27
29
 
28
30
  //#region react.ts
29
- const BunjaStoreContext = createContext(require_bunja.createBunjaStore());
31
+ const BunjaStoreContext = (0, react.createContext)(require_bunja.createBunjaStore());
30
32
  function BunjaStoreProvider({ children }) {
31
- const [value] = useState(require_bunja.createBunjaStore);
32
- useEffect(() => () => value.dispose(), [value]);
33
- 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, {
34
36
  value,
35
37
  children
36
38
  });
37
39
  }
38
- const scopeContextMap = new Map();
40
+ const scopeContextMap = /* @__PURE__ */ new Map();
39
41
  function bindScope(scope, context) {
40
42
  scopeContextMap.set(scope, context);
41
43
  }
@@ -46,12 +48,12 @@ function createScopeFromContext(context, hash) {
46
48
  }
47
49
  const defaultReadScope = (scope) => {
48
50
  const context = scopeContextMap.get(scope);
49
- return use(context);
51
+ return (0, react.use)(context);
50
52
  };
51
53
  function useBunja(bunja, readScope = defaultReadScope) {
52
- const store = use(BunjaStoreContext);
54
+ const store = (0, react.use)(BunjaStoreContext);
53
55
  const { value, mount, deps } = store.get(bunja, readScope);
54
- useEffect(mount, deps);
56
+ (0, react.useEffect)(mount, deps);
55
57
  return value;
56
58
  }
57
59
  function inject(overrideTable) {
@@ -60,15 +62,15 @@ function inject(overrideTable) {
60
62
  if (map.has(scope)) return map.get(scope);
61
63
  const context = scopeContextMap.get(scope);
62
64
  if (!context) throw new Error("Unable to read the scope. Please inject the value explicitly or bind scope to the React context.");
63
- return use(context);
65
+ return (0, react.use)(context);
64
66
  };
65
67
  }
66
68
 
67
69
  //#endregion
68
- exports.BunjaStoreContext = BunjaStoreContext
69
- exports.BunjaStoreProvider = BunjaStoreProvider
70
- exports.bindScope = bindScope
71
- exports.createScopeFromContext = createScopeFromContext
72
- exports.inject = inject
73
- exports.scopeContextMap = scopeContextMap
74
- 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 { type Context, type PropsWithChildren } from "react";
2
- import { type Bunja, type BunjaStore, type HashFn, type ReadScope, type Scope } from "./bunja.ts";
3
- export declare const BunjaStoreContext: Context<BunjaStore>;
4
- export declare function BunjaStoreProvider({ children }: PropsWithChildren): React.JSX.Element;
5
- export declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
6
- export declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
7
- export declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
8
- export declare function useBunja<T>(bunja: Bunja<T>, readScope?: ReadScope): T;
9
- export type ScopePair<T> = [Scope<T>, T];
10
- export declare function inject<const T extends ScopePair<unknown>[]>(overrideTable: T): ReadScope;
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 { type Context, type PropsWithChildren } from "react";
2
- import { type Bunja, type BunjaStore, type HashFn, type ReadScope, type Scope } from "./bunja.ts";
3
- export declare const BunjaStoreContext: Context<BunjaStore>;
4
- export declare function BunjaStoreProvider({ children }: PropsWithChildren): React.JSX.Element;
5
- export declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
6
- export declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
7
- export declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
8
- export declare function useBunja<T>(bunja: Bunja<T>, readScope?: ReadScope): T;
9
- export type ScopePair<T> = [Scope<T>, T];
10
- export declare function inject<const T extends ScopePair<unknown>[]>(overrideTable: T): ReadScope;
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,4 +1,7 @@
1
- import { createBunjaStore, createScope } from "./bunja-wcx846sL.js";
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
@@ -11,7 +14,7 @@ function BunjaStoreProvider({ children }) {
11
14
  children
12
15
  });
13
16
  }
14
- const scopeContextMap = new Map();
17
+ const scopeContextMap = /* @__PURE__ */ new Map();
15
18
  function bindScope(scope, context) {
16
19
  scopeContextMap.set(scope, context);
17
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.2",
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.2.17",
54
+ "tsdown": "^0.12.7",
55
55
  "typescript": "^5.6.3"
56
56
  },
57
57
  "peerDependencies": {
package/react.ts CHANGED
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  import {
2
4
  type Context,
3
5
  createContext,