bunja 3.0.0 → 3.0.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/deno.json +1 -1
- package/dist/solid.cjs +3 -1
- package/dist/solid.js +4 -2
- package/package.json +1 -1
- package/solid.ts +4 -1
- package/test.ts +67 -0
package/deno.json
CHANGED
package/dist/solid.cjs
CHANGED
|
@@ -35,10 +35,12 @@ const defaultReadScope = (scope) => {
|
|
|
35
35
|
return access((0, solid_js.useContext)(scopeContextMap.get(scope)));
|
|
36
36
|
};
|
|
37
37
|
function useBunja(bunja, scopeValuePairs) {
|
|
38
|
+
const owner = (0, solid_js.getOwner)();
|
|
38
39
|
const store = (0, solid_js.useContext)(BunjaStoreContext);
|
|
39
40
|
const readScope = (0, solid_js.createMemo)(() => {
|
|
40
41
|
const pairs = access(scopeValuePairs);
|
|
41
|
-
|
|
42
|
+
const impl = pairs ? require_bunja.createReadScopeFn(pairs, defaultReadScope) : defaultReadScope;
|
|
43
|
+
return (scope) => (0, solid_js.runWithOwner)(owner, () => impl(scope));
|
|
42
44
|
});
|
|
43
45
|
const entry = (0, solid_js.createMemo)(() => store.get(access(bunja), readScope()));
|
|
44
46
|
(0, solid_js.createEffect)(() => {
|
package/dist/solid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBunjaStore, createReadScopeFn, createScope } from "./bunja-BmPnlAec.js";
|
|
2
|
-
import { createComponent, createContext, createEffect, createMemo, createRoot, getOwner, onCleanup, useContext } from "solid-js";
|
|
2
|
+
import { createComponent, createContext, createEffect, createMemo, createRoot, getOwner, onCleanup, runWithOwner, useContext } from "solid-js";
|
|
3
3
|
|
|
4
4
|
//#region solid.ts
|
|
5
5
|
function access(maybeAccessor) {
|
|
@@ -33,10 +33,12 @@ const defaultReadScope = (scope) => {
|
|
|
33
33
|
return access(useContext(scopeContextMap.get(scope)));
|
|
34
34
|
};
|
|
35
35
|
function useBunja(bunja, scopeValuePairs) {
|
|
36
|
+
const owner = getOwner();
|
|
36
37
|
const store = useContext(BunjaStoreContext);
|
|
37
38
|
const readScope = createMemo(() => {
|
|
38
39
|
const pairs = access(scopeValuePairs);
|
|
39
|
-
|
|
40
|
+
const impl = pairs ? createReadScopeFn(pairs, defaultReadScope) : defaultReadScope;
|
|
41
|
+
return (scope) => runWithOwner(owner, () => impl(scope));
|
|
40
42
|
});
|
|
41
43
|
const entry = createMemo(() => store.get(access(bunja), readScope()));
|
|
42
44
|
createEffect(() => {
|
package/package.json
CHANGED
package/solid.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type JSX,
|
|
11
11
|
onCleanup,
|
|
12
12
|
type ParentProps,
|
|
13
|
+
runWithOwner,
|
|
13
14
|
useContext,
|
|
14
15
|
} from "solid-js";
|
|
15
16
|
import {
|
|
@@ -86,12 +87,14 @@ export function useBunja<T>(
|
|
|
86
87
|
bunja: MaybeAccessor<Bunja<T, any> | BunjaGetRef<T, any>>,
|
|
87
88
|
scopeValuePairs?: MaybeAccessor<ScopeValuePairs>,
|
|
88
89
|
): Accessor<T> {
|
|
90
|
+
const owner = getOwner();
|
|
89
91
|
const store = useContext(BunjaStoreContext);
|
|
90
92
|
const readScope = createMemo(() => {
|
|
91
93
|
const pairs = access(scopeValuePairs);
|
|
92
|
-
|
|
94
|
+
const impl = pairs
|
|
93
95
|
? createReadScopeFn(pairs, defaultReadScope)
|
|
94
96
|
: defaultReadScope;
|
|
97
|
+
return <T>(scope: Scope<T>) => runWithOwner(owner, () => impl(scope)) as T;
|
|
95
98
|
});
|
|
96
99
|
const entry = createMemo(() => store.get(access(bunja), readScope()));
|
|
97
100
|
createEffect(() => {
|
package/test.ts
CHANGED
|
@@ -81,6 +81,39 @@ Deno.test({
|
|
|
81
81
|
},
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
+
Deno.test({
|
|
85
|
+
name: "dependency effects mount and cleanup before consumer effects",
|
|
86
|
+
fn() {
|
|
87
|
+
const store = createBunjaStore();
|
|
88
|
+
const order: string[] = [];
|
|
89
|
+
const dependencyBunja = bunja(() => {
|
|
90
|
+
bunja.effect(() => {
|
|
91
|
+
order.push("dependency mount");
|
|
92
|
+
return () => order.push("dependency cleanup");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
const consumerBunja = bunja(() => {
|
|
96
|
+
bunja.use(dependencyBunja);
|
|
97
|
+
bunja.effect(() => {
|
|
98
|
+
order.push("consumer mount");
|
|
99
|
+
return () => order.push("consumer cleanup");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const { mount } = store.get(consumerBunja, readNull);
|
|
104
|
+
const cleanup = mount();
|
|
105
|
+
assertEquals(order, ["dependency mount", "consumer mount"]);
|
|
106
|
+
|
|
107
|
+
cleanup();
|
|
108
|
+
assertEquals(order, [
|
|
109
|
+
"dependency mount",
|
|
110
|
+
"consumer mount",
|
|
111
|
+
"dependency cleanup",
|
|
112
|
+
"consumer cleanup",
|
|
113
|
+
]);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
84
117
|
Deno.test({
|
|
85
118
|
name: "A mount first, B mount later & A unmount first, B unmount later",
|
|
86
119
|
fn() {
|
|
@@ -480,6 +513,40 @@ Deno.test({
|
|
|
480
513
|
},
|
|
481
514
|
});
|
|
482
515
|
|
|
516
|
+
Deno.test({
|
|
517
|
+
name: "active bunja.will dependency effects cleanup before consumer effects",
|
|
518
|
+
fn() {
|
|
519
|
+
const store = createBunjaStore();
|
|
520
|
+
const order: string[] = [];
|
|
521
|
+
const dependencyBunja = bunja(() => {
|
|
522
|
+
bunja.effect(() => {
|
|
523
|
+
order.push("dependency mount");
|
|
524
|
+
return () => order.push("dependency cleanup");
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
const consumerBunja = bunja(() => {
|
|
528
|
+
const getDependency = bunja.will(dependencyBunja);
|
|
529
|
+
getDependency();
|
|
530
|
+
bunja.effect(() => {
|
|
531
|
+
order.push("consumer mount");
|
|
532
|
+
return () => order.push("consumer cleanup");
|
|
533
|
+
});
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
const { mount } = store.get(consumerBunja, readNull);
|
|
537
|
+
const cleanup = mount();
|
|
538
|
+
assertEquals(order, ["dependency mount", "consumer mount"]);
|
|
539
|
+
|
|
540
|
+
cleanup();
|
|
541
|
+
assertEquals(order, [
|
|
542
|
+
"dependency mount",
|
|
543
|
+
"consumer mount",
|
|
544
|
+
"dependency cleanup",
|
|
545
|
+
"consumer cleanup",
|
|
546
|
+
]);
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
|
|
483
550
|
Deno.test({
|
|
484
551
|
name: "bunja.will records optional refs once when thunk is used",
|
|
485
552
|
fn() {
|