ripple 0.2.53 → 0.2.55
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/package.json +1 -1
- package/src/compiler/phases/2-analyze/index.js +1 -32
- package/src/compiler/phases/3-transform/index.js +13 -84
- package/src/compiler/phases/3-transform/stylesheet.js +16 -3
- package/src/compiler/utils.js +0 -20
- package/src/runtime/array.js +158 -610
- package/src/runtime/index.js +3 -3
- package/src/runtime/internal/client/constants.js +1 -1
- package/src/runtime/internal/client/for.js +5 -5
- package/src/runtime/internal/client/index.js +1 -11
- package/src/runtime/internal/client/operations.js +0 -3
- package/src/runtime/internal/client/portal.js +5 -6
- package/src/runtime/internal/client/runtime.js +48 -315
- package/src/runtime/internal/client/utils.js +0 -10
- package/src/runtime/map.js +28 -15
- package/src/runtime/set.js +47 -21
- package/tests/array.test.ripple +75 -187
- package/tests/basic.test.ripple +33 -9
- package/tests/compiler.test.ripple +5 -5
- package/tests/composite.test.ripple +253 -3
- package/tests/for.test.ripple +3 -3
- package/tests/map.test.ripple +10 -10
- package/tests/ref.test.ripple +3 -3
- package/tests/set.test.ripple +7 -7
- package/types/index.d.ts +18 -31
package/tests/array.test.ripple
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mount, flushSync, effect, untrack,
|
|
3
|
-
import {
|
|
2
|
+
import { mount, flushSync, effect, untrack, TrackedArray, track } from 'ripple';
|
|
3
|
+
import { MAX_ARRAY_LENGTH } from '../src/runtime/internal/client/constants.js';
|
|
4
4
|
|
|
5
|
-
describe('
|
|
5
|
+
describe('TrackedArray', () => {
|
|
6
6
|
let container;
|
|
7
7
|
|
|
8
8
|
function render(component) {
|
|
@@ -23,7 +23,7 @@ describe('RippleArray', () => {
|
|
|
23
23
|
|
|
24
24
|
it('handles direct assignment and length tracking', () => {
|
|
25
25
|
component ArrayTest() {
|
|
26
|
-
let items = new
|
|
26
|
+
let items = new TrackedArray(1, 2, 3);
|
|
27
27
|
|
|
28
28
|
<button onClick={() => items[items.length] = items.length + 1}>{'increment'}</button>
|
|
29
29
|
|
|
@@ -32,7 +32,7 @@ describe('RippleArray', () => {
|
|
|
32
32
|
|
|
33
33
|
component Child({ items }) {
|
|
34
34
|
<pre>{JSON.stringify(items)}</pre>
|
|
35
|
-
<pre>{items
|
|
35
|
+
<pre>{items.length}</pre>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
render(ArrayTest);
|
|
@@ -54,13 +54,13 @@ describe('RippleArray', () => {
|
|
|
54
54
|
|
|
55
55
|
it('handles push and pop operations with reactivity', () => {
|
|
56
56
|
component ArrayTest() {
|
|
57
|
-
let items = new
|
|
58
|
-
let lastItem = track(() => items[items
|
|
57
|
+
let items = new TrackedArray(1, 2, 3);
|
|
58
|
+
let lastItem = track(() => items[items.length - 1]);
|
|
59
59
|
|
|
60
60
|
<button onClick={() => items.push(4)}>{'push'}</button>
|
|
61
61
|
<button onClick={() => items.pop()}>{'pop'}</button>
|
|
62
62
|
<pre>{JSON.stringify(items)}</pre>
|
|
63
|
-
<pre>{items
|
|
63
|
+
<pre>{items.length}</pre>
|
|
64
64
|
<pre>{@lastItem}</pre>
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -93,13 +93,13 @@ describe('RippleArray', () => {
|
|
|
93
93
|
|
|
94
94
|
it('handles shift and unshift operations with reactivity', () => {
|
|
95
95
|
component ArrayTest() {
|
|
96
|
-
let items = new
|
|
96
|
+
let items = new TrackedArray(2, 3, 4);
|
|
97
97
|
let firstItem = track(() => items[0]);
|
|
98
98
|
|
|
99
99
|
<button onClick={() => items.unshift(1)}>{'unshift'}</button>
|
|
100
100
|
<button onClick={() => items.shift()}>{'shift'}</button>
|
|
101
101
|
<pre>{JSON.stringify(items)}</pre>
|
|
102
|
-
<pre>{items
|
|
102
|
+
<pre>{items.length}</pre>
|
|
103
103
|
<pre>{@firstItem}</pre>
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -132,12 +132,12 @@ describe('RippleArray', () => {
|
|
|
132
132
|
|
|
133
133
|
it('handles splice operation with reactivity', () => {
|
|
134
134
|
component ArrayTest() {
|
|
135
|
-
let items = new
|
|
135
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
136
136
|
let middleItem = track(() => items[2]);
|
|
137
137
|
|
|
138
138
|
<button onClick={() => items.splice(1, 2, 'a', 'b')}>{'splice'}</button>
|
|
139
139
|
<pre>{JSON.stringify(items)}</pre>
|
|
140
|
-
<pre>{items
|
|
140
|
+
<pre>{items.length}</pre>
|
|
141
141
|
<pre>{@middleItem}</pre>
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -161,7 +161,7 @@ describe('RippleArray', () => {
|
|
|
161
161
|
|
|
162
162
|
it('handles fill operation with reactivity', () => {
|
|
163
163
|
component ArrayTest() {
|
|
164
|
-
let items = new
|
|
164
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
165
165
|
let secondItem = track(() => items[1]);
|
|
166
166
|
|
|
167
167
|
<button onClick={() => items.fill(0, 1, 4)}>{'fill'}</button>
|
|
@@ -187,7 +187,7 @@ describe('RippleArray', () => {
|
|
|
187
187
|
|
|
188
188
|
it('handles reverse operation with reactivity', () => {
|
|
189
189
|
component ArrayTest() {
|
|
190
|
-
let items = new
|
|
190
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
191
191
|
let firstItem = track(() => items[0]);
|
|
192
192
|
let lastItem = track(() => items[4]);
|
|
193
193
|
|
|
@@ -217,7 +217,7 @@ describe('RippleArray', () => {
|
|
|
217
217
|
|
|
218
218
|
it('handles sort operation with reactivity', () => {
|
|
219
219
|
component ArrayTest() {
|
|
220
|
-
let items = new
|
|
220
|
+
let items = new TrackedArray(5, 3, 1, 4, 2);
|
|
221
221
|
let secondItem = track(() => items[1]);
|
|
222
222
|
|
|
223
223
|
<button onClick={() => items.sort()}>{'sort ascending'}</button>
|
|
@@ -252,7 +252,7 @@ describe('RippleArray', () => {
|
|
|
252
252
|
|
|
253
253
|
it('handles array methods that return values (map, filter, etc.)', () => {
|
|
254
254
|
component ArrayTest() {
|
|
255
|
-
let items = new
|
|
255
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
256
256
|
let doubled = track(() => items.map(x => x * 2));
|
|
257
257
|
let filtered = track(() => items.filter(x => (x % 2) === 0));
|
|
258
258
|
let reduced = track(() => items.reduce((acc, val) => acc + val, 0));
|
|
@@ -287,7 +287,7 @@ describe('RippleArray', () => {
|
|
|
287
287
|
|
|
288
288
|
it('handles array modification through forEach()', () => {
|
|
289
289
|
component ArrayTest() {
|
|
290
|
-
let items = new
|
|
290
|
+
let items = new TrackedArray(1, 2, 3);
|
|
291
291
|
|
|
292
292
|
<button onClick={() => items.forEach((item, i) => items[i] = item * 2)}>{'double all'}</button>
|
|
293
293
|
<pre>{JSON.stringify(items)}</pre>
|
|
@@ -309,7 +309,7 @@ describe('RippleArray', () => {
|
|
|
309
309
|
|
|
310
310
|
it('handles entries method with reactivity', () => {
|
|
311
311
|
component ArrayTest() {
|
|
312
|
-
let items = new
|
|
312
|
+
let items = new TrackedArray('a', 'b', 'c');
|
|
313
313
|
let entries = track(() => Array.from(items.entries()));
|
|
314
314
|
|
|
315
315
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
@@ -335,7 +335,7 @@ describe('RippleArray', () => {
|
|
|
335
335
|
|
|
336
336
|
it('handles concat method with reactivity', () => {
|
|
337
337
|
component ArrayTest() {
|
|
338
|
-
let items = new
|
|
338
|
+
let items = new TrackedArray(1, 2, 3);
|
|
339
339
|
let concatenated = track(() => items.concat([4, 5], 6, [7, 8]));
|
|
340
340
|
|
|
341
341
|
<button onClick={() => items.push(3.5)}>{'add to original'}</button>
|
|
@@ -361,7 +361,7 @@ describe('RippleArray', () => {
|
|
|
361
361
|
|
|
362
362
|
it('handles array modification through iterator', () => {
|
|
363
363
|
component ArrayTest() {
|
|
364
|
-
let items = new
|
|
364
|
+
let items = new TrackedArray(1, 2, 3);
|
|
365
365
|
|
|
366
366
|
<button onClick={() => items.forEach((item, i) => items[i] = item * 2)}>{'double all'}</button>
|
|
367
367
|
|
|
@@ -388,13 +388,13 @@ describe('RippleArray', () => {
|
|
|
388
388
|
expect(container.querySelectorAll('pre')[2].textContent).toBe('6');
|
|
389
389
|
});
|
|
390
390
|
|
|
391
|
-
it('handles
|
|
391
|
+
it('handles length property for reactivity', () => {
|
|
392
392
|
component ArrayTest() {
|
|
393
|
-
let items = new
|
|
394
|
-
let length = track(() => items
|
|
393
|
+
let items = new TrackedArray(1, 2, 3);
|
|
394
|
+
let length = track(() => items.length);
|
|
395
395
|
|
|
396
|
-
<button onClick={() => items
|
|
397
|
-
<button onClick={() => items
|
|
396
|
+
<button onClick={() => items.length = 5}>{'expand'}</button>
|
|
397
|
+
<button onClick={() => items.length = 2}>{'shrink'}</button>
|
|
398
398
|
<pre>{JSON.stringify(items)}</pre>
|
|
399
399
|
<pre>{@length}</pre>
|
|
400
400
|
}
|
|
@@ -425,8 +425,8 @@ describe('RippleArray', () => {
|
|
|
425
425
|
|
|
426
426
|
it('handles static methods - from and of', () => {
|
|
427
427
|
component ArrayTest() {
|
|
428
|
-
let itemsFrom =
|
|
429
|
-
let itemsOf =
|
|
428
|
+
let itemsFrom = TrackedArray.from([1, 2, 3], x => x * 2);
|
|
429
|
+
let itemsOf = TrackedArray.of(4, 5, 6);
|
|
430
430
|
|
|
431
431
|
<button onClick={() => itemsFrom.push(8)}>{'add to from'}</button>
|
|
432
432
|
<button onClick={() => itemsOf.push(7)}>{'add to of'}</button>
|
|
@@ -458,7 +458,7 @@ describe('RippleArray', () => {
|
|
|
458
458
|
|
|
459
459
|
it('handles toJSON method', () => {
|
|
460
460
|
component ArrayTest() {
|
|
461
|
-
let items = new
|
|
461
|
+
let items = new TrackedArray(1, 2, 3);
|
|
462
462
|
|
|
463
463
|
<button onClick={() => items.push(4)}>{'add'}</button>
|
|
464
464
|
<pre>{JSON.stringify(items)}</pre>
|
|
@@ -480,7 +480,7 @@ describe('RippleArray', () => {
|
|
|
480
480
|
|
|
481
481
|
it('handles array index access with reactivity', () => {
|
|
482
482
|
component ArrayTest() {
|
|
483
|
-
let items = new
|
|
483
|
+
let items = new TrackedArray(10, 20, 30);
|
|
484
484
|
let firstItem = track(() => items[0]);
|
|
485
485
|
let secondItem = track(() => items[1]);
|
|
486
486
|
|
|
@@ -513,7 +513,7 @@ describe('RippleArray', () => {
|
|
|
513
513
|
|
|
514
514
|
it('handles array slice method with reactivity', () => {
|
|
515
515
|
component ArrayTest() {
|
|
516
|
-
let items = new
|
|
516
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
517
517
|
let sliced = track(() => items.slice(1, 4));
|
|
518
518
|
|
|
519
519
|
<button onClick={() => items[2] = 30}>{'change middle'}</button>
|
|
@@ -539,7 +539,7 @@ describe('RippleArray', () => {
|
|
|
539
539
|
|
|
540
540
|
it('handles find and findIndex methods with reactivity', () => {
|
|
541
541
|
component ArrayTest() {
|
|
542
|
-
let items = new
|
|
542
|
+
let items = new TrackedArray(5, 10, 15, 20, 25);
|
|
543
543
|
let found = track(() => items.find(x => x > 12));
|
|
544
544
|
let foundIndex = track(() => items.findIndex(x => x > 12));
|
|
545
545
|
|
|
@@ -567,11 +567,11 @@ describe('RippleArray', () => {
|
|
|
567
567
|
expect(container.querySelectorAll('pre')[1].textContent).toBe('1');
|
|
568
568
|
});
|
|
569
569
|
|
|
570
|
-
// Additional tests for
|
|
570
|
+
// Additional tests for TrackedArray methods
|
|
571
571
|
|
|
572
572
|
it('handles findLast and findLastIndex methods with reactivity', () => {
|
|
573
573
|
component ArrayTest() {
|
|
574
|
-
let items = new
|
|
574
|
+
let items = new TrackedArray(5, 15, 10, 20, 15);
|
|
575
575
|
let foundLast = track(() => items.findLast(x => x === 15));
|
|
576
576
|
let foundLastIndex = track(() => items.findLastIndex(x => x === 15));
|
|
577
577
|
|
|
@@ -601,7 +601,7 @@ describe('RippleArray', () => {
|
|
|
601
601
|
|
|
602
602
|
it('handles every method with reactivity', () => {
|
|
603
603
|
component ArrayTest() {
|
|
604
|
-
let items = new
|
|
604
|
+
let items = new TrackedArray(2, 4, 6, 8);
|
|
605
605
|
let allEven = track(() => items.every(x => x % 2 === 0));
|
|
606
606
|
|
|
607
607
|
<button onClick={() => items.push(3)}>{'add odd'}</button>
|
|
@@ -633,7 +633,7 @@ describe('RippleArray', () => {
|
|
|
633
633
|
|
|
634
634
|
it('handles flat method with reactivity', () => {
|
|
635
635
|
component ArrayTest() {
|
|
636
|
-
let items = new
|
|
636
|
+
let items = new TrackedArray([1, 2], [3, 4], 5);
|
|
637
637
|
let flattened = track(() => items.flat());
|
|
638
638
|
|
|
639
639
|
<button onClick={() => items[0] = [6, 7, 8]}>{'change nested'}</button>
|
|
@@ -659,7 +659,7 @@ describe('RippleArray', () => {
|
|
|
659
659
|
|
|
660
660
|
it('handles flatMap method with reactivity', () => {
|
|
661
661
|
component ArrayTest() {
|
|
662
|
-
let items = new
|
|
662
|
+
let items = new TrackedArray(1, 2, 3);
|
|
663
663
|
let flatMapped = track(() => items.flatMap(x => [x, x * 2]));
|
|
664
664
|
|
|
665
665
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
@@ -685,7 +685,7 @@ describe('RippleArray', () => {
|
|
|
685
685
|
|
|
686
686
|
it('handles join method with reactivity', () => {
|
|
687
687
|
component ArrayTest() {
|
|
688
|
-
let items = new
|
|
688
|
+
let items = new TrackedArray('apple', 'banana', 'cherry');
|
|
689
689
|
let joined = track(() => items.join(', '));
|
|
690
690
|
|
|
691
691
|
<button onClick={() => items.push('date')}>{'add item'}</button>
|
|
@@ -711,7 +711,7 @@ describe('RippleArray', () => {
|
|
|
711
711
|
|
|
712
712
|
it('handles keys method with reactivity', () => {
|
|
713
713
|
component ArrayTest() {
|
|
714
|
-
let items = new
|
|
714
|
+
let items = new TrackedArray('a', 'b', 'c');
|
|
715
715
|
let keys = track(() => Array.from(items.keys()));
|
|
716
716
|
|
|
717
717
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
@@ -737,7 +737,7 @@ describe('RippleArray', () => {
|
|
|
737
737
|
|
|
738
738
|
it('handles lastIndexOf method with reactivity', () => {
|
|
739
739
|
component ArrayTest() {
|
|
740
|
-
let items = new
|
|
740
|
+
let items = new TrackedArray(1, 2, 3, 2, 1);
|
|
741
741
|
let lastIndex = track(() => items.lastIndexOf(2));
|
|
742
742
|
|
|
743
743
|
<button onClick={() => {
|
|
@@ -765,7 +765,7 @@ describe('RippleArray', () => {
|
|
|
765
765
|
|
|
766
766
|
it('handles reduceRight method with reactivity', () => {
|
|
767
767
|
component ArrayTest() {
|
|
768
|
-
let items = new
|
|
768
|
+
let items = new TrackedArray('a', 'b', 'c');
|
|
769
769
|
let reduced = track(() => items.reduceRight((acc, val) => acc + val, ''));
|
|
770
770
|
|
|
771
771
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
@@ -791,7 +791,7 @@ describe('RippleArray', () => {
|
|
|
791
791
|
|
|
792
792
|
it('handles some method with reactivity', () => {
|
|
793
793
|
component ArrayTest() {
|
|
794
|
-
let items = new
|
|
794
|
+
let items = new TrackedArray(1, 3, 5, 7);
|
|
795
795
|
let hasEven = track(() => items.some(x => x % 2 === 0));
|
|
796
796
|
|
|
797
797
|
<button onClick={() => items.push(2)}>{'add even'}</button>
|
|
@@ -823,7 +823,7 @@ describe('RippleArray', () => {
|
|
|
823
823
|
|
|
824
824
|
it('handles toLocaleString method with reactivity', () => {
|
|
825
825
|
component ArrayTest() {
|
|
826
|
-
let items = new
|
|
826
|
+
let items = new TrackedArray(1000, 2000, 3000);
|
|
827
827
|
let localized = track(() => items.toLocaleString('en-US'));
|
|
828
828
|
|
|
829
829
|
<button onClick={() => {items[2] = 4000}}>{'add item'}</button>
|
|
@@ -853,7 +853,7 @@ describe('RippleArray', () => {
|
|
|
853
853
|
}
|
|
854
854
|
|
|
855
855
|
component ArrayTest() {
|
|
856
|
-
let items = new
|
|
856
|
+
let items = new TrackedArray(1, 2, 3, 4);
|
|
857
857
|
let reversed = track(() => items.toReversed());
|
|
858
858
|
|
|
859
859
|
<button onClick={() => items.push(5)}>{'add item'}</button>
|
|
@@ -883,7 +883,7 @@ describe('RippleArray', () => {
|
|
|
883
883
|
}
|
|
884
884
|
|
|
885
885
|
component ArrayTest() {
|
|
886
|
-
let items = new
|
|
886
|
+
let items = new TrackedArray(3, 1, 4, 2);
|
|
887
887
|
let sorted = track(() => items.toSorted());
|
|
888
888
|
|
|
889
889
|
<button onClick={() => items.push(0)}>{'add item'}</button>
|
|
@@ -913,7 +913,7 @@ describe('RippleArray', () => {
|
|
|
913
913
|
}
|
|
914
914
|
|
|
915
915
|
component ArrayTest() {
|
|
916
|
-
let items = new
|
|
916
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
917
917
|
let spliced = track(() => items.toSpliced(1, 2, 'a', 'b'));
|
|
918
918
|
|
|
919
919
|
<button onClick={() => items[2] = 30}>{'change item'}</button>
|
|
@@ -939,7 +939,7 @@ describe('RippleArray', () => {
|
|
|
939
939
|
|
|
940
940
|
it('handles toString method with reactivity', () => {
|
|
941
941
|
component ArrayTest() {
|
|
942
|
-
let items = new
|
|
942
|
+
let items = new TrackedArray(1, 2, 3);
|
|
943
943
|
let string = track(() => items.toString());
|
|
944
944
|
|
|
945
945
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
@@ -965,7 +965,7 @@ describe('RippleArray', () => {
|
|
|
965
965
|
|
|
966
966
|
it('handles Symbol.iterator with reactivity', () => {
|
|
967
967
|
component ArrayTest() {
|
|
968
|
-
let items = new
|
|
968
|
+
let items = new TrackedArray(1, 2, 3);
|
|
969
969
|
let sum = track(0);
|
|
970
970
|
|
|
971
971
|
effect(() => {
|
|
@@ -999,7 +999,7 @@ describe('RippleArray', () => {
|
|
|
999
999
|
|
|
1000
1000
|
it('handles values method with reactivity', () => {
|
|
1001
1001
|
component ArrayTest() {
|
|
1002
|
-
let items = new
|
|
1002
|
+
let items = new TrackedArray('a', 'b', 'c');
|
|
1003
1003
|
let values = track(() => Array.from(items.values()));
|
|
1004
1004
|
|
|
1005
1005
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
@@ -1029,7 +1029,7 @@ describe('RippleArray', () => {
|
|
|
1029
1029
|
}
|
|
1030
1030
|
|
|
1031
1031
|
component ArrayTest() {
|
|
1032
|
-
let items = new
|
|
1032
|
+
let items = new TrackedArray(1, 2, 3, 4);
|
|
1033
1033
|
let withReplaced = track(() => items.with(2, 30));
|
|
1034
1034
|
|
|
1035
1035
|
<button onClick={() => items[2] = 50}>{'change original'}</button>
|
|
@@ -1055,7 +1055,7 @@ describe('RippleArray', () => {
|
|
|
1055
1055
|
|
|
1056
1056
|
it('handles at method with reactivity', () => {
|
|
1057
1057
|
component ArrayTest() {
|
|
1058
|
-
let items = new
|
|
1058
|
+
let items = new TrackedArray(10, 20, 30, 40, 50);
|
|
1059
1059
|
let atIndex2 = track(() => items.at(2));
|
|
1060
1060
|
let atNegative1 = track(() => items.at(-1));
|
|
1061
1061
|
let atNegative2 = track(() => items.at(-2));
|
|
@@ -1098,102 +1098,14 @@ describe('RippleArray', () => {
|
|
|
1098
1098
|
expect(container.querySelectorAll('pre')[3].textContent).toBe('40');
|
|
1099
1099
|
});
|
|
1100
1100
|
|
|
1101
|
-
it('handles
|
|
1101
|
+
it('handles setting length property and resizing the array', () => {
|
|
1102
1102
|
component ArrayTest() {
|
|
1103
|
-
let items = new
|
|
1104
|
-
let thirdItem = track(() => items[2]);
|
|
1103
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
1105
1104
|
|
|
1106
|
-
<button onClick={() => items
|
|
1107
|
-
<button onClick={() => items
|
|
1108
|
-
<button onClick={() => items[ARRAY_SET_INDEX_AT](6, 60)}>{'extend array'}</button>
|
|
1105
|
+
<button onClick={() => items.length = 3}>{'truncate'}</button>
|
|
1106
|
+
<button onClick={() => items.length = 7}>{'expand'}</button>
|
|
1109
1107
|
<pre>{JSON.stringify(items)}</pre>
|
|
1110
|
-
<pre>{items
|
|
1111
|
-
<pre>{@thirdItem}</pre>
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
render(ArrayTest);
|
|
1115
|
-
|
|
1116
|
-
const setIndex2Button = container.querySelectorAll('button')[0];
|
|
1117
|
-
const setLastButton = container.querySelectorAll('button')[1];
|
|
1118
|
-
const extendButton = container.querySelectorAll('button')[2];
|
|
1119
|
-
|
|
1120
|
-
// Initial state
|
|
1121
|
-
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,3,4,5]');
|
|
1122
|
-
expect(container.querySelectorAll('pre')[1].textContent).toBe('5');
|
|
1123
|
-
expect(container.querySelectorAll('pre')[2].textContent).toBe('3');
|
|
1124
|
-
|
|
1125
|
-
// Test setting index 2
|
|
1126
|
-
setIndex2Button.click();
|
|
1127
|
-
flushSync();
|
|
1128
|
-
|
|
1129
|
-
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,30,4,5]');
|
|
1130
|
-
expect(container.querySelectorAll('pre')[1].textContent).toBe('5');
|
|
1131
|
-
expect(container.querySelectorAll('pre')[2].textContent).toBe('30');
|
|
1132
|
-
|
|
1133
|
-
// Test setting with negative index
|
|
1134
|
-
setLastButton.click();
|
|
1135
|
-
flushSync();
|
|
1136
|
-
|
|
1137
|
-
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,30,4,50]');
|
|
1138
|
-
expect(container.querySelectorAll('pre')[1].textContent).toBe('5');
|
|
1139
|
-
|
|
1140
|
-
// Test extending array
|
|
1141
|
-
extendButton.click();
|
|
1142
|
-
flushSync();
|
|
1143
|
-
|
|
1144
|
-
expect(container.querySelectorAll('pre')[0].textContent).toBe('[1,2,30,4,50,null,60]');
|
|
1145
|
-
expect(container.querySelectorAll('pre')[1].textContent).toBe('7');
|
|
1146
|
-
});
|
|
1147
|
-
|
|
1148
|
-
it('handles ARRAY_SET_INDEX_AT error cases', () => {
|
|
1149
|
-
component ArrayTest() {
|
|
1150
|
-
let items = new RippleArray(1, 2, 3);
|
|
1151
|
-
let error = track(null);
|
|
1152
|
-
|
|
1153
|
-
<button onClick={() => {
|
|
1154
|
-
try {
|
|
1155
|
-
items[ARRAY_SET_INDEX_AT](1.5, 10);
|
|
1156
|
-
} catch (e) {
|
|
1157
|
-
@error = e.message;
|
|
1158
|
-
}
|
|
1159
|
-
}}>{'try non-integer'}</button>
|
|
1160
|
-
<button onClick={() => {
|
|
1161
|
-
try {
|
|
1162
|
-
@error = null;
|
|
1163
|
-
items[ARRAY_SET_INDEX_AT](-5, 10);
|
|
1164
|
-
} catch (e) {
|
|
1165
|
-
@error = e.message;
|
|
1166
|
-
}
|
|
1167
|
-
}}>{'try out of bounds negative'}</button>
|
|
1168
|
-
<pre>{@error}</pre>
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
render(ArrayTest);
|
|
1172
|
-
|
|
1173
|
-
const nonIntegerButton = container.querySelectorAll('button')[0];
|
|
1174
|
-
const outOfBoundsButton = container.querySelectorAll('button')[1];
|
|
1175
|
-
|
|
1176
|
-
// Test non-integer index
|
|
1177
|
-
nonIntegerButton.click();
|
|
1178
|
-
flushSync();
|
|
1179
|
-
|
|
1180
|
-
expect(container.querySelector('pre').textContent).toBe('Provided index must be a valid integer');
|
|
1181
|
-
|
|
1182
|
-
// Test out of bounds negative index
|
|
1183
|
-
outOfBoundsButton.click();
|
|
1184
|
-
flushSync();
|
|
1185
|
-
|
|
1186
|
-
expect(container.querySelector('pre').textContent).toBe('Provided negative index out of bounds');
|
|
1187
|
-
});
|
|
1188
|
-
|
|
1189
|
-
it('handles setting $length property and resizing the array', () => {
|
|
1190
|
-
component ArrayTest() {
|
|
1191
|
-
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
1192
|
-
|
|
1193
|
-
<button onClick={() => items.$length = 3}>{'truncate'}</button>
|
|
1194
|
-
<button onClick={() => items.$length = 7}>{'expand'}</button>
|
|
1195
|
-
<pre>{JSON.stringify(items)}</pre>
|
|
1196
|
-
<pre>{items.$length}</pre>
|
|
1108
|
+
<pre>{items.length}</pre>
|
|
1197
1109
|
}
|
|
1198
1110
|
|
|
1199
1111
|
render(ArrayTest);
|
|
@@ -1220,31 +1132,7 @@ describe('RippleArray', () => {
|
|
|
1220
1132
|
expect(container.querySelectorAll('pre')[1].textContent).toBe('7');
|
|
1221
1133
|
});
|
|
1222
1134
|
|
|
1223
|
-
|
|
1224
|
-
component ArrayTest() {
|
|
1225
|
-
let items = new RippleArray(1, 2, 3);
|
|
1226
|
-
let error = track(null);
|
|
1227
|
-
|
|
1228
|
-
<button onClick={() => {
|
|
1229
|
-
try {
|
|
1230
|
-
items.length = 5;
|
|
1231
|
-
} catch (e) {
|
|
1232
|
-
@error = e.message;
|
|
1233
|
-
}
|
|
1234
|
-
}}>{'try set length'}</button>
|
|
1235
|
-
<pre>{@error}</pre>
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
render(ArrayTest);
|
|
1239
|
-
|
|
1240
|
-
const button = container.querySelector('button');
|
|
1241
|
-
button.click();
|
|
1242
|
-
flushSync();
|
|
1243
|
-
|
|
1244
|
-
expect(container.querySelector('pre').textContent).toBe('Cannot set length on RippleArray, use $length instead');
|
|
1245
|
-
});
|
|
1246
|
-
|
|
1247
|
-
('fromAsync' in Array.prototype ? describe : describe.skip)('RippleArray fromAsync', async () => {
|
|
1135
|
+
('fromAsync' in Array.prototype ? describe : describe.skip)('TrackedArray fromAsync', async () => {
|
|
1248
1136
|
it('handles static fromAsync method with reactivity', async () => {
|
|
1249
1137
|
component Parent() {
|
|
1250
1138
|
try {
|
|
@@ -1255,7 +1143,7 @@ describe('RippleArray', () => {
|
|
|
1255
1143
|
}
|
|
1256
1144
|
|
|
1257
1145
|
component ArrayTest() {
|
|
1258
|
-
let items = await
|
|
1146
|
+
let items = await TrackedArray.fromAsync([1, 2, 3]);
|
|
1259
1147
|
|
|
1260
1148
|
<button onClick={() => {
|
|
1261
1149
|
if (items) items.push(4);
|
|
@@ -1290,7 +1178,7 @@ describe('RippleArray', () => {
|
|
|
1290
1178
|
}
|
|
1291
1179
|
|
|
1292
1180
|
component ArrayTest() {
|
|
1293
|
-
let items = await
|
|
1181
|
+
let items = await TrackedArray.fromAsync(
|
|
1294
1182
|
[1, 2, 3],
|
|
1295
1183
|
x => x * 2
|
|
1296
1184
|
);
|
|
@@ -1331,7 +1219,7 @@ describe('RippleArray', () => {
|
|
|
1331
1219
|
let error = null;
|
|
1332
1220
|
|
|
1333
1221
|
// try {
|
|
1334
|
-
// items = await
|
|
1222
|
+
// items = await TrackedArray.fromAsync(Promise.reject(new Error('Async error')));
|
|
1335
1223
|
// } catch (e) {
|
|
1336
1224
|
// }
|
|
1337
1225
|
}
|
|
@@ -1341,7 +1229,7 @@ describe('RippleArray', () => {
|
|
|
1341
1229
|
let error = null;
|
|
1342
1230
|
|
|
1343
1231
|
try {
|
|
1344
|
-
// items = await
|
|
1232
|
+
// items = await TrackedArray.fromAsync(Promise.reject(new Error('Async error')));
|
|
1345
1233
|
} catch (e) {
|
|
1346
1234
|
error = e.message;
|
|
1347
1235
|
}
|
|
@@ -1360,10 +1248,10 @@ describe('RippleArray', () => {
|
|
|
1360
1248
|
});
|
|
1361
1249
|
});
|
|
1362
1250
|
|
|
1363
|
-
describe('
|
|
1251
|
+
describe('TrackedArray copyWithin', () => {
|
|
1364
1252
|
it('handles copyWithin operation with reactivity', () => {
|
|
1365
1253
|
component ArrayTest() {
|
|
1366
|
-
let items = new
|
|
1254
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
1367
1255
|
let firstItem = track(() => items[0]);
|
|
1368
1256
|
let thirdItem = track(() => items[2]);
|
|
1369
1257
|
let fourthItem = track(() => items[3]);
|
|
@@ -1408,7 +1296,7 @@ describe('RippleArray', () => {
|
|
|
1408
1296
|
|
|
1409
1297
|
it('handles copyWithin with negative indexes and reactivity', () => {
|
|
1410
1298
|
component ArrayTest() {
|
|
1411
|
-
let items = new
|
|
1299
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
1412
1300
|
let secondItem = track(() => items[1]);
|
|
1413
1301
|
let thirdItem = track(() => items[2]);
|
|
1414
1302
|
|
|
@@ -1439,8 +1327,8 @@ describe('RippleArray', () => {
|
|
|
1439
1327
|
|
|
1440
1328
|
it('handles copyWithin with overlapping ranges', () => {
|
|
1441
1329
|
component ArrayTest() {
|
|
1442
|
-
let items = new
|
|
1443
|
-
let entries = track(() => items.entries());
|
|
1330
|
+
let items = new TrackedArray(1, 2, 3, 4, 5);
|
|
1331
|
+
let entries = track(() => Array.from(items.entries()));
|
|
1444
1332
|
|
|
1445
1333
|
<button onClick={() => items.copyWithin(2, 1, 4)}>{'copy with overlap'}</button>
|
|
1446
1334
|
<pre>{JSON.stringify(items)}</pre>
|
|
@@ -1479,12 +1367,12 @@ describe('RippleArray', () => {
|
|
|
1479
1367
|
});
|
|
1480
1368
|
});
|
|
1481
1369
|
|
|
1482
|
-
describe('Creates
|
|
1370
|
+
describe('Creates TrackedArray with a single element', () => {
|
|
1483
1371
|
it('specifies int', () => {
|
|
1484
1372
|
component ArrayTest() {
|
|
1485
|
-
let items = new
|
|
1373
|
+
let items = new TrackedArray(3);
|
|
1486
1374
|
<pre>{JSON.stringify(items)}</pre>
|
|
1487
|
-
<pre>{items
|
|
1375
|
+
<pre>{items.length}</pre>
|
|
1488
1376
|
}
|
|
1489
1377
|
|
|
1490
1378
|
render(ArrayTest);
|
|
@@ -1498,7 +1386,7 @@ describe('RippleArray', () => {
|
|
|
1498
1386
|
let error = null;
|
|
1499
1387
|
|
|
1500
1388
|
try {
|
|
1501
|
-
new
|
|
1389
|
+
new TrackedArray(MAX_ARRAY_LENGTH + 1);
|
|
1502
1390
|
} catch (e) {
|
|
1503
1391
|
error = e.message;
|
|
1504
1392
|
}
|
|
@@ -1513,9 +1401,9 @@ describe('RippleArray', () => {
|
|
|
1513
1401
|
|
|
1514
1402
|
it('specifies int using static from method', () => {
|
|
1515
1403
|
component ArrayTest() {
|
|
1516
|
-
let items =
|
|
1404
|
+
let items = TrackedArray.from([4]);
|
|
1517
1405
|
<pre>{JSON.stringify(items)}</pre>
|
|
1518
|
-
<pre>{items
|
|
1406
|
+
<pre>{items.length}</pre>
|
|
1519
1407
|
}
|
|
1520
1408
|
|
|
1521
1409
|
render(ArrayTest);
|
|
@@ -1526,9 +1414,9 @@ describe('RippleArray', () => {
|
|
|
1526
1414
|
|
|
1527
1415
|
it('specifies int using static of method', () => {
|
|
1528
1416
|
component ArrayTest() {
|
|
1529
|
-
let items =
|
|
1417
|
+
let items = TrackedArray.of(5);
|
|
1530
1418
|
<pre>{JSON.stringify(items)}</pre>
|
|
1531
|
-
<pre>{items
|
|
1419
|
+
<pre>{items.length}</pre>
|
|
1532
1420
|
}
|
|
1533
1421
|
|
|
1534
1422
|
render(ArrayTest);
|
|
@@ -1547,10 +1435,10 @@ describe('RippleArray', () => {
|
|
|
1547
1435
|
}
|
|
1548
1436
|
|
|
1549
1437
|
component ArrayTest() {
|
|
1550
|
-
const items = await
|
|
1438
|
+
const items = await TrackedArray.fromAsync([6]);
|
|
1551
1439
|
|
|
1552
1440
|
<pre>{items ? JSON.stringify(items) : 'Loading...'}</pre>
|
|
1553
|
-
<pre>{items ? items
|
|
1441
|
+
<pre>{items ? items.length : ''}</pre>
|
|
1554
1442
|
}
|
|
1555
1443
|
|
|
1556
1444
|
render(Parent);
|