bunja 3.0.2 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -1,15 +1,9 @@
1
- import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja-pdetyCM3.js";
1
+ import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja.js";
2
2
  import * as React from "react";
3
3
  import { Context, PropsWithChildren } from "react";
4
-
5
- //#region react.d.ts
6
- declare const BunjaStoreContext: Context<BunjaStore>;
7
- declare function BunjaStoreProvider({
8
- children
9
- }: PropsWithChildren): React.JSX.Element;
10
- declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
11
- declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
12
- declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
13
- declare function useBunja<T, Seed>(bunja: Bunja<T, Seed> | BunjaGetRef<T, Seed>, scopeValuePairs?: ScopeValuePairs): T;
14
- //#endregion
15
- export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
4
+ export declare const BunjaStoreContext: Context<BunjaStore>;
5
+ export declare function BunjaStoreProvider({ children }: PropsWithChildren): React.JSX.Element;
6
+ export declare const scopeContextMap: Map<Scope<unknown>, Context<unknown>>;
7
+ export declare function bindScope<T>(scope: Scope<T>, context: Context<T>): void;
8
+ export declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<T>): Scope<T>;
9
+ export declare function useBunja<T, Seed>(bunja: Bunja<T, Seed> | BunjaGetRef<T, Seed>, scopeValuePairs?: ScopeValuePairs): T;
package/dist/react.js CHANGED
@@ -1,11 +1,8 @@
1
1
  "use client";
2
-
3
-
4
- import { createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja-BmPnlAec.js";
2
+ import { createBunjaStore, createReadScopeFn, createScope, delayUnmount } from "./bunja.js";
5
3
  import * as React from "react";
6
4
  import { createContext, createElement, useContext, useEffect, useMemo, useState } from "react";
7
-
8
- //#region react.ts
5
+ // react.ts
9
6
  const __DEV__ = process.env.NODE_ENV !== "production";
10
7
  const reactUse = React.use;
11
8
  const BunjaStoreContext = createContext(createBunjaStore());
@@ -46,12 +43,14 @@ function useBunja(bunja, scopeValuePairs) {
46
43
  if (__DEV__) {
47
44
  if (store._internalState?.instantiating) throw new Error("`useBunja` cannot be called inside a bunja init function.");
48
45
  const { value, mount, deps, bunjaInstance } = store.get(bunja, readScope);
49
- useEffect(delayUnmount(mount), deps);
46
+ useEffect(delayUnmount(mount), [store, ...deps]);
50
47
  useMemo(() => ({
48
+ storeId: store.id,
51
49
  bunja,
52
50
  scopeValuePairs,
53
51
  bunjaInstance
54
52
  }), [
53
+ store,
55
54
  bunja,
56
55
  scopeValuePairs,
57
56
  bunjaInstance
@@ -59,10 +58,8 @@ function useBunja(bunja, scopeValuePairs) {
59
58
  return value;
60
59
  } else {
61
60
  const { value, mount, deps } = store.get(bunja, readScope);
62
- useEffect(delayUnmount(mount), deps);
61
+ useEffect(delayUnmount(mount), [store, ...deps]);
63
62
  return value;
64
63
  }
65
64
  }
66
-
67
- //#endregion
68
- export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
65
+ export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
@@ -0,0 +1,11 @@
1
+ import { Accessor, Context, JSX, ParentProps } from "solid-js";
2
+ import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "../bunja.js";
3
+ type MaybeAccessor<T> = T | Accessor<T>;
4
+ type AccessedValue<T> = T extends Accessor<infer U> ? U : T;
5
+ export declare const BunjaStoreContext: Context<BunjaStore>;
6
+ export declare function BunjaStoreProvider(props: ParentProps): JSX.Element;
7
+ export declare const scopeContextMap: Map<Scope<unknown>, Context<MaybeAccessor<unknown>>>;
8
+ export declare function bindScope<T>(scope: Scope<T>, context: Context<MaybeAccessor<T>>): void;
9
+ export declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<AccessedValue<T>>): Scope<AccessedValue<T>>;
10
+ export declare function useBunja<T, Seed = undefined>(bunja: MaybeAccessor<Bunja<T, Seed> | BunjaGetRef<T, Seed>>, scopeValuePairs?: MaybeAccessor<ScopeValuePairs>): Accessor<T>;
11
+ export {};
@@ -0,0 +1,69 @@
1
+ import { createComponent, createContext, createEffect, createMemo, createRoot, getOwner, onCleanup, runWithOwner, useContext } from "solid-js";
2
+ import { createBunjaStore, createReadScopeFn, createScope } from "../bunja.js";
3
+ // solid/v1-compat.ts
4
+ const __DEV__ = process.env.NODE_ENV !== "production";
5
+ function access(maybeAccessor) {
6
+ if (typeof maybeAccessor !== "function") return maybeAccessor;
7
+ return maybeAccessor();
8
+ }
9
+ const BunjaStoreContext = createContext(createBunjaStore({ wrapInstance: createRoot }));
10
+ function BunjaStoreProvider(props) {
11
+ const owner = getOwner();
12
+ const bunjaStore = createBunjaStore({ wrapInstance: (impl) => createRoot(impl, owner) });
13
+ onCleanup(() => bunjaStore.dispose());
14
+ return createComponent(BunjaStoreContext.Provider, {
15
+ get value() {
16
+ return bunjaStore;
17
+ },
18
+ get children() {
19
+ return props.children;
20
+ }
21
+ });
22
+ }
23
+ const scopeContextMap = /* @__PURE__ */ new Map();
24
+ function bindScope(scope, context) {
25
+ scopeContextMap.set(scope, context);
26
+ }
27
+ function createScopeFromContext(context, hash) {
28
+ const scope = createScope(hash);
29
+ bindScope(scope, context);
30
+ return scope;
31
+ }
32
+ function useBunja(bunja, scopeValuePairs) {
33
+ const owner = getOwner();
34
+ const store = useContext(BunjaStoreContext);
35
+ const defaultReadScope = (scope) => {
36
+ const context = scopeContextMap.get(scope);
37
+ return access(runWithOwner(owner, () => useContext(context)));
38
+ };
39
+ const readScope = createMemo(() => {
40
+ const pairs = access(scopeValuePairs);
41
+ return {
42
+ scopeValuePairs: pairs,
43
+ read: pairs ? createReadScopeFn(pairs, defaultReadScope) : defaultReadScope
44
+ };
45
+ });
46
+ const entry = createMemo(() => {
47
+ const { read, scopeValuePairs } = readScope();
48
+ const resolvedBunja = access(bunja);
49
+ const scopes = /* @__PURE__ */ new Set();
50
+ const result = store.get(resolvedBunja, (scope) => {
51
+ scopes.add(scope);
52
+ return read(scope);
53
+ });
54
+ for (const scope of scopes) read(scope);
55
+ if (__DEV__) Object.assign(getOwner(), {
56
+ storeId: store.id,
57
+ bunja: resolvedBunja,
58
+ scopeValuePairs,
59
+ bunjaInstance: result.bunjaInstance
60
+ });
61
+ return result;
62
+ });
63
+ createEffect(() => {
64
+ const cleanup = entry().mount();
65
+ onCleanup(() => setTimeout(cleanup));
66
+ });
67
+ return () => entry().value;
68
+ }
69
+ export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
package/dist/solid.d.ts CHANGED
@@ -1,14 +1,11 @@
1
- import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja-pdetyCM3.js";
2
- import { Accessor, Context, JSX, ParentProps } from "solid-js";
3
-
4
- //#region solid.d.ts
1
+ import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja.js";
2
+ import { Accessor, Context, Element, ParentProps } from "solid-js";
5
3
  type MaybeAccessor<T> = T | Accessor<T>;
6
4
  type AccessedValue<T> = T extends Accessor<infer U> ? U : T;
7
- declare const BunjaStoreContext: Context<BunjaStore>;
8
- declare function BunjaStoreProvider(props: ParentProps): JSX.Element;
9
- declare const scopeContextMap: Map<Scope<unknown>, Context<MaybeAccessor<unknown>>>;
10
- declare function bindScope<T>(scope: Scope<T>, context: Context<MaybeAccessor<T>>): void;
11
- declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<AccessedValue<T>>): Scope<AccessedValue<T>>;
12
- declare function useBunja<T>(bunja: MaybeAccessor<Bunja<T, any> | BunjaGetRef<T, any>>, scopeValuePairs?: MaybeAccessor<ScopeValuePairs>): Accessor<T>;
13
- //#endregion
14
- export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
5
+ export declare const BunjaStoreContext: Context<BunjaStore>;
6
+ export declare function BunjaStoreProvider(props: ParentProps): Element;
7
+ export declare const scopeContextMap: Map<Scope<unknown>, Context<MaybeAccessor<unknown>>>;
8
+ export declare function bindScope<T>(scope: Scope<T>, context: Context<MaybeAccessor<T>>): void;
9
+ export declare function createScopeFromContext<T>(context: Context<T>, hash?: HashFn<AccessedValue<T>>): Scope<AccessedValue<T>>;
10
+ export declare function useBunja<T, Seed = undefined>(bunja: MaybeAccessor<Bunja<T, Seed> | BunjaGetRef<T, Seed>>, scopeValuePairs?: MaybeAccessor<ScopeValuePairs>): Accessor<T>;
11
+ export {};
package/dist/solid.js CHANGED
@@ -1,17 +1,17 @@
1
- import { createBunjaStore, createReadScopeFn, createScope } from "./bunja-BmPnlAec.js";
1
+ import { createBunjaStore, createReadScopeFn, createScope } from "./bunja.js";
2
2
  import { createComponent, createContext, createEffect, createMemo, createRoot, getOwner, onCleanup, runWithOwner, useContext } from "solid-js";
3
-
4
- //#region solid.ts
3
+ // solid.ts
4
+ const __DEV__ = process.env.NODE_ENV !== "production";
5
5
  function access(maybeAccessor) {
6
6
  if (typeof maybeAccessor !== "function") return maybeAccessor;
7
7
  return maybeAccessor();
8
8
  }
9
- const BunjaStoreContext = createContext(createBunjaStore({ wrapInstance: createRoot }));
9
+ const BunjaStoreContext = createContext(createBunjaStore({ wrapInstance: (impl) => runWithOwner(null, () => createRoot(impl)) }));
10
10
  function BunjaStoreProvider(props) {
11
11
  const owner = getOwner();
12
- const bunjaStore = createBunjaStore({ wrapInstance: (impl) => createRoot(impl, owner) });
12
+ const bunjaStore = createBunjaStore({ wrapInstance: (impl) => runWithOwner(owner, () => createRoot(impl)) });
13
13
  onCleanup(() => bunjaStore.dispose());
14
- return createComponent(BunjaStoreContext.Provider, {
14
+ return createComponent(BunjaStoreContext, {
15
15
  get value() {
16
16
  return bunjaStore;
17
17
  },
@@ -36,26 +36,32 @@ function useBunja(bunja, scopeValuePairs) {
36
36
  const context = scopeContextMap.get(scope);
37
37
  return access(runWithOwner(owner, () => useContext(context)));
38
38
  };
39
- const readScope = createMemo(() => {
40
- const pairs = access(scopeValuePairs);
41
- return pairs ? createReadScopeFn(pairs, defaultReadScope) : defaultReadScope;
42
- });
43
39
  const entry = createMemo(() => {
44
- const read = readScope();
45
- const scopes = /* @__PURE__ */ new Set();
46
- const result = store.get(access(bunja), (scope) => {
47
- scopes.add(scope);
48
- return read(scope);
40
+ const pairs = access(scopeValuePairs);
41
+ const read = pairs ? createReadScopeFn(pairs, defaultReadScope) : defaultReadScope;
42
+ const resolvedBunja = access(bunja);
43
+ const resolutionOwner = getOwner();
44
+ const scopes = /* @__PURE__ */ new Map();
45
+ const result = store.get(resolvedBunja, (scope) => {
46
+ const key = scope;
47
+ if (!scopes.has(key)) scopes.set(key, runWithOwner(resolutionOwner, () => read(scope)));
48
+ return scopes.get(key);
49
+ });
50
+ for (const scope of scopes.keys()) read(scope);
51
+ if (__DEV__) Object.assign(getOwner(), {
52
+ storeId: store.id,
53
+ bunja: resolvedBunja,
54
+ scopeValuePairs: pairs,
55
+ bunjaInstance: result.bunjaInstance
49
56
  });
50
- for (const scope of scopes) read(scope);
51
57
  return result;
52
58
  });
53
- createEffect(() => {
54
- const cleanup = entry().mount();
55
- onCleanup(() => setTimeout(cleanup));
59
+ createEffect(entry, (resolved) => {
60
+ const cleanup = resolved.mount();
61
+ return () => {
62
+ setTimeout(cleanup);
63
+ };
56
64
  });
57
65
  return () => entry().value;
58
66
  }
59
-
60
- //#endregion
61
- export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
67
+ export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
package/package.json CHANGED
@@ -1,59 +1,33 @@
1
1
  {
2
2
  "name": "bunja",
3
3
  "type": "module",
4
- "version": "3.0.2",
4
+ "version": "4.0.0-alpha.2",
5
5
  "description": "State Lifetime Manager",
6
- "main": "dist/bunja.cjs",
7
- "module": "dist/bunja.js",
6
+ "main": "./dist/bunja.js",
8
7
  "types": "dist/bunja.d.ts",
9
8
  "exports": {
10
9
  ".": {
11
- "import": {
12
- "types": "./dist/bunja.d.ts",
13
- "default": "./dist/bunja.js"
14
- },
15
- "require": {
16
- "types": "./dist/bunja.d.cts",
17
- "default": "./dist/bunja.cjs"
18
- }
10
+ "types": "./dist/bunja.d.ts",
11
+ "default": "./dist/bunja.js"
19
12
  },
20
13
  "./react": {
21
- "import": {
22
- "types": "./dist/react.d.ts",
23
- "default": "./dist/react.js"
24
- },
25
- "require": {
26
- "types": "./dist/react.d.cts",
27
- "default": "./dist/react.cjs"
28
- }
14
+ "types": "./dist/react.d.ts",
15
+ "default": "./dist/react.js"
29
16
  },
30
17
  "./solid": {
31
- "import": {
32
- "types": "./dist/solid.d.ts",
33
- "default": "./dist/solid.js"
34
- },
35
- "require": {
36
- "types": "./dist/solid.d.cts",
37
- "default": "./dist/solid.cjs"
38
- }
39
- }
40
- },
41
- "typesVersions": {
42
- "*": {
43
- "react": [
44
- "./dist/react.d.ts"
45
- ],
46
- "solid": [
47
- "./dist/solid.d.ts"
48
- ],
49
- "*": [
50
- "./dist/bunja.d.ts"
51
- ]
18
+ "types": "./dist/solid.d.ts",
19
+ "default": "./dist/solid.js"
20
+ },
21
+ "./solid/v1-compat": {
22
+ "types": "./dist/solid/v1-compat.d.ts",
23
+ "default": "./dist/solid/v1-compat.js"
52
24
  }
53
25
  },
54
26
  "scripts": {
55
27
  "clean": "rm -rf ./dist",
56
- "build": "tsdown --format cjs && tsdown --format esm --no-clean"
28
+ "build": "tsdown",
29
+ "typecheck": "tsc --noEmit && tsc -p solid/tsconfig.json",
30
+ "test": "node --import tsx --conditions=browser --test test.ts solid_test.ts react_test.ts override_test.ts && node --import tsx --test solid_server_test.ts"
57
31
  },
58
32
  "keywords": [
59
33
  "bunja",
@@ -68,15 +42,19 @@
68
42
  },
69
43
  "devDependencies": {
70
44
  "@types/react": "^19",
45
+ "@types/react-test-renderer": "^19.3.0",
71
46
  "react": "^19",
72
- "solid-js": "^1.9.7",
73
- "tsdown": "^0.12.7",
74
- "typescript": "^5.6.3"
47
+ "react-test-renderer": "^19.3.1",
48
+ "solid-js": "2.0.0-rc.20",
49
+ "tsdown": "0.23.3",
50
+ "typescript": "^5.6.3",
51
+ "tsx": "^4.20.0",
52
+ "solid-js-v1": "npm:solid-js@^1.9.7"
75
53
  },
76
54
  "peerDependencies": {
77
55
  "@types/react": "*",
78
56
  "react": ">=18",
79
- "solid-js": "^1"
57
+ "solid-js": "^1 || ^2.0.0-rc.20"
80
58
  },
81
59
  "peerDependenciesMeta": {
82
60
  "@types/react": {
@@ -88,5 +66,13 @@
88
66
  "solid-js": {
89
67
  "optional": true
90
68
  }
69
+ },
70
+ "files": [
71
+ "dist",
72
+ "README.md",
73
+ "LICENSE"
74
+ ],
75
+ "engines": {
76
+ "node": ">=22.18.0"
91
77
  }
92
78
  }