ripple 0.2.151 → 0.2.153
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 +3 -3
- package/package.json +5 -5
- package/src/compiler/phases/1-parse/index.js +1 -1
- package/src/compiler/phases/3-transform/client/index.js +37 -16
- package/src/compiler/phases/3-transform/server/index.js +43 -25
- package/src/runtime/internal/client/events.js +5 -1
- package/src/runtime/internal/client/index.js +2 -1
- package/src/runtime/internal/client/render.js +18 -15
- package/src/runtime/internal/client/runtime.js +78 -10
- package/src/runtime/internal/server/index.js +51 -11
- package/src/server/index.js +1 -1
- package/tests/client/array/array.derived.test.ripple +61 -33
- package/tests/client/array/array.iteration.test.ripple +3 -1
- package/tests/client/array/array.mutations.test.ripple +19 -15
- package/tests/client/array/array.static.test.ripple +115 -104
- package/tests/client/array/array.to-methods.test.ripple +3 -3
- package/tests/client/basic/basic.attributes.test.ripple +110 -57
- package/tests/client/basic/basic.collections.test.ripple +41 -22
- package/tests/client/basic/basic.errors.test.ripple +12 -6
- package/tests/client/basic/basic.events.test.ripple +51 -33
- package/tests/client/basic/basic.reactivity.test.ripple +120 -56
- package/tests/client/basic/basic.rendering.test.ripple +49 -19
- package/tests/client/basic/basic.styling.test.ripple +2 -2
- package/tests/client/basic/basic.utilities.test.ripple +1 -1
- package/tests/client/boundaries.test.ripple +70 -58
- package/tests/client/compiler/compiler.assignments.test.ripple +32 -4
- package/tests/client/compiler/compiler.attributes.test.ripple +46 -46
- package/tests/client/compiler/compiler.basic.test.ripple +18 -15
- package/tests/client/compiler/compiler.tracked-access.test.ripple +53 -42
- package/tests/client/compiler/compiler.typescript.test.ripple +1 -2
- package/tests/client/composite/composite.dynamic-components.test.ripple +6 -6
- package/tests/client/composite/composite.generics.test.ripple +39 -36
- package/tests/client/composite/composite.props.test.ripple +4 -3
- package/tests/client/composite/composite.reactivity.test.ripple +112 -27
- package/tests/client/composite/composite.render.test.ripple +9 -8
- package/tests/client/computed-properties.test.ripple +24 -24
- package/tests/client/context.test.ripple +11 -9
- package/tests/client/date.test.ripple +3 -1
- package/tests/client/dynamic-elements.test.ripple +103 -78
- package/tests/client/for.test.ripple +27 -17
- package/tests/client/head.test.ripple +42 -6
- package/tests/client/html.test.ripple +42 -32
- package/tests/client/input-value.test.ripple +4 -4
- package/tests/client/map.test.ripple +140 -141
- package/tests/client/media-query.test.ripple +31 -31
- package/tests/client/object.test.ripple +148 -112
- package/tests/client/portal.test.ripple +29 -15
- package/tests/client/ref.test.ripple +9 -3
- package/tests/client/set.test.ripple +111 -111
- package/tests/client/tracked-expression.test.ripple +16 -17
- package/tests/client/url/url.derived.test.ripple +19 -9
- package/tests/client/url/url.parsing.test.ripple +24 -8
- package/tests/client/url/url.partial-removal.test.ripple +12 -4
- package/tests/client/url/url.reactivity.test.ripple +63 -25
- package/tests/client/url/url.serialization.test.ripple +18 -6
- package/tests/client/url-search-params/url-search-params.derived.test.ripple +10 -6
- package/tests/client/url-search-params/url-search-params.iteration.test.ripple +3 -1
- package/tests/client/url-search-params/url-search-params.mutation.test.ripple +26 -14
- package/tests/client/url-search-params/url-search-params.tracked-url.test.ripple +3 -1
- package/tests/server/await.test.ripple +23 -22
- package/tests/server/basic.test.ripple +1 -1
- package/tests/server/compiler.test.ripple +3 -7
- package/tests/server/composite.test.ripple +38 -36
- package/tests/server/for.test.ripple +9 -5
- package/tests/server/if.test.ripple +1 -1
- package/tests/server/streaming-ssr.test.ripple +67 -0
- package/types/server.d.ts +5 -4
|
@@ -4,8 +4,8 @@ describe('TrackedArray > derived', () => {
|
|
|
4
4
|
it('handles array methods that return values (map, filter, etc.)', () => {
|
|
5
5
|
component ArrayTest() {
|
|
6
6
|
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
7
|
-
let doubled = track(() => items.map(x => x * 2));
|
|
8
|
-
let filtered = track(() => items.filter(x =>
|
|
7
|
+
let doubled = track(() => items.map((x) => x * 2));
|
|
8
|
+
let filtered = track(() => items.filter((x) => x % 2 === 0));
|
|
9
9
|
let reduced = track(() => items.reduce((acc, val) => acc + val, 0));
|
|
10
10
|
let includes = track(() => items.includes(3));
|
|
11
11
|
|
|
@@ -91,13 +91,17 @@ describe('TrackedArray > derived', () => {
|
|
|
91
91
|
it('handles find and findIndex methods with reactivity', () => {
|
|
92
92
|
component ArrayTest() {
|
|
93
93
|
let items = new TrackedArray(5, 10, 15, 20, 25);
|
|
94
|
-
let found = track(() => items.find(x => x > 12));
|
|
95
|
-
let foundIndex = track(() => items.findIndex(x => x > 12));
|
|
96
|
-
|
|
97
|
-
<button
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
let found = track(() => items.find((x) => x > 12));
|
|
95
|
+
let foundIndex = track(() => items.findIndex((x) => x > 12));
|
|
96
|
+
|
|
97
|
+
<button
|
|
98
|
+
onClick={() => {
|
|
99
|
+
items[1] = 13;
|
|
100
|
+
items[0] = 6;
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
{'update values'}
|
|
104
|
+
</button>
|
|
101
105
|
<pre>{@found}</pre>
|
|
102
106
|
<pre>{@foundIndex}</pre>
|
|
103
107
|
}
|
|
@@ -121,13 +125,17 @@ describe('TrackedArray > derived', () => {
|
|
|
121
125
|
it('handles findLast and findLastIndex methods with reactivity', () => {
|
|
122
126
|
component ArrayTest() {
|
|
123
127
|
let items = new TrackedArray(5, 15, 10, 20, 15);
|
|
124
|
-
let foundLast = track(() => items.findLast(x => x === 15));
|
|
125
|
-
let foundLastIndex = track(() => items.findLastIndex(x => x === 15));
|
|
126
|
-
|
|
127
|
-
<button
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
let foundLast = track(() => items.findLast((x) => x === 15));
|
|
129
|
+
let foundLastIndex = track(() => items.findLastIndex((x) => x === 15));
|
|
130
|
+
|
|
131
|
+
<button
|
|
132
|
+
onClick={() => {
|
|
133
|
+
items[1] = 25;
|
|
134
|
+
items[4] = 15;
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{'update values'}
|
|
138
|
+
</button>
|
|
131
139
|
<pre>{@foundLast}</pre>
|
|
132
140
|
<pre>{@foundLastIndex}</pre>
|
|
133
141
|
}
|
|
@@ -151,13 +159,17 @@ describe('TrackedArray > derived', () => {
|
|
|
151
159
|
it('handles every method with reactivity', () => {
|
|
152
160
|
component ArrayTest() {
|
|
153
161
|
let items = new TrackedArray(2, 4, 6, 8);
|
|
154
|
-
let allEven = track(() => items.every(x => x % 2 === 0));
|
|
162
|
+
let allEven = track(() => items.every((x) => x % 2 === 0));
|
|
155
163
|
|
|
156
164
|
<button onClick={() => items.push(3)}>{'add odd'}</button>
|
|
157
|
-
<button
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
165
|
+
<button
|
|
166
|
+
onClick={() => {
|
|
167
|
+
items.pop();
|
|
168
|
+
items.push(10);
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
{'ensure all even'}
|
|
172
|
+
</button>
|
|
161
173
|
<pre>{@allEven.toString()}</pre>
|
|
162
174
|
}
|
|
163
175
|
|
|
@@ -209,7 +221,7 @@ describe('TrackedArray > derived', () => {
|
|
|
209
221
|
it('handles flatMap method with reactivity', () => {
|
|
210
222
|
component ArrayTest() {
|
|
211
223
|
let items = new TrackedArray(1, 2, 3);
|
|
212
|
-
let flatMapped = track(() => items.flatMap(x => [x, x * 2]));
|
|
224
|
+
let flatMapped = track(() => items.flatMap((x) => [x, x * 2]));
|
|
213
225
|
|
|
214
226
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
215
227
|
<pre>{JSON.stringify(items)}</pre>
|
|
@@ -254,7 +266,9 @@ describe('TrackedArray > derived', () => {
|
|
|
254
266
|
addButton.click();
|
|
255
267
|
flushSync();
|
|
256
268
|
|
|
257
|
-
expect(container.querySelectorAll('pre')[0].textContent).toBe(
|
|
269
|
+
expect(container.querySelectorAll('pre')[0].textContent).toBe(
|
|
270
|
+
'["apple","banana","cherry","date"]',
|
|
271
|
+
);
|
|
258
272
|
expect(container.querySelectorAll('pre')[1].textContent).toBe('apple, banana, cherry, date');
|
|
259
273
|
});
|
|
260
274
|
|
|
@@ -263,9 +277,13 @@ describe('TrackedArray > derived', () => {
|
|
|
263
277
|
let items = new TrackedArray(1, 2, 3, 2, 1);
|
|
264
278
|
let lastIndex = track(() => items.lastIndexOf(2));
|
|
265
279
|
|
|
266
|
-
<button
|
|
267
|
-
|
|
268
|
-
|
|
280
|
+
<button
|
|
281
|
+
onClick={() => {
|
|
282
|
+
items.push(2);
|
|
283
|
+
}}
|
|
284
|
+
>
|
|
285
|
+
{'add duplicate'}
|
|
286
|
+
</button>
|
|
269
287
|
<pre>{JSON.stringify(items)}</pre>
|
|
270
288
|
<pre>{@lastIndex}</pre>
|
|
271
289
|
}
|
|
@@ -315,13 +333,17 @@ describe('TrackedArray > derived', () => {
|
|
|
315
333
|
it('handles some method with reactivity', () => {
|
|
316
334
|
component ArrayTest() {
|
|
317
335
|
let items = new TrackedArray(1, 3, 5, 7);
|
|
318
|
-
let hasEven = track(() => items.some(x => x % 2 === 0));
|
|
336
|
+
let hasEven = track(() => items.some((x) => x % 2 === 0));
|
|
319
337
|
|
|
320
338
|
<button onClick={() => items.push(2)}>{'add even'}</button>
|
|
321
|
-
<button
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
339
|
+
<button
|
|
340
|
+
onClick={() => {
|
|
341
|
+
items.pop();
|
|
342
|
+
items.push(9);
|
|
343
|
+
}}
|
|
344
|
+
>
|
|
345
|
+
{'ensure all odd'}
|
|
346
|
+
</button>
|
|
325
347
|
<pre>{@hasEven.toString()}</pre>
|
|
326
348
|
}
|
|
327
349
|
|
|
@@ -349,7 +371,13 @@ describe('TrackedArray > derived', () => {
|
|
|
349
371
|
let items = new TrackedArray(1000, 2000, 3000);
|
|
350
372
|
let localized = track(() => items.toLocaleString('en-US'));
|
|
351
373
|
|
|
352
|
-
<button
|
|
374
|
+
<button
|
|
375
|
+
onClick={() => {
|
|
376
|
+
items[2] = 4000;
|
|
377
|
+
}}
|
|
378
|
+
>
|
|
379
|
+
{'add item'}
|
|
380
|
+
</button>
|
|
353
381
|
<pre>{JSON.stringify(items)}</pre>
|
|
354
382
|
<pre>{@localized}</pre>
|
|
355
383
|
}
|
|
@@ -397,7 +425,7 @@ describe('TrackedArray > derived', () => {
|
|
|
397
425
|
});
|
|
398
426
|
|
|
399
427
|
it('handles with method with reactivity', (context) => {
|
|
400
|
-
if (!
|
|
428
|
+
if (!'with' in Array.prototype) {
|
|
401
429
|
context.skip();
|
|
402
430
|
}
|
|
403
431
|
|
|
@@ -24,7 +24,9 @@ describe('TrackedArray > iteration', () => {
|
|
|
24
24
|
flushSync();
|
|
25
25
|
|
|
26
26
|
expect(container.querySelectorAll('pre')[0].textContent).toBe('["a","b","c","d"]');
|
|
27
|
-
expect(container.querySelectorAll('pre')[1].textContent).toBe(
|
|
27
|
+
expect(container.querySelectorAll('pre')[1].textContent).toBe(
|
|
28
|
+
'[[0,"a"],[1,"b"],[2,"c"],[3,"d"]]',
|
|
29
|
+
);
|
|
28
30
|
});
|
|
29
31
|
|
|
30
32
|
it('handles keys method with reactivity', () => {
|
|
@@ -7,7 +7,7 @@ describe('TrackedArray > mutations', () => {
|
|
|
7
7
|
|
|
8
8
|
<button onClick={() => items[items.length] = items.length + 1}>{'increment'}</button>
|
|
9
9
|
|
|
10
|
-
<Child
|
|
10
|
+
<Child {items} />
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
component Child({ items }: { items: TrackedArray<number> }) {
|
|
@@ -15,21 +15,21 @@ describe('TrackedArray > mutations', () => {
|
|
|
15
15
|
<pre>{items.length}</pre>
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
render(ArrayTest);
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const button = container.querySelector('button');
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
button.click();
|
|
23
|
+
flushSync();
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,3,4]');
|
|
26
|
+
expect(container.querySelectorAll('pre')[1].textContent).toBe('4');
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
button.click();
|
|
29
|
+
flushSync();
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,3,4,5]');
|
|
32
|
+
expect(container.querySelectorAll('pre')[1].textContent).toBe('5');
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it('handles push and pop operations with reactivity', () => {
|
|
@@ -44,7 +44,7 @@ describe('TrackedArray > mutations', () => {
|
|
|
44
44
|
<pre>{@lastItem}</pre>
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
render(ArrayTest);
|
|
48
48
|
|
|
49
49
|
const pushButton = container.querySelectorAll('button')[0];
|
|
50
50
|
const popButton = container.querySelectorAll('button')[1];
|
|
@@ -69,7 +69,7 @@ describe('TrackedArray > mutations', () => {
|
|
|
69
69
|
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,3]');
|
|
70
70
|
expect(container.querySelectorAll('pre')[1].textContent).toBe('3');
|
|
71
71
|
expect(container.querySelectorAll('pre')[2].textContent).toBe('3');
|
|
72
|
-
|
|
72
|
+
});
|
|
73
73
|
|
|
74
74
|
it('handles shift and unshift operations with reactivity', () => {
|
|
75
75
|
component ArrayTest() {
|
|
@@ -234,7 +234,9 @@ describe('TrackedArray > mutations', () => {
|
|
|
234
234
|
component ArrayTest() {
|
|
235
235
|
let items = new TrackedArray(1, 2, 3);
|
|
236
236
|
|
|
237
|
-
<button onClick={() => items.forEach((item, i) => items[i] = item * 2)}>
|
|
237
|
+
<button onClick={() => items.forEach((item, i) => items[i] = item * 2)}>
|
|
238
|
+
{'double all'}
|
|
239
|
+
</button>
|
|
238
240
|
<pre>{JSON.stringify(items)}</pre>
|
|
239
241
|
}
|
|
240
242
|
|
|
@@ -256,7 +258,9 @@ describe('TrackedArray > mutations', () => {
|
|
|
256
258
|
component ArrayTest() {
|
|
257
259
|
let items = new TrackedArray(1, 2, 3);
|
|
258
260
|
|
|
259
|
-
<button onClick={() => items.forEach((item, i) => items[i] = item * 2)}>
|
|
261
|
+
<button onClick={() => items.forEach((item, i) => items[i] = item * 2)}>
|
|
262
|
+
{'double all'}
|
|
263
|
+
</button>
|
|
260
264
|
|
|
261
265
|
for (const item of items) {
|
|
262
266
|
<pre>{item}</pre>
|
|
@@ -35,121 +35,129 @@ describe('TrackedArray > static', () => {
|
|
|
35
35
|
expect(container.querySelectorAll('pre')[1].textContent).toBe('[4,5,6,7]');
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
('fromAsync' in Array.prototype ? describe : describe.skip)(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
('fromAsync' in Array.prototype ? describe : describe.skip)(
|
|
39
|
+
'TrackedArray fromAsync',
|
|
40
|
+
async () => {
|
|
41
|
+
it('handles static fromAsync method with reactivity', async () => {
|
|
42
|
+
component Parent() {
|
|
43
|
+
try {
|
|
44
|
+
<ArrayTest />
|
|
45
|
+
} pending {
|
|
46
|
+
<div>{'Loading placeholder...'}</div>
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
|
-
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
component ArrayTest() {
|
|
51
|
+
let items = await TrackedArray.fromAsync([1, 2, 3]);
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
<button
|
|
54
|
+
onClick={() => {
|
|
55
|
+
if (items) items.push(4);
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{'add item'}
|
|
59
|
+
</button>
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
<pre>{JSON.stringify(items)}</pre>
|
|
62
|
+
}
|
|
57
63
|
|
|
58
|
-
|
|
64
|
+
render(Parent);
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
67
|
+
flushSync();
|
|
62
68
|
|
|
63
|
-
|
|
69
|
+
const addButton = container.querySelector('button');
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,3]');
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
// Test adding an item to the async-created array
|
|
74
|
+
addButton.click();
|
|
75
|
+
flushSync();
|
|
70
76
|
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
expect(container.querySelectorAll('pre')[1].textContent).toBe('[1,2,3,4]');
|
|
78
|
+
});
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
it('handles static fromAsync method with mapping function', async () => {
|
|
81
|
+
component Parent() {
|
|
82
|
+
try {
|
|
83
|
+
<ArrayTest />
|
|
84
|
+
} pending {
|
|
85
|
+
<div>{'Loading placeholder...'}</div>
|
|
86
|
+
}
|
|
80
87
|
}
|
|
81
|
-
}
|
|
82
88
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
component ArrayTest() {
|
|
90
|
+
let items = await TrackedArray.fromAsync([1, 2, 3], (x: number) => x * 2);
|
|
91
|
+
|
|
92
|
+
<button
|
|
93
|
+
onClick={() => {
|
|
94
|
+
if (items) items.push(8);
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
{'add item'}
|
|
98
|
+
</button>
|
|
99
|
+
<pre>{items ? JSON.stringify(items) : 'Loading...'}</pre>
|
|
100
|
+
}
|
|
94
101
|
|
|
95
|
-
|
|
102
|
+
render(Parent);
|
|
96
103
|
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
105
|
+
flushSync();
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
const addButton = container.querySelector('button');
|
|
101
108
|
|
|
102
|
-
|
|
109
|
+
expect(container.querySelector('pre').textContent).toBe('[2,4,6]');
|
|
103
110
|
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
addButton.click();
|
|
112
|
+
flushSync();
|
|
106
113
|
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
expect(container.querySelector('pre').textContent).toBe('[2,4,6,8]');
|
|
115
|
+
});
|
|
109
116
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
// TODO: Fix this test case, needs some async love around try statements being using in a not template way
|
|
118
|
+
it.skip('handles error in fromAsync method', async () => {
|
|
119
|
+
component Parent() {
|
|
120
|
+
try {
|
|
121
|
+
<ArrayTest />
|
|
122
|
+
} pending {
|
|
123
|
+
<div>{'Loading placeholder...'}</div>
|
|
124
|
+
}
|
|
117
125
|
}
|
|
118
|
-
}
|
|
119
126
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
component ArrayTest() {
|
|
128
|
+
let items = null;
|
|
129
|
+
let error = null;
|
|
123
130
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
// try {
|
|
132
|
+
// items = await TrackedArray.fromAsync(Promise.reject(new Error('Async error')));
|
|
133
|
+
// } catch (e) {
|
|
134
|
+
// }
|
|
135
|
+
}
|
|
129
136
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
component ArrayTest() {
|
|
138
|
+
let items = null;
|
|
139
|
+
let error = null;
|
|
133
140
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
try {
|
|
142
|
+
// items = await TrackedArray.fromAsync(Promise.reject(new Error('Async error')));
|
|
143
|
+
} catch (e) {
|
|
144
|
+
error = (e as Error).message;
|
|
145
|
+
}
|
|
139
146
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
<pre>{error ? 'Error: ' + error : 'No error'}</pre>
|
|
148
|
+
<pre>{items ? JSON.stringify(items) : 'No items'}</pre>
|
|
149
|
+
}
|
|
143
150
|
|
|
144
|
-
|
|
151
|
+
render(Parent);
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
154
|
+
flushSync();
|
|
148
155
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
expect(container.querySelectorAll('pre')[0].textContent).toBe('Error: Async error');
|
|
157
|
+
expect(container.querySelectorAll('pre')[1].textContent).toBe('No items');
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
);
|
|
153
161
|
|
|
154
162
|
describe('Creates TrackedArray with a single element', () => {
|
|
155
163
|
it('specifies int', () => {
|
|
@@ -209,29 +217,32 @@ describe('TrackedArray > static', () => {
|
|
|
209
217
|
expect(container.querySelectorAll('pre')[1].textContent).toBe('1');
|
|
210
218
|
});
|
|
211
219
|
|
|
212
|
-
('fromAsync' in Array.prototype ? it : it.skip)(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
('fromAsync' in Array.prototype ? it : it.skip)(
|
|
221
|
+
'specifies int using static fromAsync method',
|
|
222
|
+
async () => {
|
|
223
|
+
component Parent() {
|
|
224
|
+
try {
|
|
225
|
+
<ArrayTest />
|
|
226
|
+
} pending {
|
|
227
|
+
<div>{'Loading placeholder...'}</div>
|
|
228
|
+
}
|
|
218
229
|
}
|
|
219
|
-
}
|
|
220
230
|
|
|
221
|
-
|
|
222
|
-
|
|
231
|
+
component ArrayTest() {
|
|
232
|
+
const items = await TrackedArray.fromAsync([6]);
|
|
223
233
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
234
|
+
<pre>{items ? JSON.stringify(items) : 'Loading...'}</pre>
|
|
235
|
+
<pre>{items ? items.length : ''}</pre>
|
|
236
|
+
}
|
|
227
237
|
|
|
228
|
-
|
|
238
|
+
render(Parent);
|
|
229
239
|
|
|
230
|
-
|
|
231
|
-
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
241
|
+
flushSync();
|
|
232
242
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
243
|
+
expect(container.querySelectorAll('pre')[0].textContent).toBe('[6]');
|
|
244
|
+
expect(container.querySelectorAll('pre')[1].textContent).toBe('1');
|
|
245
|
+
},
|
|
246
|
+
);
|
|
236
247
|
});
|
|
237
248
|
});
|
|
@@ -2,7 +2,7 @@ import { track, flushSync, TrackedArray } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('TrackedArray > to* methods', () => {
|
|
4
4
|
it('handles toReversed method with reactivity', (context) => {
|
|
5
|
-
if (!
|
|
5
|
+
if (!'toReversed' in Array.prototype) {
|
|
6
6
|
context.skip();
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -32,7 +32,7 @@ describe('TrackedArray > to* methods', () => {
|
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
it('handles toSorted method with reactivity', (context) => {
|
|
35
|
-
if (!
|
|
35
|
+
if (!'toSorted' in Array.prototype) {
|
|
36
36
|
context.skip();
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -62,7 +62,7 @@ describe('TrackedArray > to* methods', () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
it('handles toSpliced method with reactivity', (context) => {
|
|
65
|
-
if (!
|
|
65
|
+
if (!'toSpliced' in Array.prototype) {
|
|
66
66
|
context.skip();
|
|
67
67
|
}
|
|
68
68
|
|