bunja 2.0.0 → 2.1.0

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 {
@@ -91,7 +92,15 @@ export class BunjaStore {
91
92
  }
92
93
  }
93
94
  get _internalState(): InternalState | undefined {
94
- if (__DEV__) return { bunjas: this.#bunjas, scopes: this.#scopes };
95
+ if (__DEV__) {
96
+ return {
97
+ bunjas: this.#bunjas,
98
+ scopes: this.#scopes,
99
+ get instantiating() {
100
+ return bunja.use != invalidUse;
101
+ },
102
+ };
103
+ }
95
104
  return undefined;
96
105
  }
97
106
  dispose(): void {
@@ -354,7 +363,12 @@ export class Bunja<T> {
354
363
  readonly id: string = String(Bunja.counter++);
355
364
  debugLabel: string = "";
356
365
  #phase: BunjaPhase = { baked: false, parents: new Set(), scopes: new Set() };
357
- constructor(public init: () => T) {}
366
+ constructor(public init: () => T) {
367
+ if (__DEV__) {
368
+ devtoolsGlobalHook.bunjas[this.id] = this;
369
+ devtoolsGlobalHook.emit("bunjaCreated", { bunjaId: this.id });
370
+ }
371
+ }
358
372
  get baked(): boolean {
359
373
  return this.#phase.baked;
360
374
  }
@@ -422,7 +436,12 @@ export class Scope<T> {
422
436
  private static counter: number = 0;
423
437
  readonly id: string = String(Scope.counter++);
424
438
  debugLabel: string = "";
425
- constructor(public readonly hash: HashFn<T> = Scope.identity) {}
439
+ constructor(public readonly hash: HashFn<T> = Scope.identity) {
440
+ if (__DEV__) {
441
+ devtoolsGlobalHook.scopes[this.id] = this;
442
+ devtoolsGlobalHook.emit("scopeCreated", { scopeId: this.id });
443
+ }
444
+ }
426
445
  private static identity<T>(x: T): T {
427
446
  return x;
428
447
  }
@@ -503,6 +522,8 @@ function toposort<T extends Toposortable>(nodes: T[]): T[] {
503
522
  const noop = () => {};
504
523
 
505
524
  export interface BunjaDevtoolsGlobalHook {
525
+ bunjas: Record<string, Bunja<any>>;
526
+ scopes: Record<string, Scope<any>>;
506
527
  stores: Record<string, BunjaStore>;
507
528
  listeners: Record<
508
529
  BunjaDevtoolsEventType,
@@ -518,6 +539,8 @@ export interface BunjaDevtoolsGlobalHook {
518
539
  ): () => void;
519
540
  }
520
541
  export interface BunjaDevtoolsEvent {
542
+ bunjaCreated: { bunjaId: string };
543
+ scopeCreated: { scopeId: string };
521
544
  storeCreated: { storeId: string };
522
545
  storeDisposed: { storeId: string };
523
546
  getCalled: { storeId: string; bunjaInstanceId: string };
@@ -542,7 +565,11 @@ if (__DEV__) {
542
565
  } else {
543
566
  devtoolsGlobalHook = {
544
567
  stores: {},
568
+ bunjas: {},
569
+ scopes: {},
545
570
  listeners: {
571
+ bunjaCreated: new Set(),
572
+ scopeCreated: new Set(),
546
573
  storeCreated: new Set(),
547
574
  storeDisposed: new Set(),
548
575
  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.0",
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,20 @@ declare class ScopeInstance extends RefCounter {
93
94
  constructor(value: unknown, dispose: () => void);
94
95
  }
95
96
  interface BunjaDevtoolsGlobalHook {
97
+ bunjas: Record<string, Bunja<any>>;
98
+ scopes: Record<string, Scope<any>>;
96
99
  stores: Record<string, BunjaStore>;
97
100
  listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
98
101
  emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
99
102
  on<T extends BunjaDevtoolsEventType>(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void;
100
103
  }
101
104
  interface BunjaDevtoolsEvent {
105
+ bunjaCreated: {
106
+ bunjaId: string;
107
+ };
108
+ scopeCreated: {
109
+ scopeId: string;
110
+ };
102
111
  storeCreated: {
103
112
  storeId: string;
104
113
  };
@@ -42,9 +42,11 @@ var BunjaStore = class BunjaStore {
42
42
  get _internalState() {
43
43
  if (__DEV__) return {
44
44
  bunjas: this.#bunjas,
45
- scopes: this.#scopes
45
+ scopes: this.#scopes,
46
+ get instantiating() {
47
+ return bunja.use != invalidUse;
48
+ }
46
49
  };
47
- return void 0;
48
50
  }
49
51
  dispose() {
50
52
  for (const instance of Object.values(this.#bunjas)) instance.dispose();
@@ -96,9 +98,8 @@ var BunjaStore = class BunjaStore {
96
98
  throw new Error("`bunja.use` can only be used with Bunja or Scope.");
97
99
  };
98
100
  for (const relatedBunja of bunja$1.relatedBunjas) bunjaInstanceMap.set(relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap));
99
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
100
101
  return {
101
- bunjaInstance,
102
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
102
103
  bunjaInstanceMap,
103
104
  scopeInstanceMap
104
105
  };
@@ -129,9 +130,8 @@ var BunjaStore = class BunjaStore {
129
130
  const originalBakingContext = this.#bakingContext;
130
131
  try {
131
132
  this.#bakingContext = { currentBunja: bunja$1 };
132
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
133
133
  return {
134
- bunjaInstance,
134
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
135
135
  bunjaInstanceMap,
136
136
  scopeInstanceMap
137
137
  };
@@ -239,6 +239,10 @@ var Bunja = class Bunja {
239
239
  };
240
240
  constructor(init) {
241
241
  this.init = init;
242
+ if (__DEV__) {
243
+ devtoolsGlobalHook.bunjas[this.id] = this;
244
+ devtoolsGlobalHook.emit("bunjaCreated", { bunjaId: this.id });
245
+ }
242
246
  }
243
247
  get baked() {
244
248
  return this.#phase.baked;
@@ -268,12 +272,11 @@ var Bunja = class Bunja {
268
272
  const scopes = this.#phase.scopes;
269
273
  const parents = this.parents;
270
274
  const relatedBunjas = toposort(parents);
271
- const relatedScopes = Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]));
272
275
  this.#phase = {
273
276
  baked: true,
274
277
  parents,
275
278
  relatedBunjas,
276
- relatedScopes
279
+ relatedScopes: Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]))
277
280
  };
278
281
  }
279
282
  calcInstanceId(scopeInstanceMap) {
@@ -291,6 +294,10 @@ var Scope = class Scope {
291
294
  debugLabel = "";
292
295
  constructor(hash = Scope.identity) {
293
296
  this.hash = hash;
297
+ if (__DEV__) {
298
+ devtoolsGlobalHook.scopes[this.id] = this;
299
+ devtoolsGlobalHook.emit("scopeCreated", { scopeId: this.id });
300
+ }
294
301
  }
295
302
  static identity(x) {
296
303
  return x;
@@ -361,7 +368,11 @@ if (__DEV__) if (globalThis.__BUNJA_DEVTOOLS_GLOBAL_HOOK__) devtoolsGlobalHook =
361
368
  else {
362
369
  devtoolsGlobalHook = {
363
370
  stores: {},
371
+ bunjas: {},
372
+ scopes: {},
364
373
  listeners: {
374
+ bunjaCreated: /* @__PURE__ */ new Set(),
375
+ scopeCreated: /* @__PURE__ */ new Set(),
365
376
  storeCreated: /* @__PURE__ */ new Set(),
366
377
  storeDisposed: /* @__PURE__ */ new Set(),
367
378
  getCalled: /* @__PURE__ */ new Set(),
@@ -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,20 @@ declare class ScopeInstance extends RefCounter {
93
94
  constructor(value: unknown, dispose: () => void);
94
95
  }
95
96
  interface BunjaDevtoolsGlobalHook {
97
+ bunjas: Record<string, Bunja<any>>;
98
+ scopes: Record<string, Scope<any>>;
96
99
  stores: Record<string, BunjaStore>;
97
100
  listeners: Record<BunjaDevtoolsEventType, Set<(event: any) => void>>;
98
101
  emit<T extends BunjaDevtoolsEventType>(type: T, event: BunjaDevtoolsEvent[T]): void;
99
102
  on<T extends BunjaDevtoolsEventType>(type: T, listener: (event: BunjaDevtoolsEvent[T]) => void): () => void;
100
103
  }
101
104
  interface BunjaDevtoolsEvent {
105
+ bunjaCreated: {
106
+ bunjaId: string;
107
+ };
108
+ scopeCreated: {
109
+ scopeId: string;
110
+ };
102
111
  storeCreated: {
103
112
  storeId: string;
104
113
  };
@@ -43,9 +43,11 @@ var BunjaStore = class BunjaStore {
43
43
  get _internalState() {
44
44
  if (__DEV__) return {
45
45
  bunjas: this.#bunjas,
46
- scopes: this.#scopes
46
+ scopes: this.#scopes,
47
+ get instantiating() {
48
+ return bunja.use != invalidUse;
49
+ }
47
50
  };
48
- return void 0;
49
51
  }
50
52
  dispose() {
51
53
  for (const instance of Object.values(this.#bunjas)) instance.dispose();
@@ -97,9 +99,8 @@ var BunjaStore = class BunjaStore {
97
99
  throw new Error("`bunja.use` can only be used with Bunja or Scope.");
98
100
  };
99
101
  for (const relatedBunja of bunja$1.relatedBunjas) bunjaInstanceMap.set(relatedBunja, this.#getBunjaInstance(relatedBunja, scopeInstanceMap));
100
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
101
102
  return {
102
- bunjaInstance,
103
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
103
104
  bunjaInstanceMap,
104
105
  scopeInstanceMap
105
106
  };
@@ -130,9 +131,8 @@ var BunjaStore = class BunjaStore {
130
131
  const originalBakingContext = this.#bakingContext;
131
132
  try {
132
133
  this.#bakingContext = { currentBunja: bunja$1 };
133
- const bunjaInstance = this.#getBunjaInstance(bunja$1, scopeInstanceMap);
134
134
  return {
135
- bunjaInstance,
135
+ bunjaInstance: this.#getBunjaInstance(bunja$1, scopeInstanceMap),
136
136
  bunjaInstanceMap,
137
137
  scopeInstanceMap
138
138
  };
@@ -240,6 +240,10 @@ var Bunja = class Bunja {
240
240
  };
241
241
  constructor(init) {
242
242
  this.init = init;
243
+ if (__DEV__) {
244
+ devtoolsGlobalHook.bunjas[this.id] = this;
245
+ devtoolsGlobalHook.emit("bunjaCreated", { bunjaId: this.id });
246
+ }
243
247
  }
244
248
  get baked() {
245
249
  return this.#phase.baked;
@@ -269,12 +273,11 @@ var Bunja = class Bunja {
269
273
  const scopes = this.#phase.scopes;
270
274
  const parents = this.parents;
271
275
  const relatedBunjas = toposort(parents);
272
- const relatedScopes = Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]));
273
276
  this.#phase = {
274
277
  baked: true,
275
278
  parents,
276
279
  relatedBunjas,
277
- relatedScopes
280
+ relatedScopes: Array.from(new Set([...relatedBunjas.flatMap((bunja$1) => bunja$1.relatedScopes), ...scopes]))
278
281
  };
279
282
  }
280
283
  calcInstanceId(scopeInstanceMap) {
@@ -292,6 +295,10 @@ var Scope = class Scope {
292
295
  debugLabel = "";
293
296
  constructor(hash = Scope.identity) {
294
297
  this.hash = hash;
298
+ if (__DEV__) {
299
+ devtoolsGlobalHook.scopes[this.id] = this;
300
+ devtoolsGlobalHook.emit("scopeCreated", { scopeId: this.id });
301
+ }
295
302
  }
296
303
  static identity(x) {
297
304
  return x;
@@ -362,7 +369,11 @@ if (__DEV__) if (globalThis.__BUNJA_DEVTOOLS_GLOBAL_HOOK__) devtoolsGlobalHook =
362
369
  else {
363
370
  devtoolsGlobalHook = {
364
371
  stores: {},
372
+ bunjas: {},
373
+ scopes: {},
365
374
  listeners: {
375
+ bunjaCreated: /* @__PURE__ */ new Set(),
376
+ scopeCreated: /* @__PURE__ */ new Set(),
366
377
  storeCreated: /* @__PURE__ */ new Set(),
367
378
  storeDisposed: /* @__PURE__ */ new Set(),
368
379
  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-DFFVW7Gi.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-BKpQTG04.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-B_HNgDan.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-BOUkMIz6.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-DFFVW7Gi.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-BKpQTG04.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-B_HNgDan.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-BOUkMIz6.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-DFFVW7Gi.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-BKpQTG04.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-B_HNgDan.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-BOUkMIz6.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.0",
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,