bunja 3.0.1 → 4.0.0-alpha.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/dist/bunja.d.ts +214 -2
- package/dist/bunja.js +780 -3
- package/dist/react.d.ts +7 -13
- package/dist/react.js +7 -10
- package/dist/solid.d.ts +8 -11
- package/dist/solid.js +29 -12
- package/package.json +24 -43
- package/bunja.ts +0 -1199
- package/deno.json +0 -17
- package/dist/bunja-B81fiP3K.d.cts +0 -192
- package/dist/bunja-BmPnlAec.js +0 -636
- package/dist/bunja-DJPGfe5j.cjs +0 -684
- package/dist/bunja-pdetyCM3.d.ts +0 -192
- package/dist/bunja.cjs +0 -10
- package/dist/bunja.d.cts +0 -2
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/react.cjs +0 -74
- package/dist/react.d.cts +0 -15
- package/dist/solid.cjs +0 -59
- package/dist/solid.d.cts +0 -14
- package/react.ts +0 -113
- package/solid.ts +0 -105
- package/test.ts +0 -868
- package/tsconfig.json +0 -13
- package/tsdown.config.ts +0 -10
package/dist/react.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja
|
|
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
|
-
|
|
6
|
-
declare const
|
|
7
|
-
declare function
|
|
8
|
-
|
|
9
|
-
|
|
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 };
|
package/dist/solid.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja
|
|
1
|
+
import { Bunja, BunjaGetRef, BunjaStore, HashFn, Scope, ScopeValuePairs } from "./bunja.js";
|
|
2
2
|
import { Accessor, Context, JSX, ParentProps } from "solid-js";
|
|
3
|
-
|
|
4
|
-
//#region solid.d.ts
|
|
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
|
-
|
|
14
|
-
export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
|
|
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>(bunja: MaybeAccessor<Bunja<T, any> | BunjaGetRef<T, any>>, scopeValuePairs?: MaybeAccessor<ScopeValuePairs>): Accessor<T>;
|
|
11
|
+
export {};
|
package/dist/solid.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { createBunjaStore, createReadScopeFn, createScope } from "./bunja
|
|
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
|
-
|
|
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();
|
|
@@ -29,24 +29,41 @@ function createScopeFromContext(context, hash) {
|
|
|
29
29
|
bindScope(scope, context);
|
|
30
30
|
return scope;
|
|
31
31
|
}
|
|
32
|
-
const defaultReadScope = (scope) => {
|
|
33
|
-
return access(useContext(scopeContextMap.get(scope)));
|
|
34
|
-
};
|
|
35
32
|
function useBunja(bunja, scopeValuePairs) {
|
|
36
33
|
const owner = getOwner();
|
|
37
34
|
const store = useContext(BunjaStoreContext);
|
|
35
|
+
const defaultReadScope = (scope) => {
|
|
36
|
+
const context = scopeContextMap.get(scope);
|
|
37
|
+
return access(runWithOwner(owner, () => useContext(context)));
|
|
38
|
+
};
|
|
38
39
|
const readScope = createMemo(() => {
|
|
39
40
|
const pairs = access(scopeValuePairs);
|
|
40
|
-
|
|
41
|
-
|
|
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;
|
|
42
62
|
});
|
|
43
|
-
const entry = createMemo(() => store.get(access(bunja), readScope()));
|
|
44
63
|
createEffect(() => {
|
|
45
64
|
const cleanup = entry().mount();
|
|
46
65
|
onCleanup(() => setTimeout(cleanup));
|
|
47
66
|
});
|
|
48
67
|
return () => entry().value;
|
|
49
68
|
}
|
|
50
|
-
|
|
51
|
-
//#endregion
|
|
52
|
-
export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
|
|
69
|
+
export { BunjaStoreContext, BunjaStoreProvider, bindScope, createScopeFromContext, scopeContextMap, useBunja };
|
package/package.json
CHANGED
|
@@ -1,59 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunja",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-alpha.1",
|
|
5
5
|
"description": "State Lifetime Manager",
|
|
6
|
-
"main": "dist/bunja.
|
|
7
|
-
"module": "dist/bunja.js",
|
|
6
|
+
"main": "./dist/bunja.js",
|
|
8
7
|
"types": "dist/bunja.d.ts",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
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
|
-
"
|
|
22
|
-
|
|
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
|
-
"
|
|
32
|
-
|
|
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"
|
|
52
20
|
}
|
|
53
21
|
},
|
|
54
22
|
"scripts": {
|
|
55
23
|
"clean": "rm -rf ./dist",
|
|
56
|
-
"build": "tsdown
|
|
24
|
+
"build": "tsdown",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"test": "node --import tsx --conditions=browser --test test.ts solid_test.ts react_test.ts override_test.ts"
|
|
57
27
|
},
|
|
58
28
|
"keywords": [
|
|
59
29
|
"bunja",
|
|
@@ -68,10 +38,13 @@
|
|
|
68
38
|
},
|
|
69
39
|
"devDependencies": {
|
|
70
40
|
"@types/react": "^19",
|
|
41
|
+
"@types/react-test-renderer": "^19.3.0",
|
|
71
42
|
"react": "^19",
|
|
43
|
+
"react-test-renderer": "^19.3.1",
|
|
72
44
|
"solid-js": "^1.9.7",
|
|
73
|
-
"tsdown": "
|
|
74
|
-
"typescript": "^5.6.3"
|
|
45
|
+
"tsdown": "0.23.3",
|
|
46
|
+
"typescript": "^5.6.3",
|
|
47
|
+
"tsx": "^4.20.0"
|
|
75
48
|
},
|
|
76
49
|
"peerDependencies": {
|
|
77
50
|
"@types/react": "*",
|
|
@@ -88,5 +61,13 @@
|
|
|
88
61
|
"solid-js": {
|
|
89
62
|
"optional": true
|
|
90
63
|
}
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"dist",
|
|
67
|
+
"README.md",
|
|
68
|
+
"LICENSE"
|
|
69
|
+
],
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=22.18.0"
|
|
91
72
|
}
|
|
92
73
|
}
|