bunja 2.0.0 → 2.1.1

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/bunja.ts CHANGED
@@ -68,6 +68,7 @@ type ScopeInstanceMap = Map<Scope<unknown>, ScopeInstance>;
68
68
  interface InternalState {
69
69
  bunjas: Record<string, BunjaInstance>;
70
70
  scopes: Map<Scope<unknown>, Map<unknown, ScopeInstance>>;
71
+ instantiating: boolean;
71
72
  }
72
73
 
73
74
  interface BunjaBakingContext {
@@ -85,13 +86,18 @@ export class BunjaStore {
85
86
  #bakingContext: BunjaBakingContext | undefined;
86
87
  wrapInstance: WrapInstanceFn = defaultWrapInstanceFn;
87
88
  constructor() {
88
- if (__DEV__) {
89
- devtoolsGlobalHook.stores[this.id] = this;
90
- devtoolsGlobalHook.emit("storeCreated", { storeId: this.id });
91
- }
89
+ if (__DEV__) devtoolsGlobalHook.emit("storeCreated", { storeId: this.id });
92
90
  }
93
91
  get _internalState(): InternalState | undefined {
94
- if (__DEV__) return { bunjas: this.#bunjas, scopes: this.#scopes };
92
+ if (__DEV__) {
93
+ return {
94
+ bunjas: this.#bunjas,
95
+ scopes: this.#scopes,
96
+ get instantiating() {
97
+ return bunja.use != invalidUse;
98
+ },
99
+ };
100
+ }
95
101
  return undefined;
96
102
  }
97
103
  dispose(): void {
@@ -101,10 +107,7 @@ export class BunjaStore {
101
107
  }
102
108
  this.#bunjas = {};
103
109
  this.#scopes = new Map();
104
- if (__DEV__) {
105
- devtoolsGlobalHook.emit("storeDisposed", { storeId: this.id });
106
- delete devtoolsGlobalHook.stores[this.id];
107
- }
110
+ if (__DEV__) devtoolsGlobalHook.emit("storeDisposed", { storeId: this.id });
108
111
  }
109
112
  get<T>(bunja: Bunja<T>, readScope: ReadScope): BunjaStoreGetResult<T> {
110
113
  const originalUse = bunjaFn.use;
@@ -354,7 +357,12 @@ export class Bunja<T> {
354
357
  readonly id: string = String(Bunja.counter++);
355
358
  debugLabel: string = "";
356
359
  #phase: BunjaPhase = { baked: false, parents: new Set(), scopes: new Set() };
357
- constructor(public init: () => T) {}
360
+ constructor(public init: () => T) {
361
+ if (__DEV__) {
362
+ devtoolsGlobalHook.bunjas[this.id] = this;
363
+ devtoolsGlobalHook.emit("bunjaCreated", { bunjaId: this.id });
364
+ }
365
+ }
358
366
  get baked(): boolean {
359
367
  return this.#phase.baked;
360
368
  }
@@ -422,7 +430,12 @@ export class Scope<T> {
422
430
  private static counter: number = 0;
423
431
  readonly id: string = String(Scope.counter++);
424
432
  debugLabel: string = "";
425
- constructor(public readonly hash: HashFn<T> = Scope.identity) {}
433
+ constructor(public readonly hash: HashFn<T> = Scope.identity) {
434
+ if (__DEV__) {
435
+ devtoolsGlobalHook.scopes[this.id] = this;
436
+ devtoolsGlobalHook.emit("scopeCreated", { scopeId: this.id });
437
+ }
438
+ }
426
439
  private static identity<T>(x: T): T {
427
440
  return x;
428
441
  }
@@ -503,7 +516,8 @@ function toposort<T extends Toposortable>(nodes: T[]): T[] {
503
516
  const noop = () => {};
504
517
 
505
518
  export interface BunjaDevtoolsGlobalHook {
506
- stores: Record<string, BunjaStore>;
519
+ bunjas: Record<string, Bunja<any>>;
520
+ scopes: Record<string, Scope<any>>;
507
521
  listeners: Record<
508
522
  BunjaDevtoolsEventType,
509
523
  Set<(event: any) => void>
@@ -518,6 +532,8 @@ export interface BunjaDevtoolsGlobalHook {
518
532
  ): () => void;
519
533
  }
520
534
  export interface BunjaDevtoolsEvent {
535
+ bunjaCreated: { bunjaId: string };
536
+ scopeCreated: { scopeId: string };
521
537
  storeCreated: { storeId: string };
522
538
  storeDisposed: { storeId: string };
523
539
  getCalled: { storeId: string; bunjaInstanceId: string };
@@ -541,8 +557,11 @@ if (__DEV__) {
541
557
  devtoolsGlobalHook = (globalThis as any).__BUNJA_DEVTOOLS_GLOBAL_HOOK__;
542
558
  } else {
543
559
  devtoolsGlobalHook = {
544
- stores: {},
560
+ bunjas: {},
561
+ scopes: {},
545
562
  listeners: {
563
+ bunjaCreated: new Set(),
564
+ scopeCreated: new Set(),
546
565
  storeCreated: new Set(),
547
566
  storeDisposed: new Set(),
548
567
  getCalled: new Set(),
package/deno.json CHANGED
@@ -1,11 +1,17 @@
1
1
  {
2
2
  "name": "@disjukr/bunja",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "license": "Zlib",
5
5
  "exports": {
6
6
  ".": "./bunja.ts",
7
7
  "./react": "./react.ts",
8
8
  "./solid": "./solid.ts"
9
9
  },
10
- "exclude": ["dist"]
10
+ "imports": {
11
+ "@std/assert": "jsr:@std/assert@1",
12
+ "@std/testing": "jsr:@std/testing@1"
13
+ },
14
+ "exclude": [
15
+ "dist"
16
+ ]
11
17
  }
@@ -19,6 +19,7 @@ type Dep<T> = Bunja<T> | Scope<T>;
19
19
  interface InternalState {
20
20
  bunjas: Record<string, BunjaInstance>;
21
21
  scopes: Map<Scope<unknown>, Map<unknown, ScopeInstance>>;
22
+ instantiating: boolean;
22
23
  }
23
24
  type WrapInstanceFn = <T>(fn: (dispose: () => void) => T) => T;
24
25
  declare class BunjaStore {
@@ -93,12 +94,19 @@ declare class ScopeInstance extends RefCounter {
93
94
  constructor(value: unknown, dispose: () => void);
94
95
  }
95
96
  interface BunjaDevtoolsGlobalHook {
96
- stores: Record<string, BunjaStore>;
97
+ bunjas: Record<string, Bunja<any>>;
98
+ scopes: Record<string, Scope<any>>;
97
99
  listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
98
100
  emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
99
101
  on<T extends BunjaDevtoolsEventType>(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void;
100
102
  }
101
103
  interface BunjaDevtoolsEvent {
104
+ bunjaCreated: {
105
+ bunjaId: string;
106
+ };
107
+ scopeCreated: {
108
+ scopeId: string;
109
+ };
102
110
  storeCreated: {
103
111
  storeId: string;
104
112
  };
@@ -19,6 +19,7 @@ type Dep<T> = Bunja<T> | Scope<T>;
19
19
  interface InternalState {
20
20
  bunjas: Record<string, BunjaInstance>;
21
21
  scopes: Map<Scope<unknown>, Map<unknown, ScopeInstance>>;
22
+ instantiating: boolean;
22
23
  }
23
24
  type WrapInstanceFn = <T>(fn: (dispose: () => void) => T) => T;
24
25
  declare class BunjaStore {
@@ -93,12 +94,19 @@ declare class ScopeInstance extends RefCounter {
93
94
  constructor(value: unknown, dispose: () => void);
94
95
  }
95
96
  interface BunjaDevtoolsGlobalHook {
96
- stores: Record<string, BunjaStore>;
97
+ bunjas: Record<string, Bunja<any>>;
98
+ scopes: Record<string, Scope<any>>;
97
99
  listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
98
100
  emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
99
101
  on<T extends BunjaDevtoolsEventType>(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void;
100
102
  }
101
103
  interface BunjaDevtoolsEvent {
104
+ bunjaCreated: {
105
+ bunjaId: string;
106
+ };
107
+ scopeCreated: {
108
+ scopeId: string;
109
+ };
102
110
  storeCreated: {
103
111
  storeId: string;
104
112
  };
@@ -35,27 +35,23 @@ var BunjaStore = class BunjaStore {
35
35
  #bakingContext;
36
36
  wrapInstance = defaultWrapInstanceFn;
37
37
  constructor() {
38
- if (__DEV__) {
39
- devtoolsGlobalHook.stores[this.id] = this;
40
- devtoolsGlobalHook.emit("storeCreated", { storeId: this.id });
41
- }
38
+ if (__DEV__) devtoolsGlobalHook.emit("storeCreated", { storeId: this.id });
42
39
  }
43
40
  get _internalState() {
44
41
  if (__DEV__) return {
45
42
  bunjas: this.#bunjas,
46
- scopes: this.#scopes
43
+ scopes: this.#scopes,
44
+ get instantiating() {
45
+ return bunja.use != invalidUse;
46
+ }
47
47
  };
48
- return void 0;
49
48
  }
50
49
  dispose() {
51
50
  for (const instance of Object.values(this.#bunjas)) instance.dispose();
52
51
  for (const instanceMap of Object.values(this.#scopes)) for (const instance of instanceMap.values()) instance.dispose();
53
52
  this.#bunjas = {};
54
53
  this.#scopes = /* @__PURE__ */ new Map();
55
- if (__DEV__) {
56
- devtoolsGlobalHook.emit("storeDisposed", { storeId: this.id });
57
- delete devtoolsGlobalHook.stores[this.id];
58
- }
54
+ if (__DEV__) devtoolsGlobalHook.emit("storeDisposed", { storeId: this.id });
59
55
  }
60
56
  get(bunja$1, readScope) {
61
57
  const originalUse = bunjaFn.use;
@@ -97,9 +93,8 @@ var BunjaStore = class BunjaStore {
97
93
  throw new Error("`bunja.use` can only be used with Bunja or Scope.");
98
94
  };
99
95
  for (const relatedBunja of bunja$1.relatedBunjas) bunjaInstanceMap.set(relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap));
100
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
101
96
  return {
102
- bunjaInstance,
97
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
103
98
  bunjaInstanceMap,
104
99
  scopeInstanceMap
105
100
  };
@@ -130,9 +125,8 @@ var BunjaStore = class BunjaStore {
130
125
  const originalBakingContext = this.#bakingContext;
131
126
  try {
132
127
  this.#bakingContext = { currentBunja: bunja$1 };
133
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
134
128
  return {
135
- bunjaInstance,
129
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
136
130
  bunjaInstanceMap,
137
131
  scopeInstanceMap
138
132
  };
@@ -240,6 +234,10 @@ var Bunja = class Bunja {
240
234
  };
241
235
  constructor(init) {
242
236
  this.init = init;
237
+ if (__DEV__) {
238
+ devtoolsGlobalHook.bunjas[this.id] = this;
239
+ devtoolsGlobalHook.emit("bunjaCreated", { bunjaId: this.id });
240
+ }
243
241
  }
244
242
  get baked() {
245
243
  return this.#phase.baked;
@@ -269,12 +267,11 @@ var Bunja = class Bunja {
269
267
  const scopes = this.#phase.scopes;
270
268
  const parents = this.parents;
271
269
  const relatedBunjas = toposort(parents);
272
- const relatedScopes = Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]));
273
270
  this.#phase = {
274
271
  baked: true,
275
272
  parents,
276
273
  relatedBunjas,
277
- relatedScopes
274
+ relatedScopes: Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]))
278
275
  };
279
276
  }
280
277
  calcInstanceId(scopeInstanceMap) {
@@ -292,6 +289,10 @@ var Scope = class Scope {
292
289
  debugLabel = "";
293
290
  constructor(hash = Scope.identity) {
294
291
  this.hash = hash;
292
+ if (__DEV__) {
293
+ devtoolsGlobalHook.scopes[this.id] = this;
294
+ devtoolsGlobalHook.emit("scopeCreated", { scopeId: this.id });
295
+ }
295
296
  }
296
297
  static identity(x) {
297
298
  return x;
@@ -361,8 +362,11 @@ let devtoolsGlobalHook;
361
362
  if (__DEV__) if (globalThis.__BUNJA_DEVTOOLS_GLOBAL_HOOK__) devtoolsGlobalHook = globalThis.__BUNJA_DEVTOOLS_GLOBAL_HOOK__;
362
363
  else {
363
364
  devtoolsGlobalHook = {
364
- stores: {},
365
+ bunjas: {},
366
+ scopes: {},
365
367
  listeners: {
368
+ bunjaCreated: /* @__PURE__ */ new Set(),
369
+ scopeCreated: /* @__PURE__ */ new Set(),
366
370
  storeCreated: /* @__PURE__ */ new Set(),
367
371
  storeDisposed: /* @__PURE__ */ new Set(),
368
372
  getCalled: /* @__PURE__ */ new Set(),
@@ -34,27 +34,23 @@ var BunjaStore = class BunjaStore {
34
34
  #bakingContext;
35
35
  wrapInstance = defaultWrapInstanceFn;
36
36
  constructor() {
37
- if (__DEV__) {
38
- devtoolsGlobalHook.stores[this.id] = this;
39
- devtoolsGlobalHook.emit("storeCreated", { storeId: this.id });
40
- }
37
+ if (__DEV__) devtoolsGlobalHook.emit("storeCreated", { storeId: this.id });
41
38
  }
42
39
  get _internalState() {
43
40
  if (__DEV__) return {
44
41
  bunjas: this.#bunjas,
45
- scopes: this.#scopes
42
+ scopes: this.#scopes,
43
+ get instantiating() {
44
+ return bunja.use != invalidUse;
45
+ }
46
46
  };
47
- return void 0;
48
47
  }
49
48
  dispose() {
50
49
  for (const instance of Object.values(this.#bunjas)) instance.dispose();
51
50
  for (const instanceMap of Object.values(this.#scopes)) for (const instance of instanceMap.values()) instance.dispose();
52
51
  this.#bunjas = {};
53
52
  this.#scopes = /* @__PURE__ */ new Map();
54
- if (__DEV__) {
55
- devtoolsGlobalHook.emit("storeDisposed", { storeId: this.id });
56
- delete devtoolsGlobalHook.stores[this.id];
57
- }
53
+ if (__DEV__) devtoolsGlobalHook.emit("storeDisposed", { storeId: this.id });
58
54
  }
59
55
  get(bunja$1, readScope) {
60
56
  const originalUse = bunjaFn.use;
@@ -96,9 +92,8 @@ var BunjaStore = class BunjaStore {
96
92
  throw new Error("`bunja.use` can only be used with Bunja or Scope.");
97
93
  };
98
94
  for (const relatedBunja of bunja$1.relatedBunjas) bunjaInstanceMap.set(relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap));
99
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
100
95
  return {
101
- bunjaInstance,
96
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
102
97
  bunjaInstanceMap,
103
98
  scopeInstanceMap
104
99
  };
@@ -129,9 +124,8 @@ var BunjaStore = class BunjaStore {
129
124
  const originalBakingContext = this.#bakingContext;
130
125
  try {
131
126
  this.#bakingContext = { currentBunja: bunja$1 };
132
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
133
127
  return {
134
- bunjaInstance,
128
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
135
129
  bunjaInstanceMap,
136
130
  scopeInstanceMap
137
131
  };
@@ -239,6 +233,10 @@ var Bunja = class Bunja {
239
233
  };
240
234
  constructor(init) {
241
235
  this.init = init;
236
+ if (__DEV__) {
237
+ devtoolsGlobalHook.bunjas[this.id] = this;
238
+ devtoolsGlobalHook.emit("bunjaCreated", { bunjaId: this.id });
239
+ }
242
240
  }
243
241
  get baked() {
244
242
  return this.#phase.baked;
@@ -268,12 +266,11 @@ var Bunja = class Bunja {
268
266
  const scopes = this.#phase.scopes;
269
267
  const parents = this.parents;
270
268
  const relatedBunjas = toposort(parents);
271
- const relatedScopes = Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]));
272
269
  this.#phase = {
273
270
  baked: true,
274
271
  parents,
275
272
  relatedBunjas,
276
- relatedScopes
273
+ relatedScopes: Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]))
277
274
  };
278
275
  }
279
276
  calcInstanceId(scopeInstanceMap) {
@@ -291,6 +288,10 @@ var Scope = class Scope {
291
288
  debugLabel = "";
292
289
  constructor(hash = Scope.identity) {
293
290
  this.hash = hash;
291
+ if (__DEV__) {
292
+ devtoolsGlobalHook.scopes[this.id] = this;
293
+ devtoolsGlobalHook.emit("scopeCreated", { scopeId: this.id });
294
+ }
294
295
  }
295
296
  static identity(x) {
296
297
  return x;
@@ -360,8 +361,11 @@ let devtoolsGlobalHook;
360
361
  if (__DEV__) if (globalThis.__BUNJA_DEVTOOLS_GLOBAL_HOOK__) devtoolsGlobalHook = globalThis.__BUNJA_DEVTOOLS_GLOBAL_HOOK__;
361
362
  else {
362
363
  devtoolsGlobalHook = {
363
- stores: {},
364
+ bunjas: {},
365
+ scopes: {},
364
366
  listeners: {
367
+ bunjaCreated: /* @__PURE__ */ new Set(),
368
+ scopeCreated: /* @__PURE__ */ new Set(),
365
369
  storeCreated: /* @__PURE__ */ new Set(),
366
370
  storeDisposed: /* @__PURE__ */ new Set(),
367
371
  getCalled: /* @__PURE__ */ new Set(),
package/dist/bunja.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_bunja = require('./bunja-CaephaLd.cjs');
1
+ const require_bunja = require('./bunja-Ce8RwebF.cjs');
2
2
 
3
3
  exports.Bunja = require_bunja.Bunja;
4
4
  exports.BunjaStore = require_bunja.BunjaStore;
package/dist/bunja.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaForkFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-DXtbhAmJ.cjs";
1
+ import { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaForkFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-CPUl4ZRK.cjs";
2
2
  export { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaForkFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount };
package/dist/bunja.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaForkFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-D_SKFBCD.js";
1
+ import { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaForkFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-BvZKLiEP.js";
2
2
  export { Bunja, BunjaDevtoolsEvent, BunjaDevtoolsEventType, BunjaDevtoolsGlobalHook, BunjaEffectCallback, BunjaEffectFn, BunjaFn, BunjaForkFn, BunjaStore, BunjaStoreGetResult, BunjaUseFn, CreateBunjaStoreConfig, Dep, HashFn, ReadScope, Scope, ScopeValuePair, WrapInstanceFn, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount };
package/dist/bunja.js CHANGED
@@ -1,3 +1,3 @@
1
- import { Bunja, BunjaStore, Scope, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-EJqDbU0A.js";
1
+ import { Bunja, BunjaStore, Scope, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-DhBgerdn.js";
2
2
 
3
3
  export { Bunja, BunjaStore, Scope, bunja, createBunjaStore, createReadScopeFn, createScope, delayUnmount };
package/dist/react.cjs CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
 
4
4
  const require_chunk = require('./chunk-CUT6urMc.cjs');
5
- const require_bunja = require('./bunja-CaephaLd.cjs');
6
- const react = require_chunk.__toESM(require("react"));
5
+ const require_bunja = require('./bunja-Ce8RwebF.cjs');
6
+ let react = require("react");
7
+ react = require_chunk.__toESM(react);
7
8
 
8
9
  //#region react.ts
9
10
  const __DEV__ = process.env.NODE_ENV !== "production";
@@ -11,7 +12,7 @@ const BunjaStoreContext = (0, react.createContext)(require_bunja.createBunjaStor
11
12
  function BunjaStoreProvider({ children }) {
12
13
  const [value] = (0, react.useState)(require_bunja.createBunjaStore);
13
14
  (0, react.useEffect)(() => () => value.dispose(), [value]);
14
- return (0, react.createElement)(BunjaStoreContext, {
15
+ return (0, react.createElement)(BunjaStoreContext.Provider, {
15
16
  value,
16
17
  children
17
18
  });
@@ -26,13 +27,13 @@ function createScopeFromContext(context, hash) {
26
27
  return scope;
27
28
  }
28
29
  const defaultReadScope = (scope) => {
29
- const context = scopeContextMap.get(scope);
30
- return (0, react.use)(context);
30
+ return (0, react.useContext)(scopeContextMap.get(scope));
31
31
  };
32
32
  function useBunja(bunja, scopeValuePairs) {
33
- const store = (0, react.use)(BunjaStoreContext);
33
+ const store = (0, react.useContext)(BunjaStoreContext);
34
34
  const readScope = scopeValuePairs ? require_bunja.createReadScopeFn(scopeValuePairs, defaultReadScope) : defaultReadScope;
35
35
  if (__DEV__) {
36
+ if (store._internalState?.instantiating) throw new Error("`useBunja` cannot be called inside a bunja init function.");
36
37
  const { value, mount, deps, bunjaInstance } = store.get(bunja, readScope);
37
38
  (0, react.useEffect)(require_bunja.delayUnmount(mount), deps);
38
39
  (0, react.useMemo)(() => ({
package/dist/react.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-DXtbhAmJ.cjs";
1
+ import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-CPUl4ZRK.cjs";
2
2
  import { Context, PropsWithChildren } from "react";
3
3
 
4
4
  //#region react.d.ts
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-D_SKFBCD.js";
1
+ import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-BvZKLiEP.js";
2
2
  import { Context, PropsWithChildren } from "react";
3
3
 
4
4
  //#region react.d.ts
package/dist/react.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
 
3
3
 
4
- import { createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-EJqDbU0A.js";
5
- import { createContext, createElement, use, useEffect, useMemo, useState } from "react";
4
+ import { createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-DhBgerdn.js";
5
+ import { createContext, createElement, useContext, useEffect, useMemo, useState } from "react";
6
6
 
7
7
  //#region react.ts
8
8
  const __DEV__ = process.env.NODE_ENV !== "production";
@@ -10,7 +10,7 @@ const BunjaStoreContext = createContext(createBunjaStore());
10
10
  function BunjaStoreProvider({ children }) {
11
11
  const [value] = useState(createBunjaStore);
12
12
  useEffect(() => () => value.dispose(), [value]);
13
- return createElement(BunjaStoreContext, {
13
+ return createElement(BunjaStoreContext.Provider, {
14
14
  value,
15
15
  children
16
16
  });
@@ -25,13 +25,13 @@ function createScopeFromContext(context, hash) {
25
25
  return scope;
26
26
  }
27
27
  const defaultReadScope = (scope) => {
28
- const context = scopeContextMap.get(scope);
29
- return use(context);
28
+ return useContext(scopeContextMap.get(scope));
30
29
  };
31
30
  function useBunja(bunja, scopeValuePairs) {
32
- const store = use(BunjaStoreContext);
31
+ const store = useContext(BunjaStoreContext);
33
32
  const readScope = scopeValuePairs ? createReadScopeFn(scopeValuePairs, defaultReadScope) : defaultReadScope;
34
33
  if (__DEV__) {
34
+ if (store._internalState?.instantiating) throw new Error("`useBunja` cannot be called inside a bunja init function.");
35
35
  const { value, mount, deps, bunjaInstance } = store.get(bunja, readScope);
36
36
  useEffect(delayUnmount(mount), deps);
37
37
  useMemo(() => ({
package/dist/solid.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_bunja = require('./bunja-CaephaLd.cjs');
3
- const solid_js = require_chunk.__toESM(require("solid-js"));
2
+ const require_bunja = require('./bunja-Ce8RwebF.cjs');
3
+ let solid_js = require("solid-js");
4
+ solid_js = require_chunk.__toESM(solid_js);
4
5
 
5
6
  //#region solid.ts
6
7
  function access(maybeAccessor) {
@@ -31,8 +32,7 @@ function createScopeFromContext(context, hash) {
31
32
  return scope;
32
33
  }
33
34
  const defaultReadScope = (scope) => {
34
- const context = scopeContextMap.get(scope);
35
- return access((0, solid_js.useContext)(context));
35
+ return access((0, solid_js.useContext)(scopeContextMap.get(scope)));
36
36
  };
37
37
  function useBunja(bunja, scopeValuePairs) {
38
38
  const store = (0, solid_js.useContext)(BunjaStoreContext);
package/dist/solid.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-DXtbhAmJ.cjs";
1
+ import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-CPUl4ZRK.cjs";
2
2
  import { Accessor, Context, JSX, ParentProps } from "solid-js";
3
3
 
4
4
  //#region solid.d.ts
package/dist/solid.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-D_SKFBCD.js";
1
+ import { Bunja, BunjaStore, HashFn, Scope, ScopeValuePair } from "./bunja-BvZKLiEP.js";
2
2
  import { Accessor, Context, JSX, ParentProps } from "solid-js";
3
3
 
4
4
  //#region solid.d.ts
package/dist/solid.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createBunjaStore, createReadScopeFn, createScope } from "./bunja-EJqDbU0A.js";
1
+ import { createBunjaStore, createReadScopeFn, createScope } from "./bunja-DhBgerdn.js";
2
2
  import { createComponent, createContext, createEffect, createMemo, createRoot, getOwner, onCleanup, useContext } from "solid-js";
3
3
 
4
4
  //#region solid.ts
@@ -30,8 +30,7 @@ function createScopeFromContext(context, hash) {
30
30
  return scope;
31
31
  }
32
32
  const defaultReadScope = (scope) => {
33
- const context = scopeContextMap.get(scope);
34
- return access(useContext(context));
33
+ return access(useContext(scopeContextMap.get(scope)));
35
34
  };
36
35
  function useBunja(bunja, scopeValuePairs) {
37
36
  const store = useContext(BunjaStoreContext);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bunja",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.1.1",
5
5
  "description": "State Lifetime Manager",
6
6
  "main": "dist/bunja.cjs",
7
7
  "module": "dist/bunja.js",
@@ -61,6 +61,11 @@
61
61
  ],
62
62
  "author": "JongChan Choi <jong@chan.moe>",
63
63
  "license": "Zlib",
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "https://github.com/disjukr/bunja.git",
67
+ "directory": "bunja"
68
+ },
64
69
  "devDependencies": {
65
70
  "@types/react": "^19",
66
71
  "react": "^19",
@@ -70,7 +75,7 @@
70
75
  },
71
76
  "peerDependencies": {
72
77
  "@types/react": "*",
73
- "react": ">=19",
78
+ "react": ">=18",
74
79
  "solid-js": "^1"
75
80
  },
76
81
  "peerDependenciesMeta": {
package/react.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createContext,
6
6
  createElement,
7
7
  type PropsWithChildren,
8
- use,
8
+ useContext,
9
9
  useEffect,
10
10
  useMemo,
11
11
  useState,
@@ -36,7 +36,7 @@ export function BunjaStoreProvider(
36
36
  ): React.JSX.Element {
37
37
  const [value] = useState(createBunjaStore);
38
38
  useEffect(() => () => value.dispose(), [value]);
39
- return createElement(BunjaStoreContext, { value, children });
39
+ return createElement(BunjaStoreContext.Provider, { value, children });
40
40
  }
41
41
 
42
42
  export const scopeContextMap: Map<Scope<unknown>, Context<unknown>> = new Map();
@@ -55,18 +55,23 @@ export function createScopeFromContext<T>(
55
55
 
56
56
  const defaultReadScope: ReadScope = <T>(scope: Scope<T>) => {
57
57
  const context = scopeContextMap.get(scope as Scope<unknown>)!;
58
- return use(context) as T;
58
+ return useContext(context) as T;
59
59
  };
60
60
 
61
61
  export function useBunja<T>(
62
62
  bunja: Bunja<T>,
63
63
  scopeValuePairs?: ScopeValuePair<any>[],
64
64
  ): T {
65
- const store = use(BunjaStoreContext);
65
+ const store = useContext(BunjaStoreContext);
66
66
  const readScope = scopeValuePairs
67
67
  ? createReadScopeFn(scopeValuePairs, defaultReadScope)
68
68
  : defaultReadScope;
69
69
  if (__DEV__) {
70
+ if (store._internalState?.instantiating) {
71
+ throw new Error(
72
+ "`useBunja` cannot be called inside a bunja init function.",
73
+ );
74
+ }
70
75
  const { value, mount, deps, bunjaInstance } = store.get(bunja, readScope);
71
76
  useEffect(delayUnmount(mount), deps);
72
77
  useMemo(
package/test.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { assertEquals } from "jsr:@std/assert";
2
- import { assertSpyCalls, spy } from "jsr:@std/testing/mock";
1
+ import { assertEquals } from "@std/assert";
2
+ import { assertSpyCalls, spy } from "@std/testing/mock";
3
3
 
4
4
  import { bunja, createBunjaStore, createScope } from "./bunja.ts";
5
5
 
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ESNext",
4
+ "module": "ESNext",
4
5
  "strict": true,
5
6
  "moduleResolution": "Bundler",
6
7
  "allowImportingTsExtensions": true,