ripple 0.2.49 → 0.2.50
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 +2 -4
- package/package.json +2 -2
- package/src/compiler/phases/3-transform/index.js +10 -41
- package/src/runtime/internal/client/index.js +0 -18
- package/src/runtime/internal/client/runtime.js +1 -1
- package/tests/accessors-props.test.ripple +19 -23
- package/tests/array.test.ripple +103 -103
- package/tests/basic.test.ripple +184 -152
- package/tests/map.test.ripple +13 -13
- package/tests/set.test.ripple +3 -3
- package/types/index.d.ts +1 -1
- package/src/runtime/internal/client/array.js +0 -352
package/tests/array.test.ripple
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mount, flushSync, effect, untrack, RippleArray } from 'ripple';
|
|
2
|
+
import { mount, flushSync, effect, untrack, RippleArray, track } from 'ripple';
|
|
3
3
|
import { ARRAY_SET_INDEX_AT, MAX_ARRAY_LENGTH } from '../src/runtime/internal/client/constants.js';
|
|
4
4
|
|
|
5
5
|
describe('RippleArray', () => {
|
|
@@ -55,13 +55,13 @@ describe('RippleArray', () => {
|
|
|
55
55
|
it('handles push and pop operations with reactivity', () => {
|
|
56
56
|
component ArrayTest() {
|
|
57
57
|
let items = new RippleArray(1, 2, 3);
|
|
58
|
-
let
|
|
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
63
|
<pre>{items.$length}</pre>
|
|
64
|
-
<pre>{
|
|
64
|
+
<pre>{@lastItem}</pre>
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
render(ArrayTest);
|
|
@@ -94,13 +94,13 @@ describe('RippleArray', () => {
|
|
|
94
94
|
it('handles shift and unshift operations with reactivity', () => {
|
|
95
95
|
component ArrayTest() {
|
|
96
96
|
let items = new RippleArray(2, 3, 4);
|
|
97
|
-
let
|
|
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
102
|
<pre>{items.$length}</pre>
|
|
103
|
-
<pre>{
|
|
103
|
+
<pre>{@firstItem}</pre>
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
render(ArrayTest);
|
|
@@ -133,12 +133,12 @@ describe('RippleArray', () => {
|
|
|
133
133
|
it('handles splice operation with reactivity', () => {
|
|
134
134
|
component ArrayTest() {
|
|
135
135
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
136
|
-
let
|
|
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
140
|
<pre>{items.$length}</pre>
|
|
141
|
-
<pre>{
|
|
141
|
+
<pre>{@middleItem}</pre>
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
render(ArrayTest);
|
|
@@ -162,11 +162,11 @@ describe('RippleArray', () => {
|
|
|
162
162
|
it('handles fill operation with reactivity', () => {
|
|
163
163
|
component ArrayTest() {
|
|
164
164
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
165
|
-
let
|
|
165
|
+
let secondItem = track(() => items[1]);
|
|
166
166
|
|
|
167
167
|
<button onClick={() => items.fill(0, 1, 4)}>{'fill'}</button>
|
|
168
168
|
<pre>{JSON.stringify(items)}</pre>
|
|
169
|
-
<pre>{
|
|
169
|
+
<pre>{@secondItem}</pre>
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
render(ArrayTest);
|
|
@@ -188,13 +188,13 @@ describe('RippleArray', () => {
|
|
|
188
188
|
it('handles reverse operation with reactivity', () => {
|
|
189
189
|
component ArrayTest() {
|
|
190
190
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
191
|
-
let
|
|
192
|
-
let
|
|
191
|
+
let firstItem = track(() => items[0]);
|
|
192
|
+
let lastItem = track(() => items[4]);
|
|
193
193
|
|
|
194
194
|
<button onClick={() => items.reverse()}>{'reverse'}</button>
|
|
195
195
|
<pre>{JSON.stringify(items)}</pre>
|
|
196
|
-
<pre>{
|
|
197
|
-
<pre>{
|
|
196
|
+
<pre>{@firstItem}</pre>
|
|
197
|
+
<pre>{@lastItem}</pre>
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
render(ArrayTest);
|
|
@@ -218,12 +218,12 @@ describe('RippleArray', () => {
|
|
|
218
218
|
it('handles sort operation with reactivity', () => {
|
|
219
219
|
component ArrayTest() {
|
|
220
220
|
let items = new RippleArray(5, 3, 1, 4, 2);
|
|
221
|
-
let
|
|
221
|
+
let secondItem = track(() => items[1]);
|
|
222
222
|
|
|
223
223
|
<button onClick={() => items.sort()}>{'sort ascending'}</button>
|
|
224
224
|
<button onClick={() => items.sort((a, b) => b - a)}>{'sort descending'}</button>
|
|
225
225
|
<pre>{JSON.stringify(items)}</pre>
|
|
226
|
-
<pre>{
|
|
226
|
+
<pre>{@secondItem}</pre>
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
render(ArrayTest);
|
|
@@ -253,16 +253,16 @@ describe('RippleArray', () => {
|
|
|
253
253
|
it('handles array methods that return values (map, filter, etc.)', () => {
|
|
254
254
|
component ArrayTest() {
|
|
255
255
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
256
|
-
let
|
|
257
|
-
let
|
|
258
|
-
let
|
|
259
|
-
let
|
|
256
|
+
let doubled = track(() => items.map(x => x * 2));
|
|
257
|
+
let filtered = track(() => items.filter(x => (x % 2) === 0));
|
|
258
|
+
let reduced = track(() => items.reduce((acc, val) => acc + val, 0));
|
|
259
|
+
let includes = track(() => items.includes(3));
|
|
260
260
|
|
|
261
261
|
<button onClick={() => items.push(6)}>{'add item'}</button>
|
|
262
|
-
<pre>{JSON.stringify(
|
|
263
|
-
<pre>{JSON.stringify(
|
|
264
|
-
<pre>{
|
|
265
|
-
<pre>{
|
|
262
|
+
<pre>{JSON.stringify(@doubled)}</pre>
|
|
263
|
+
<pre>{JSON.stringify(@filtered)}</pre>
|
|
264
|
+
<pre>{@reduced}</pre>
|
|
265
|
+
<pre>{@includes.toString()}</pre>
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
render(ArrayTest);
|
|
@@ -310,11 +310,11 @@ describe('RippleArray', () => {
|
|
|
310
310
|
it('handles entries method with reactivity', () => {
|
|
311
311
|
component ArrayTest() {
|
|
312
312
|
let items = new RippleArray('a', 'b', 'c');
|
|
313
|
-
let
|
|
313
|
+
let entries = track(() => Array.from(items.entries()));
|
|
314
314
|
|
|
315
315
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
316
316
|
<pre>{JSON.stringify(items)}</pre>
|
|
317
|
-
<pre>{JSON.stringify(
|
|
317
|
+
<pre>{JSON.stringify(@entries)}</pre>
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
render(ArrayTest);
|
|
@@ -336,11 +336,11 @@ describe('RippleArray', () => {
|
|
|
336
336
|
it('handles concat method with reactivity', () => {
|
|
337
337
|
component ArrayTest() {
|
|
338
338
|
let items = new RippleArray(1, 2, 3);
|
|
339
|
-
let
|
|
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>
|
|
342
342
|
<pre>{JSON.stringify(items)}</pre>
|
|
343
|
-
<pre>{JSON.stringify(
|
|
343
|
+
<pre>{JSON.stringify(@concatenated)}</pre>
|
|
344
344
|
}
|
|
345
345
|
|
|
346
346
|
render(ArrayTest);
|
|
@@ -391,12 +391,12 @@ describe('RippleArray', () => {
|
|
|
391
391
|
it('handles $length property for reactivity', () => {
|
|
392
392
|
component ArrayTest() {
|
|
393
393
|
let items = new RippleArray(1, 2, 3);
|
|
394
|
-
let
|
|
394
|
+
let length = track(() => items.$length);
|
|
395
395
|
|
|
396
396
|
<button onClick={() => items.$length = 5}>{'expand'}</button>
|
|
397
397
|
<button onClick={() => items.$length = 2}>{'shrink'}</button>
|
|
398
398
|
<pre>{JSON.stringify(items)}</pre>
|
|
399
|
-
<pre>{
|
|
399
|
+
<pre>{@length}</pre>
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
render(ArrayTest);
|
|
@@ -481,12 +481,12 @@ describe('RippleArray', () => {
|
|
|
481
481
|
it('handles array index access with reactivity', () => {
|
|
482
482
|
component ArrayTest() {
|
|
483
483
|
let items = new RippleArray(10, 20, 30);
|
|
484
|
-
let
|
|
485
|
-
let
|
|
484
|
+
let firstItem = track(() => items[0]);
|
|
485
|
+
let secondItem = track(() => items[1]);
|
|
486
486
|
|
|
487
487
|
<button onClick={() => items[0] = 100}>{'change first'}</button>
|
|
488
|
-
<pre>{
|
|
489
|
-
<pre>{
|
|
488
|
+
<pre>{@firstItem}</pre>
|
|
489
|
+
<pre>{@secondItem}</pre>
|
|
490
490
|
<pre>{items[0]}</pre>
|
|
491
491
|
<pre>{items[1]}</pre>
|
|
492
492
|
}
|
|
@@ -540,15 +540,15 @@ describe('RippleArray', () => {
|
|
|
540
540
|
it('handles find and findIndex methods with reactivity', () => {
|
|
541
541
|
component ArrayTest() {
|
|
542
542
|
let items = new RippleArray(5, 10, 15, 20, 25);
|
|
543
|
-
let
|
|
544
|
-
let
|
|
543
|
+
let found = track(() => items.find(x => x > 12));
|
|
544
|
+
let foundIndex = track(() => items.findIndex(x => x > 12));
|
|
545
545
|
|
|
546
546
|
<button onClick={() => {
|
|
547
547
|
items[1] = 13;
|
|
548
548
|
items[0] = 6;
|
|
549
549
|
}}>{'update values'}</button>
|
|
550
|
-
<pre>{
|
|
551
|
-
<pre>{
|
|
550
|
+
<pre>{@found}</pre>
|
|
551
|
+
<pre>{@foundIndex}</pre>
|
|
552
552
|
}
|
|
553
553
|
|
|
554
554
|
render(ArrayTest);
|
|
@@ -572,15 +572,15 @@ describe('RippleArray', () => {
|
|
|
572
572
|
it('handles findLast and findLastIndex methods with reactivity', () => {
|
|
573
573
|
component ArrayTest() {
|
|
574
574
|
let items = new RippleArray(5, 15, 10, 20, 15);
|
|
575
|
-
let
|
|
576
|
-
let
|
|
575
|
+
let foundLast = track(() => items.findLast(x => x === 15));
|
|
576
|
+
let foundLastIndex = track(() => items.findLastIndex(x => x === 15));
|
|
577
577
|
|
|
578
578
|
<button onClick={() => {
|
|
579
579
|
items[1] = 25;
|
|
580
580
|
items[4] = 15;
|
|
581
581
|
}}>{'update values'}</button>
|
|
582
|
-
<pre>{
|
|
583
|
-
<pre>{
|
|
582
|
+
<pre>{@foundLast}</pre>
|
|
583
|
+
<pre>{@foundLastIndex}</pre>
|
|
584
584
|
}
|
|
585
585
|
|
|
586
586
|
render(ArrayTest);
|
|
@@ -602,14 +602,14 @@ describe('RippleArray', () => {
|
|
|
602
602
|
it('handles every method with reactivity', () => {
|
|
603
603
|
component ArrayTest() {
|
|
604
604
|
let items = new RippleArray(2, 4, 6, 8);
|
|
605
|
-
let
|
|
605
|
+
let allEven = track(() => items.every(x => x % 2 === 0));
|
|
606
606
|
|
|
607
607
|
<button onClick={() => items.push(3)}>{'add odd'}</button>
|
|
608
608
|
<button onClick={() => {
|
|
609
609
|
items.pop();
|
|
610
610
|
items.push(10);
|
|
611
611
|
}}>{'ensure all even'}</button>
|
|
612
|
-
<pre>{
|
|
612
|
+
<pre>{@allEven.toString()}</pre>
|
|
613
613
|
}
|
|
614
614
|
|
|
615
615
|
render(ArrayTest);
|
|
@@ -634,11 +634,11 @@ describe('RippleArray', () => {
|
|
|
634
634
|
it('handles flat method with reactivity', () => {
|
|
635
635
|
component ArrayTest() {
|
|
636
636
|
let items = new RippleArray([1, 2], [3, 4], 5);
|
|
637
|
-
let
|
|
637
|
+
let flattened = track(() => items.flat());
|
|
638
638
|
|
|
639
639
|
<button onClick={() => items[0] = [6, 7, 8]}>{'change nested'}</button>
|
|
640
640
|
<pre>{JSON.stringify(items)}</pre>
|
|
641
|
-
<pre>{JSON.stringify(
|
|
641
|
+
<pre>{JSON.stringify(@flattened)}</pre>
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
render(ArrayTest);
|
|
@@ -660,11 +660,11 @@ describe('RippleArray', () => {
|
|
|
660
660
|
it('handles flatMap method with reactivity', () => {
|
|
661
661
|
component ArrayTest() {
|
|
662
662
|
let items = new RippleArray(1, 2, 3);
|
|
663
|
-
let
|
|
663
|
+
let flatMapped = track(() => items.flatMap(x => [x, x * 2]));
|
|
664
664
|
|
|
665
665
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
666
666
|
<pre>{JSON.stringify(items)}</pre>
|
|
667
|
-
<pre>{JSON.stringify(
|
|
667
|
+
<pre>{JSON.stringify(@flatMapped)}</pre>
|
|
668
668
|
}
|
|
669
669
|
|
|
670
670
|
render(ArrayTest);
|
|
@@ -686,11 +686,11 @@ describe('RippleArray', () => {
|
|
|
686
686
|
it('handles join method with reactivity', () => {
|
|
687
687
|
component ArrayTest() {
|
|
688
688
|
let items = new RippleArray('apple', 'banana', 'cherry');
|
|
689
|
-
let
|
|
689
|
+
let joined = track(() => items.join(', '));
|
|
690
690
|
|
|
691
691
|
<button onClick={() => items.push('date')}>{'add item'}</button>
|
|
692
692
|
<pre>{JSON.stringify(items)}</pre>
|
|
693
|
-
<pre>{
|
|
693
|
+
<pre>{@joined}</pre>
|
|
694
694
|
}
|
|
695
695
|
|
|
696
696
|
render(ArrayTest);
|
|
@@ -712,11 +712,11 @@ describe('RippleArray', () => {
|
|
|
712
712
|
it('handles keys method with reactivity', () => {
|
|
713
713
|
component ArrayTest() {
|
|
714
714
|
let items = new RippleArray('a', 'b', 'c');
|
|
715
|
-
let
|
|
715
|
+
let keys = track(() => Array.from(items.keys()));
|
|
716
716
|
|
|
717
717
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
718
718
|
<pre>{JSON.stringify(items)}</pre>
|
|
719
|
-
<pre>{JSON.stringify(
|
|
719
|
+
<pre>{JSON.stringify(@keys)}</pre>
|
|
720
720
|
}
|
|
721
721
|
|
|
722
722
|
render(ArrayTest);
|
|
@@ -738,13 +738,13 @@ describe('RippleArray', () => {
|
|
|
738
738
|
it('handles lastIndexOf method with reactivity', () => {
|
|
739
739
|
component ArrayTest() {
|
|
740
740
|
let items = new RippleArray(1, 2, 3, 2, 1);
|
|
741
|
-
let
|
|
741
|
+
let lastIndex = track(() => items.lastIndexOf(2));
|
|
742
742
|
|
|
743
743
|
<button onClick={() => {
|
|
744
744
|
items.push(2);
|
|
745
745
|
}}>{'add duplicate'}</button>
|
|
746
746
|
<pre>{JSON.stringify(items)}</pre>
|
|
747
|
-
<pre>{
|
|
747
|
+
<pre>{@lastIndex}</pre>
|
|
748
748
|
}
|
|
749
749
|
|
|
750
750
|
render(ArrayTest);
|
|
@@ -766,11 +766,11 @@ describe('RippleArray', () => {
|
|
|
766
766
|
it('handles reduceRight method with reactivity', () => {
|
|
767
767
|
component ArrayTest() {
|
|
768
768
|
let items = new RippleArray('a', 'b', 'c');
|
|
769
|
-
let
|
|
769
|
+
let reduced = track(() => items.reduceRight((acc, val) => acc + val, ''));
|
|
770
770
|
|
|
771
771
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
772
772
|
<pre>{JSON.stringify(items)}</pre>
|
|
773
|
-
<pre>{
|
|
773
|
+
<pre>{@reduced}</pre>
|
|
774
774
|
}
|
|
775
775
|
|
|
776
776
|
render(ArrayTest);
|
|
@@ -792,14 +792,14 @@ describe('RippleArray', () => {
|
|
|
792
792
|
it('handles some method with reactivity', () => {
|
|
793
793
|
component ArrayTest() {
|
|
794
794
|
let items = new RippleArray(1, 3, 5, 7);
|
|
795
|
-
let
|
|
795
|
+
let hasEven = track(() => items.some(x => x % 2 === 0));
|
|
796
796
|
|
|
797
797
|
<button onClick={() => items.push(2)}>{'add even'}</button>
|
|
798
798
|
<button onClick={() => {
|
|
799
799
|
items.pop();
|
|
800
800
|
items.push(9);
|
|
801
801
|
}}>{'ensure all odd'}</button>
|
|
802
|
-
<pre>{
|
|
802
|
+
<pre>{@hasEven.toString()}</pre>
|
|
803
803
|
}
|
|
804
804
|
|
|
805
805
|
render(ArrayTest);
|
|
@@ -824,11 +824,11 @@ describe('RippleArray', () => {
|
|
|
824
824
|
it('handles toLocaleString method with reactivity', () => {
|
|
825
825
|
component ArrayTest() {
|
|
826
826
|
let items = new RippleArray(1000, 2000, 3000);
|
|
827
|
-
let
|
|
827
|
+
let localized = track(() => items.toLocaleString('en-US'));
|
|
828
828
|
|
|
829
829
|
<button onClick={() => {items[2] = 4000}}>{'add item'}</button>
|
|
830
830
|
<pre>{JSON.stringify(items)}</pre>
|
|
831
|
-
<pre>{
|
|
831
|
+
<pre>{@localized}</pre>
|
|
832
832
|
}
|
|
833
833
|
|
|
834
834
|
render(ArrayTest);
|
|
@@ -854,11 +854,11 @@ describe('RippleArray', () => {
|
|
|
854
854
|
|
|
855
855
|
component ArrayTest() {
|
|
856
856
|
let items = new RippleArray(1, 2, 3, 4);
|
|
857
|
-
let
|
|
857
|
+
let reversed = track(() => items.toReversed());
|
|
858
858
|
|
|
859
859
|
<button onClick={() => items.push(5)}>{'add item'}</button>
|
|
860
860
|
<pre>{JSON.stringify(items)}</pre>
|
|
861
|
-
<pre>{JSON.stringify(
|
|
861
|
+
<pre>{JSON.stringify(@reversed)}</pre>
|
|
862
862
|
}
|
|
863
863
|
|
|
864
864
|
render(ArrayTest);
|
|
@@ -884,11 +884,11 @@ describe('RippleArray', () => {
|
|
|
884
884
|
|
|
885
885
|
component ArrayTest() {
|
|
886
886
|
let items = new RippleArray(3, 1, 4, 2);
|
|
887
|
-
let
|
|
887
|
+
let sorted = track(() => items.toSorted());
|
|
888
888
|
|
|
889
889
|
<button onClick={() => items.push(0)}>{'add item'}</button>
|
|
890
890
|
<pre>{JSON.stringify(items)}</pre>
|
|
891
|
-
<pre>{JSON.stringify(
|
|
891
|
+
<pre>{JSON.stringify(@sorted)}</pre>
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
render(ArrayTest);
|
|
@@ -914,11 +914,11 @@ describe('RippleArray', () => {
|
|
|
914
914
|
|
|
915
915
|
component ArrayTest() {
|
|
916
916
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
917
|
-
let
|
|
917
|
+
let spliced = track(() => items.toSpliced(1, 2, 'a', 'b'));
|
|
918
918
|
|
|
919
919
|
<button onClick={() => items[2] = 30}>{'change item'}</button>
|
|
920
920
|
<pre>{JSON.stringify(items)}</pre>
|
|
921
|
-
<pre>{JSON.stringify(
|
|
921
|
+
<pre>{JSON.stringify(@spliced)}</pre>
|
|
922
922
|
}
|
|
923
923
|
|
|
924
924
|
render(ArrayTest);
|
|
@@ -940,11 +940,11 @@ describe('RippleArray', () => {
|
|
|
940
940
|
it('handles toString method with reactivity', () => {
|
|
941
941
|
component ArrayTest() {
|
|
942
942
|
let items = new RippleArray(1, 2, 3);
|
|
943
|
-
let
|
|
943
|
+
let string = track(() => items.toString());
|
|
944
944
|
|
|
945
945
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
946
946
|
<pre>{JSON.stringify(items)}</pre>
|
|
947
|
-
<pre>{
|
|
947
|
+
<pre>{@string}</pre>
|
|
948
948
|
}
|
|
949
949
|
|
|
950
950
|
render(ArrayTest);
|
|
@@ -966,20 +966,20 @@ describe('RippleArray', () => {
|
|
|
966
966
|
it('handles Symbol.iterator with reactivity', () => {
|
|
967
967
|
component ArrayTest() {
|
|
968
968
|
let items = new RippleArray(1, 2, 3);
|
|
969
|
-
let
|
|
969
|
+
let sum = track(0);
|
|
970
970
|
|
|
971
971
|
effect(() => {
|
|
972
|
-
|
|
972
|
+
@sum = 0;
|
|
973
973
|
for (const item of items) {
|
|
974
974
|
untrack(() => {
|
|
975
|
-
|
|
975
|
+
@sum += item;
|
|
976
976
|
});
|
|
977
977
|
}
|
|
978
978
|
});
|
|
979
979
|
|
|
980
980
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
981
981
|
<pre>{JSON.stringify(items)}</pre>
|
|
982
|
-
<pre>{
|
|
982
|
+
<pre>{@sum}</pre>
|
|
983
983
|
}
|
|
984
984
|
|
|
985
985
|
render(ArrayTest);
|
|
@@ -1000,11 +1000,11 @@ describe('RippleArray', () => {
|
|
|
1000
1000
|
it('handles values method with reactivity', () => {
|
|
1001
1001
|
component ArrayTest() {
|
|
1002
1002
|
let items = new RippleArray('a', 'b', 'c');
|
|
1003
|
-
let
|
|
1003
|
+
let values = track(() => Array.from(items.values()));
|
|
1004
1004
|
|
|
1005
1005
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
1006
1006
|
<pre>{JSON.stringify(items)}</pre>
|
|
1007
|
-
<pre>{JSON.stringify(
|
|
1007
|
+
<pre>{JSON.stringify(@values)}</pre>
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
1010
|
render(ArrayTest);
|
|
@@ -1030,11 +1030,11 @@ describe('RippleArray', () => {
|
|
|
1030
1030
|
|
|
1031
1031
|
component ArrayTest() {
|
|
1032
1032
|
let items = new RippleArray(1, 2, 3, 4);
|
|
1033
|
-
let
|
|
1033
|
+
let withReplaced = track(() => items.with(2, 30));
|
|
1034
1034
|
|
|
1035
1035
|
<button onClick={() => items[2] = 50}>{'change original'}</button>
|
|
1036
1036
|
<pre>{JSON.stringify(items)}</pre>
|
|
1037
|
-
<pre>{JSON.stringify(
|
|
1037
|
+
<pre>{JSON.stringify(@withReplaced)}</pre>
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
1040
|
render(ArrayTest);
|
|
@@ -1056,16 +1056,16 @@ describe('RippleArray', () => {
|
|
|
1056
1056
|
it('handles at method with reactivity', () => {
|
|
1057
1057
|
component ArrayTest() {
|
|
1058
1058
|
let items = new RippleArray(10, 20, 30, 40, 50);
|
|
1059
|
-
let
|
|
1060
|
-
let
|
|
1061
|
-
let
|
|
1059
|
+
let atIndex2 = track(() => items.at(2));
|
|
1060
|
+
let atNegative1 = track(() => items.at(-1));
|
|
1061
|
+
let atNegative2 = track(() => items.at(-2));
|
|
1062
1062
|
|
|
1063
1063
|
<button onClick={() => items[2] = 300}>{'change index 2'}</button>
|
|
1064
1064
|
<button onClick={() => items[items.length - 1] = 500}>{'change last'}</button>
|
|
1065
1065
|
<pre>{JSON.stringify(items)}</pre>
|
|
1066
|
-
<pre>{
|
|
1067
|
-
<pre>{
|
|
1068
|
-
<pre>{
|
|
1066
|
+
<pre>{@atIndex2}</pre>
|
|
1067
|
+
<pre>{@atNegative1}</pre>
|
|
1068
|
+
<pre>{@atNegative2}</pre>
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
1071
1071
|
render(ArrayTest);
|
|
@@ -1101,14 +1101,14 @@ describe('RippleArray', () => {
|
|
|
1101
1101
|
it('handles ARRAY_SET_INDEX_AT method with reactivity', () => {
|
|
1102
1102
|
component ArrayTest() {
|
|
1103
1103
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
1104
|
-
let
|
|
1104
|
+
let thirdItem = track(() => items[2]);
|
|
1105
1105
|
|
|
1106
1106
|
<button onClick={() => items[ARRAY_SET_INDEX_AT](2, 30)}>{'set index 2'}</button>
|
|
1107
1107
|
<button onClick={() => items[ARRAY_SET_INDEX_AT](-1, 50)}>{'set last with negative'}</button>
|
|
1108
1108
|
<button onClick={() => items[ARRAY_SET_INDEX_AT](6, 60)}>{'extend array'}</button>
|
|
1109
1109
|
<pre>{JSON.stringify(items)}</pre>
|
|
1110
1110
|
<pre>{items.$length}</pre>
|
|
1111
|
-
<pre>{
|
|
1111
|
+
<pre>{@thirdItem}</pre>
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
1114
1114
|
render(ArrayTest);
|
|
@@ -1148,24 +1148,24 @@ describe('RippleArray', () => {
|
|
|
1148
1148
|
it('handles ARRAY_SET_INDEX_AT error cases', () => {
|
|
1149
1149
|
component ArrayTest() {
|
|
1150
1150
|
let items = new RippleArray(1, 2, 3);
|
|
1151
|
-
let
|
|
1151
|
+
let error = track(null);
|
|
1152
1152
|
|
|
1153
1153
|
<button onClick={() => {
|
|
1154
1154
|
try {
|
|
1155
1155
|
items[ARRAY_SET_INDEX_AT](1.5, 10);
|
|
1156
1156
|
} catch (e) {
|
|
1157
|
-
|
|
1157
|
+
@error = e.message;
|
|
1158
1158
|
}
|
|
1159
1159
|
}}>{'try non-integer'}</button>
|
|
1160
1160
|
<button onClick={() => {
|
|
1161
1161
|
try {
|
|
1162
|
-
|
|
1162
|
+
@error = null;
|
|
1163
1163
|
items[ARRAY_SET_INDEX_AT](-5, 10);
|
|
1164
1164
|
} catch (e) {
|
|
1165
|
-
|
|
1165
|
+
@error = e.message;
|
|
1166
1166
|
}
|
|
1167
1167
|
}}>{'try out of bounds negative'}</button>
|
|
1168
|
-
<pre>{
|
|
1168
|
+
<pre>{@error}</pre>
|
|
1169
1169
|
}
|
|
1170
1170
|
|
|
1171
1171
|
render(ArrayTest);
|
|
@@ -1223,16 +1223,16 @@ describe('RippleArray', () => {
|
|
|
1223
1223
|
it('throws error when trying to set length property directly', () => {
|
|
1224
1224
|
component ArrayTest() {
|
|
1225
1225
|
let items = new RippleArray(1, 2, 3);
|
|
1226
|
-
let
|
|
1226
|
+
let error = track(null);
|
|
1227
1227
|
|
|
1228
1228
|
<button onClick={() => {
|
|
1229
1229
|
try {
|
|
1230
1230
|
items.length = 5;
|
|
1231
1231
|
} catch (e) {
|
|
1232
|
-
|
|
1232
|
+
@error = e.message;
|
|
1233
1233
|
}
|
|
1234
1234
|
}}>{'try set length'}</button>
|
|
1235
|
-
<pre>{
|
|
1235
|
+
<pre>{@error}</pre>
|
|
1236
1236
|
}
|
|
1237
1237
|
|
|
1238
1238
|
render(ArrayTest);
|
|
@@ -1353,16 +1353,16 @@ describe('RippleArray', () => {
|
|
|
1353
1353
|
it('handles copyWithin operation with reactivity', () => {
|
|
1354
1354
|
component ArrayTest() {
|
|
1355
1355
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
1356
|
-
let
|
|
1357
|
-
let
|
|
1358
|
-
let
|
|
1356
|
+
let firstItem = track(() => items[0]);
|
|
1357
|
+
let thirdItem = track(() => items[2]);
|
|
1358
|
+
let fourthItem = track(() => items[3]);
|
|
1359
1359
|
|
|
1360
1360
|
<button onClick={() => items.copyWithin(0, 3)}>{'copy end to start'}</button>
|
|
1361
1361
|
<button onClick={() => items.copyWithin(2, 0, 2)}>{'copy start to middle'}</button>
|
|
1362
1362
|
<pre>{JSON.stringify(items)}</pre>
|
|
1363
|
-
<pre>{
|
|
1364
|
-
<pre>{
|
|
1365
|
-
<pre>{
|
|
1363
|
+
<pre>{@firstItem}</pre>
|
|
1364
|
+
<pre>{@thirdItem}</pre>
|
|
1365
|
+
<pre>{@fourthItem}</pre>
|
|
1366
1366
|
}
|
|
1367
1367
|
|
|
1368
1368
|
render(ArrayTest);
|
|
@@ -1398,13 +1398,13 @@ describe('RippleArray', () => {
|
|
|
1398
1398
|
it('handles copyWithin with negative indexes and reactivity', () => {
|
|
1399
1399
|
component ArrayTest() {
|
|
1400
1400
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
1401
|
-
let
|
|
1402
|
-
let
|
|
1401
|
+
let secondItem = track(() => items[1]);
|
|
1402
|
+
let thirdItem = track(() => items[2]);
|
|
1403
1403
|
|
|
1404
1404
|
<button onClick={() => items.copyWithin(-4, -2)}>{'copy with negative indexes'}</button>
|
|
1405
1405
|
<pre>{JSON.stringify(items)}</pre>
|
|
1406
|
-
<pre>{
|
|
1407
|
-
<pre>{
|
|
1406
|
+
<pre>{@secondItem}</pre>
|
|
1407
|
+
<pre>{@thirdItem}</pre>
|
|
1408
1408
|
}
|
|
1409
1409
|
|
|
1410
1410
|
render(ArrayTest);
|
|
@@ -1429,12 +1429,12 @@ describe('RippleArray', () => {
|
|
|
1429
1429
|
it('handles copyWithin with overlapping ranges', () => {
|
|
1430
1430
|
component ArrayTest() {
|
|
1431
1431
|
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
1432
|
-
let
|
|
1432
|
+
let entries = track(() => items.entries());
|
|
1433
1433
|
|
|
1434
1434
|
<button onClick={() => items.copyWithin(2, 1, 4)}>{'copy with overlap'}</button>
|
|
1435
1435
|
<pre>{JSON.stringify(items)}</pre>
|
|
1436
1436
|
|
|
1437
|
-
for (const [i, value] of
|
|
1437
|
+
for (const [i, value] of @entries) {
|
|
1438
1438
|
<pre>{`items[${i}]: ${value}`}</pre>
|
|
1439
1439
|
}
|
|
1440
1440
|
}
|