@ryupold/vode 1.8.6 → 1.8.8
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/README.md +34 -56
- package/dist/vode.cjs.min.js +2 -2
- package/dist/vode.d.ts +6 -10
- package/dist/vode.es5.min.js +7 -7
- package/dist/vode.js +84 -138
- package/dist/vode.min.js +1 -1
- package/dist/vode.min.mjs +1 -1
- package/dist/vode.mjs +84 -138
- package/package.json +1 -1
- package/src/state-context.ts +6 -4
- package/src/vode.ts +105 -156
- package/test/helper.ts +78 -32
- package/test/index.ts +41 -16
- package/test/mocks.ts +132 -38
- package/test/tests-app.ts +117 -1
- package/test/tests-catch.ts +160 -0
- package/test/tests-defuse.ts +22 -1
- package/test/tests-examples.ts +992 -0
- package/test/tests-hydrate.ts +43 -9
- package/test/tests-memo.ts +91 -50
- package/test/tests-mount-unmount.ts +265 -1
- package/test/tests-patch-advanced.ts +84 -0
- package/test/tests-patch-merge.ts +66 -0
- package/test/tests-state-context.ts +32 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expect } from "./helper";
|
|
2
|
+
import { app, createState, DIV } from "../index";
|
|
3
|
+
|
|
4
|
+
function setup() {
|
|
5
|
+
const root = document.createElement("div");
|
|
6
|
+
const container = document.createElement("div");
|
|
7
|
+
root.appendChild(container);
|
|
8
|
+
return container;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
"patch-merge: array property replaces existing array": () => {
|
|
13
|
+
const container = setup();
|
|
14
|
+
const state: any = createState({ items: [1, 2, 3] });
|
|
15
|
+
app(container, state, () => [DIV]);
|
|
16
|
+
|
|
17
|
+
state.patch({ items: [4, 5, 6] });
|
|
18
|
+
|
|
19
|
+
expect(state.items).toEqual([4, 5, 6]);
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
"patch-merge: Date property stores correctly": () => {
|
|
23
|
+
const container = setup();
|
|
24
|
+
const state: any = createState({ date: new Date("2024-01-01") });
|
|
25
|
+
app(container, state, () => [DIV]);
|
|
26
|
+
|
|
27
|
+
state.patch({ date: new Date("2025-06-15") });
|
|
28
|
+
|
|
29
|
+
expect(state.date instanceof Date).toEqual(true);
|
|
30
|
+
expect(state.date.getFullYear()).toEqual(2025);
|
|
31
|
+
expect(state.date.getMonth()).toEqual(5);
|
|
32
|
+
expect(state.date.getDate()).toEqual(15);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
"patch-merge: object replaces existing array property": () => {
|
|
36
|
+
const container = setup();
|
|
37
|
+
const state: any = createState({ data: [1, 2, 3] });
|
|
38
|
+
app(container, state, () => [DIV]);
|
|
39
|
+
|
|
40
|
+
state.patch({ data: { key: "value" } });
|
|
41
|
+
|
|
42
|
+
expect(Array.isArray(state.data)).toEqual(false);
|
|
43
|
+
expect(state.data.key).toEqual("value");
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
"patch-merge: object replaces existing primitive property": () => {
|
|
47
|
+
const container = setup();
|
|
48
|
+
const state: any = createState({ value: 42 });
|
|
49
|
+
app(container, state, () => [DIV]);
|
|
50
|
+
|
|
51
|
+
state.patch({ value: { nested: true } });
|
|
52
|
+
|
|
53
|
+
expect(state.value.nested).toEqual(true);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
"patch-merge: new array property via patch": () => {
|
|
57
|
+
const container = setup();
|
|
58
|
+
const state: any = createState({ name: "test" });
|
|
59
|
+
app(container, state, () => [DIV]);
|
|
60
|
+
|
|
61
|
+
state.patch({ tags: ["a", "b", "c"] });
|
|
62
|
+
|
|
63
|
+
expect(Array.isArray(state.tags)).toEqual(true);
|
|
64
|
+
expect(state.tags).toEqual(["a", "b", "c"]);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from "./helper";
|
|
2
|
-
import { context } from "../src/state-context";
|
|
2
|
+
import { context, ProxySubContext } from "../src/state-context";
|
|
3
3
|
import { createState } from "../src/vode";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
@@ -103,4 +103,35 @@ export default {
|
|
|
103
103
|
expect(patches[0])
|
|
104
104
|
.toEqual({ x: { y: { z: 100 } } });
|
|
105
105
|
},
|
|
106
|
+
|
|
107
|
+
"StateContext.put() with intermediate null creates objects along the path": () => {
|
|
108
|
+
const state = createState({ a: null as { b: number } | null });
|
|
109
|
+
const ctx = context(state);
|
|
110
|
+
|
|
111
|
+
ctx.a.b.put(42);
|
|
112
|
+
expect(state.a?.b).toEqual(42);
|
|
113
|
+
|
|
114
|
+
ctx.a.put(null);
|
|
115
|
+
expect(state.a).toEqual(null);
|
|
116
|
+
expect(state.a?.b).toEqual(undefined);
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
"StateContext.put() with three-level intermediate null": () => {
|
|
120
|
+
const state = createState({ a: null as { b: { c: number } } | null });
|
|
121
|
+
const ctx = context(state);
|
|
122
|
+
|
|
123
|
+
ctx.a.b.c.put(99);
|
|
124
|
+
|
|
125
|
+
expect(state.a?.b.c).toEqual(99);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
"StateContext.put() with multiple intermediate nulls": () => {
|
|
129
|
+
const state = createState({ a: { x: null as { z: string } | null, y: 1 } });
|
|
130
|
+
const ctx = context(state);
|
|
131
|
+
|
|
132
|
+
ctx.a.x.z.put("deep");
|
|
133
|
+
|
|
134
|
+
expect(state.a.x?.z).toEqual("deep");
|
|
135
|
+
expect(state.a.y).toEqual(1);
|
|
136
|
+
},
|
|
106
137
|
};
|