@fun-land/fun-web 0.2.0 → 0.3.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/README.md +45 -17
- package/dist/esm/src/dom.d.ts +16 -9
- package/dist/esm/src/dom.js +14 -4
- package/dist/esm/src/dom.js.map +1 -1
- package/dist/esm/src/index.d.ts +1 -1
- package/dist/esm/src/index.js +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/tsconfig.publish.tsbuildinfo +1 -1
- package/dist/src/dom.d.ts +16 -9
- package/dist/src/dom.js +18 -6
- package/dist/src/dom.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +1 -1
- package/dist/tsconfig.publish.tsbuildinfo +1 -1
- package/examples/README.md +4 -4
- package/examples/counter/counter.ts +2 -2
- package/examples/todo-app/Todo.ts +33 -46
- package/examples/todo-app/todo-app.ts +32 -35
- package/package.json +9 -7
- package/src/dom.test.ts +23 -25
- package/src/dom.ts +44 -21
- package/src/index.ts +3 -1
- package/src/mount.test.ts +4 -4
- package/src/state.test.ts +44 -18
- package/tsconfig.json +1 -1
package/src/state.test.ts
CHANGED
|
@@ -38,10 +38,13 @@ describe("funState", () => {
|
|
|
38
38
|
const controller = new AbortController();
|
|
39
39
|
const callback = jest.fn();
|
|
40
40
|
|
|
41
|
-
state.
|
|
41
|
+
state.watch(controller.signal, callback);
|
|
42
42
|
state.set({ count: 1 });
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
// Called with initial value, then with new value
|
|
45
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
46
|
+
expect(callback).toHaveBeenNthCalledWith(1, { count: 0 });
|
|
47
|
+
expect(callback).toHaveBeenNthCalledWith(2, { count: 1 });
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
it("should call subscriber multiple times", () => {
|
|
@@ -49,13 +52,15 @@ describe("funState", () => {
|
|
|
49
52
|
const controller = new AbortController();
|
|
50
53
|
const callback = jest.fn();
|
|
51
54
|
|
|
52
|
-
state.
|
|
55
|
+
state.watch(controller.signal, callback);
|
|
53
56
|
state.set({ count: 1 });
|
|
54
57
|
state.set({ count: 2 });
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
expect(callback).
|
|
58
|
-
expect(callback).toHaveBeenNthCalledWith(
|
|
59
|
+
// watch calls immediately with initial value, then on each change
|
|
60
|
+
expect(callback).toHaveBeenCalledTimes(3);
|
|
61
|
+
expect(callback).toHaveBeenNthCalledWith(1, { count: 0 });
|
|
62
|
+
expect(callback).toHaveBeenNthCalledWith(2, { count: 1 });
|
|
63
|
+
expect(callback).toHaveBeenNthCalledWith(3, { count: 2 });
|
|
59
64
|
});
|
|
60
65
|
|
|
61
66
|
it("should call focused state subscriber only when that property changes", () => {
|
|
@@ -64,7 +69,10 @@ describe("funState", () => {
|
|
|
64
69
|
const controller = new AbortController();
|
|
65
70
|
const callback = jest.fn();
|
|
66
71
|
|
|
67
|
-
countState.
|
|
72
|
+
countState.watch(controller.signal, callback);
|
|
73
|
+
|
|
74
|
+
// Initial call with 0
|
|
75
|
+
expect(callback).toHaveBeenCalledWith(0);
|
|
68
76
|
|
|
69
77
|
// Change count - should trigger
|
|
70
78
|
state.set({ count: 1, name: "test" });
|
|
@@ -86,13 +94,18 @@ describe("funState", () => {
|
|
|
86
94
|
const callback1 = jest.fn();
|
|
87
95
|
const callback2 = jest.fn();
|
|
88
96
|
|
|
89
|
-
state.
|
|
90
|
-
state.
|
|
97
|
+
state.watch(controller.signal, callback1);
|
|
98
|
+
state.watch(controller.signal, callback2);
|
|
91
99
|
|
|
92
100
|
state.set({ count: 1 });
|
|
93
101
|
|
|
94
|
-
|
|
95
|
-
expect(
|
|
102
|
+
// Both should be called with initial value, then with new value
|
|
103
|
+
expect(callback1).toHaveBeenCalledTimes(2);
|
|
104
|
+
expect(callback1).toHaveBeenNthCalledWith(1, { count: 0 });
|
|
105
|
+
expect(callback1).toHaveBeenNthCalledWith(2, { count: 1 });
|
|
106
|
+
expect(callback2).toHaveBeenCalledTimes(2);
|
|
107
|
+
expect(callback2).toHaveBeenNthCalledWith(1, { count: 0 });
|
|
108
|
+
expect(callback2).toHaveBeenNthCalledWith(2, { count: 1 });
|
|
96
109
|
});
|
|
97
110
|
|
|
98
111
|
it("should work with accessor-based focus", () => {
|
|
@@ -105,11 +118,14 @@ describe("funState", () => {
|
|
|
105
118
|
const controller = new AbortController();
|
|
106
119
|
const callback = jest.fn();
|
|
107
120
|
|
|
108
|
-
nameState.
|
|
121
|
+
nameState.watch(controller.signal, callback);
|
|
109
122
|
|
|
110
123
|
state.set({ name: "Bob", age: 30 });
|
|
111
124
|
|
|
112
|
-
|
|
125
|
+
// Called with initial value "Alice", then "Bob"
|
|
126
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
127
|
+
expect(callback).toHaveBeenNthCalledWith(1, "Alice");
|
|
128
|
+
expect(callback).toHaveBeenNthCalledWith(2, "Bob");
|
|
113
129
|
});
|
|
114
130
|
});
|
|
115
131
|
|
|
@@ -178,11 +194,14 @@ describe("funState", () => {
|
|
|
178
194
|
const controller = new AbortController();
|
|
179
195
|
const callback = jest.fn();
|
|
180
196
|
|
|
181
|
-
nameState.
|
|
197
|
+
nameState.watch(controller.signal, callback);
|
|
182
198
|
|
|
183
199
|
state.set({ user: { profile: { name: "Bob" } } });
|
|
184
200
|
|
|
185
|
-
|
|
201
|
+
// Called with initial value "Alice", then "Bob"
|
|
202
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
203
|
+
expect(callback).toHaveBeenNthCalledWith(1, "Alice");
|
|
204
|
+
expect(callback).toHaveBeenNthCalledWith(2, "Bob");
|
|
186
205
|
|
|
187
206
|
controller.abort();
|
|
188
207
|
});
|
|
@@ -207,17 +226,24 @@ describe("funState", () => {
|
|
|
207
226
|
const controller = new AbortController();
|
|
208
227
|
const callback = jest.fn();
|
|
209
228
|
|
|
210
|
-
nameState.
|
|
229
|
+
nameState.watch(controller.signal, callback);
|
|
230
|
+
|
|
231
|
+
// Initial call with "Alice"
|
|
232
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
233
|
+
expect(callback).toHaveBeenCalledWith("Alice");
|
|
234
|
+
|
|
235
|
+
callback.mockClear();
|
|
211
236
|
|
|
212
|
-
// Change age, not name
|
|
237
|
+
// Change age, not name - should not trigger again
|
|
213
238
|
state.set({ user: { profile: { name: "Alice", age: 31 } } });
|
|
214
239
|
|
|
215
240
|
expect(callback).not.toHaveBeenCalled();
|
|
216
241
|
|
|
217
|
-
// Change name
|
|
242
|
+
// Change name - should trigger
|
|
218
243
|
state.set({ user: { profile: { name: "Bob", age: 31 } } });
|
|
219
244
|
|
|
220
245
|
expect(callback).toHaveBeenCalledWith("Bob");
|
|
246
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
221
247
|
|
|
222
248
|
controller.abort();
|
|
223
249
|
});
|