ripple 0.3.71 → 0.3.74
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/CHANGELOG.md +75 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +2 -8
- package/src/runtime/index-client.js +3 -13
- package/src/runtime/internal/client/blocks.js +3 -25
- package/src/runtime/internal/client/for.js +80 -5
- package/src/runtime/internal/client/index.js +0 -2
- package/src/runtime/internal/client/types.d.ts +0 -10
- package/tests/client/__snapshots__/computed-properties.test.tsrx.snap +8 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +22 -0
- package/tests/client/__snapshots__/html.test.tsrx.snap +4 -0
- package/tests/client/array/array.copy-within.test.tsrx +19 -19
- package/tests/client/array/array.derived.test.tsrx +97 -109
- package/tests/client/array/array.iteration.test.tsrx +28 -28
- package/tests/client/array/array.mutations.test.tsrx +68 -68
- package/tests/client/array/array.static.test.tsrx +82 -92
- package/tests/client/array/array.to-methods.test.tsrx +15 -15
- package/tests/client/async-suspend.test.tsrx +180 -179
- package/tests/client/basic/__snapshots__/basic.attributes.test.tsrx.snap +2 -0
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +4 -0
- package/tests/client/basic/basic.attributes.test.tsrx +273 -317
- package/tests/client/basic/basic.collections.test.tsrx +59 -71
- package/tests/client/basic/basic.components.test.tsrx +196 -222
- package/tests/client/basic/basic.errors.test.tsrx +72 -78
- package/tests/client/basic/basic.events.test.tsrx +80 -85
- package/tests/client/basic/basic.get-set.test.tsrx +54 -64
- package/tests/client/basic/basic.hmr.test.tsrx +15 -19
- package/tests/client/basic/basic.reactivity.test.tsrx +121 -135
- package/tests/client/basic/basic.rendering.test.tsrx +273 -178
- package/tests/client/basic/basic.utilities.test.tsrx +8 -10
- package/tests/client/boundaries.test.tsrx +18 -18
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -76
- package/tests/client/compiler/compiler.attributes.test.tsrx +18 -14
- package/tests/client/compiler/compiler.basic.test.tsrx +364 -296
- package/tests/client/compiler/compiler.regex.test.tsrx +40 -44
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +57 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +4 -3
- package/tests/client/composite/composite.dynamic-components.test.tsrx +41 -44
- package/tests/client/composite/composite.generics.test.tsrx +165 -167
- package/tests/client/composite/composite.props.test.tsrx +66 -74
- package/tests/client/composite/composite.reactivity.test.tsrx +132 -166
- package/tests/client/composite/composite.render.test.tsrx +92 -101
- package/tests/client/computed-properties.test.tsrx +14 -18
- package/tests/client/context.test.tsrx +14 -18
- package/tests/client/css/global-additional-cases.test.tsrx +491 -437
- package/tests/client/css/global-advanced-selectors.test.tsrx +169 -153
- package/tests/client/css/global-at-rules.test.tsrx +71 -66
- package/tests/client/css/global-basic.test.tsrx +105 -98
- package/tests/client/css/global-classes-ids.test.tsrx +128 -114
- package/tests/client/css/global-combinators.test.tsrx +83 -78
- package/tests/client/css/global-complex-nesting.test.tsrx +134 -120
- package/tests/client/css/global-edge-cases.test.tsrx +138 -120
- package/tests/client/css/global-keyframes.test.tsrx +108 -96
- package/tests/client/css/global-nested.test.tsrx +88 -78
- package/tests/client/css/global-pseudo.test.tsrx +104 -98
- package/tests/client/css/global-scoping.test.tsrx +145 -125
- package/tests/client/css/style-identifier.test.tsrx +62 -69
- package/tests/client/date.test.tsrx +83 -83
- package/tests/client/dynamic-elements.test.tsrx +227 -283
- package/tests/client/events.test.tsrx +252 -266
- package/tests/client/for.test.tsrx +120 -127
- package/tests/client/head.test.tsrx +40 -48
- package/tests/client/html.test.tsrx +37 -49
- package/tests/client/input-value.test.tsrx +1125 -1354
- package/tests/client/lazy-array.test.tsrx +10 -16
- package/tests/client/lazy-destructuring.test.tsrx +169 -221
- package/tests/client/map.test.tsrx +39 -41
- package/tests/client/media-query.test.tsrx +15 -19
- package/tests/client/object.test.tsrx +46 -56
- package/tests/client/portal.test.tsrx +31 -37
- package/tests/client/ref.test.tsrx +173 -193
- package/tests/client/return.test.tsrx +62 -37
- package/tests/client/set.test.tsrx +33 -33
- package/tests/client/svg.test.tsrx +195 -215
- package/tests/client/switch.test.tsrx +201 -191
- package/tests/client/track-async-hydration.test.tsrx +14 -18
- package/tests/client/tracked-index-access.test.tsrx +18 -28
- package/tests/client/try.test.tsrx +494 -619
- package/tests/client/tsx.test.tsrx +290 -371
- package/tests/client/typescript-generics.test.tsrx +121 -129
- package/tests/client/url/url.derived.test.tsrx +21 -25
- package/tests/client/url/url.parsing.test.tsrx +35 -35
- package/tests/client/url/url.partial-removal.test.tsrx +32 -32
- package/tests/client/url/url.reactivity.test.tsrx +68 -72
- package/tests/client/url/url.serialization.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +21 -27
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +16 -16
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +37 -37
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +56 -60
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +32 -34
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +9 -9
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +10 -10
- package/tests/hydration/compiled/client/basic.js +396 -325
- package/tests/hydration/compiled/client/composite.js +52 -44
- package/tests/hydration/compiled/client/for.js +734 -604
- package/tests/hydration/compiled/client/head.js +183 -103
- package/tests/hydration/compiled/client/html.js +93 -86
- package/tests/hydration/compiled/client/if-children.js +95 -71
- package/tests/hydration/compiled/client/if.js +113 -89
- package/tests/hydration/compiled/client/mixed-control-flow.js +225 -209
- package/tests/hydration/compiled/client/nested-control-flow.js +94 -98
- package/tests/hydration/compiled/client/reactivity.js +26 -24
- package/tests/hydration/compiled/client/return.js +8 -42
- package/tests/hydration/compiled/client/switch.js +208 -173
- package/tests/hydration/compiled/client/track-async-serialization.js +176 -128
- package/tests/hydration/compiled/client/try.js +29 -21
- package/tests/hydration/compiled/server/basic.js +210 -221
- package/tests/hydration/compiled/server/composite.js +13 -14
- package/tests/hydration/compiled/server/for.js +427 -444
- package/tests/hydration/compiled/server/head.js +199 -189
- package/tests/hydration/compiled/server/html.js +33 -41
- package/tests/hydration/compiled/server/if-children.js +114 -117
- package/tests/hydration/compiled/server/if.js +77 -83
- package/tests/hydration/compiled/server/mixed-control-flow.js +145 -150
- package/tests/hydration/compiled/server/nested-control-flow.js +10 -0
- package/tests/hydration/compiled/server/reactivity.js +24 -22
- package/tests/hydration/compiled/server/return.js +6 -18
- package/tests/hydration/compiled/server/switch.js +179 -176
- package/tests/hydration/compiled/server/track-async-serialization.js +88 -70
- package/tests/hydration/compiled/server/try.js +31 -35
- package/tests/hydration/components/basic.tsrx +216 -286
- package/tests/hydration/components/composite.tsrx +32 -42
- package/tests/hydration/components/events.tsrx +81 -101
- package/tests/hydration/components/for.tsrx +270 -336
- package/tests/hydration/components/head.tsrx +43 -39
- package/tests/hydration/components/hmr.tsrx +16 -22
- package/tests/hydration/components/html-in-template.tsrx +15 -21
- package/tests/hydration/components/html.tsrx +442 -526
- package/tests/hydration/components/if-children.tsrx +107 -125
- package/tests/hydration/components/if.tsrx +68 -90
- package/tests/hydration/components/mixed-control-flow.tsrx +65 -72
- package/tests/hydration/components/nested-control-flow.tsrx +202 -216
- package/tests/hydration/components/portal.tsrx +33 -41
- package/tests/hydration/components/reactivity.tsrx +26 -34
- package/tests/hydration/components/return.tsrx +4 -6
- package/tests/hydration/components/switch.tsrx +73 -78
- package/tests/hydration/components/track-async-serialization.tsrx +83 -93
- package/tests/hydration/components/try.tsrx +37 -51
- package/tests/hydration/switch.test.js +8 -8
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +120 -167
- package/tests/server/basic.components.test.tsrx +163 -197
- package/tests/server/basic.test.tsrx +298 -220
- package/tests/server/compiler.test.tsrx +142 -72
- package/tests/server/composite.props.test.tsrx +54 -58
- package/tests/server/composite.test.tsrx +165 -167
- package/tests/server/context.test.tsrx +13 -17
- package/tests/server/dynamic-elements.test.tsrx +103 -135
- package/tests/server/for.test.tsrx +115 -84
- package/tests/server/head.test.tsrx +31 -31
- package/tests/server/html-nesting-validation.test.tsrx +16 -8
- package/tests/server/if.test.tsrx +49 -59
- package/tests/server/lazy-destructuring.test.tsrx +288 -366
- package/tests/server/return.test.tsrx +58 -36
- package/tests/server/streaming-ssr.test.tsrx +4 -4
- package/tests/server/style-identifier.test.tsrx +58 -66
- package/tests/server/switch.test.tsrx +89 -97
- package/tests/server/track-async-serialization.test.tsrx +85 -103
- package/tests/server/try.test.tsrx +275 -360
- package/tests/utils/ref-types.test.js +72 -0
- package/tests/utils/vite-plugin-config.test.js +41 -74
- package/types/index.d.ts +1 -0
- package/src/runtime/internal/client/compat.js +0 -40
- package/tests/utils/compiler-compat-config.test.js +0 -38
|
@@ -2,19 +2,19 @@ import { RippleArray, flushSync, track } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('RippleArray copyWithin', () => {
|
|
4
4
|
it('handles copyWithin operation with reactivity', () => {
|
|
5
|
-
function ArrayTest() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
function ArrayTest() @{
|
|
6
|
+
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
7
|
+
let &[firstItem] = track(() => items[0]);
|
|
8
|
+
let &[thirdItem] = track(() => items[2]);
|
|
9
|
+
let &[fourthItem] = track(() => items[3]);
|
|
10
|
+
<>
|
|
11
11
|
<button onClick={() => items.copyWithin(0, 3)}>{'copy end to start'}</button>
|
|
12
12
|
<button onClick={() => items.copyWithin(2, 0, 2)}>{'copy start to middle'}</button>
|
|
13
13
|
<pre>{JSON.stringify(items)}</pre>
|
|
14
14
|
<pre>{firstItem}</pre>
|
|
15
15
|
<pre>{thirdItem}</pre>
|
|
16
16
|
<pre>{fourthItem}</pre>
|
|
17
|
-
|
|
17
|
+
</>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
render(ArrayTest);
|
|
@@ -48,16 +48,16 @@ describe('RippleArray copyWithin', () => {
|
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it('handles copyWithin with negative indexes and reactivity', () => {
|
|
51
|
-
function ArrayTest() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
function ArrayTest() @{
|
|
52
|
+
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
53
|
+
let &[secondItem] = track(() => items[1]);
|
|
54
|
+
let &[thirdItem] = track(() => items[2]);
|
|
55
|
+
<>
|
|
56
56
|
<button onClick={() => items.copyWithin(-4, -2)}>{'copy with negative indexes'}</button>
|
|
57
57
|
<pre>{JSON.stringify(items)}</pre>
|
|
58
58
|
<pre>{secondItem}</pre>
|
|
59
59
|
<pre>{thirdItem}</pre>
|
|
60
|
-
|
|
60
|
+
</>
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
render(ArrayTest);
|
|
@@ -80,16 +80,16 @@ describe('RippleArray copyWithin', () => {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('handles copyWithin with overlapping ranges', () => {
|
|
83
|
-
function ArrayTest() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
function ArrayTest() @{
|
|
84
|
+
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
85
|
+
let &[entries] = track(() => Array.from(items.entries()));
|
|
86
|
+
<>
|
|
87
87
|
<button onClick={() => items.copyWithin(2, 1, 4)}>{'copy with overlap'}</button>
|
|
88
88
|
<pre>{JSON.stringify(items)}</pre>
|
|
89
|
-
for (const [i, value] of entries) {
|
|
89
|
+
@for (const [i, value] of entries) {
|
|
90
90
|
<pre>{`items[${i}]: ${value}`}</pre>
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
</>
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
render(ArrayTest);
|
|
@@ -2,19 +2,19 @@ import { RippleArray, flushSync, track } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('RippleArray > derived', () => {
|
|
4
4
|
it('handles array methods that return values (map, filter, etc.)', () => {
|
|
5
|
-
function ArrayTest() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
function ArrayTest() @{
|
|
6
|
+
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
7
|
+
let &[doubled] = track(() => items.map((x) => x * 2));
|
|
8
|
+
let &[filtered] = track(() => items.filter((x) => x % 2 === 0));
|
|
9
|
+
let &[reduced] = track(() => items.reduce((acc, val) => acc + val, 0));
|
|
10
|
+
let &[includes] = track(() => items.includes(3));
|
|
11
|
+
<>
|
|
12
12
|
<button onClick={() => items.push(6)}>{'add item'}</button>
|
|
13
13
|
<pre>{JSON.stringify(doubled)}</pre>
|
|
14
14
|
<pre>{JSON.stringify(filtered)}</pre>
|
|
15
15
|
<pre>{reduced}</pre>
|
|
16
16
|
<pre>{includes.toString()}</pre>
|
|
17
|
-
|
|
17
|
+
</>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
render(ArrayTest);
|
|
@@ -38,14 +38,14 @@ describe('RippleArray > derived', () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
it('handles concat method with reactivity', () => {
|
|
41
|
-
function ArrayTest() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
function ArrayTest() @{
|
|
42
|
+
let items = new RippleArray(1, 2, 3);
|
|
43
|
+
let &[concatenated] = track(() => items.concat([4, 5], 6, [7, 8]));
|
|
44
|
+
<>
|
|
45
45
|
<button onClick={() => items.push(3.5)}>{'add to original'}</button>
|
|
46
46
|
<pre>{JSON.stringify(items)}</pre>
|
|
47
47
|
<pre>{JSON.stringify(concatenated)}</pre>
|
|
48
|
-
|
|
48
|
+
</>
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
render(ArrayTest);
|
|
@@ -65,14 +65,14 @@ describe('RippleArray > derived', () => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('handles array slice method with reactivity', () => {
|
|
68
|
-
function ArrayTest() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
function ArrayTest() @{
|
|
69
|
+
let items = new RippleArray(1, 2, 3, 4, 5);
|
|
70
|
+
let &[sliced] = track(() => items.slice(1, 4));
|
|
71
|
+
<>
|
|
72
72
|
<button onClick={() => (items[2] = 30)}>{'change middle'}</button>
|
|
73
73
|
<pre>{JSON.stringify(items)}</pre>
|
|
74
74
|
<pre>{JSON.stringify(sliced)}</pre>
|
|
75
|
-
|
|
75
|
+
</>
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
render(ArrayTest);
|
|
@@ -92,22 +92,20 @@ describe('RippleArray > derived', () => {
|
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it('handles find and findIndex methods with reactivity', () => {
|
|
95
|
-
function ArrayTest() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
function ArrayTest() @{
|
|
96
|
+
let items = new RippleArray(5, 10, 15, 20, 25);
|
|
97
|
+
let &[found] = track(() => items.find((x) => x > 12));
|
|
98
|
+
let &[foundIndex] = track(() => items.findIndex((x) => x > 12));
|
|
99
|
+
<>
|
|
100
100
|
<button
|
|
101
101
|
onClick={() => {
|
|
102
102
|
items[1] = 13;
|
|
103
103
|
items[0] = 6;
|
|
104
104
|
}}
|
|
105
|
-
>
|
|
106
|
-
{'update values'}
|
|
107
|
-
</button>
|
|
105
|
+
>{'update values'}</button>
|
|
108
106
|
<pre>{found}</pre>
|
|
109
107
|
<pre>{foundIndex}</pre>
|
|
110
|
-
|
|
108
|
+
</>
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
render(ArrayTest);
|
|
@@ -127,22 +125,20 @@ describe('RippleArray > derived', () => {
|
|
|
127
125
|
});
|
|
128
126
|
|
|
129
127
|
it('handles findLast and findLastIndex methods with reactivity', () => {
|
|
130
|
-
function ArrayTest() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
function ArrayTest() @{
|
|
129
|
+
let items = new RippleArray(5, 15, 10, 20, 15);
|
|
130
|
+
let &[foundLast] = track(() => items.findLast((x) => x === 15));
|
|
131
|
+
let &[foundLastIndex] = track(() => items.findLastIndex((x) => x === 15));
|
|
132
|
+
<>
|
|
135
133
|
<button
|
|
136
134
|
onClick={() => {
|
|
137
135
|
items[1] = 25;
|
|
138
136
|
items[4] = 15;
|
|
139
137
|
}}
|
|
140
|
-
>
|
|
141
|
-
{'update values'}
|
|
142
|
-
</button>
|
|
138
|
+
>{'update values'}</button>
|
|
143
139
|
<pre>{foundLast}</pre>
|
|
144
140
|
<pre>{foundLastIndex}</pre>
|
|
145
|
-
|
|
141
|
+
</>
|
|
146
142
|
}
|
|
147
143
|
|
|
148
144
|
render(ArrayTest);
|
|
@@ -162,21 +158,19 @@ describe('RippleArray > derived', () => {
|
|
|
162
158
|
});
|
|
163
159
|
|
|
164
160
|
it('handles every method with reactivity', () => {
|
|
165
|
-
function ArrayTest() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
161
|
+
function ArrayTest() @{
|
|
162
|
+
let items = new RippleArray(2, 4, 6, 8);
|
|
163
|
+
let &[allEven] = track(() => items.every((x) => x % 2 === 0));
|
|
164
|
+
<>
|
|
169
165
|
<button onClick={() => items.push(3)}>{'add odd'}</button>
|
|
170
166
|
<button
|
|
171
167
|
onClick={() => {
|
|
172
168
|
items.pop();
|
|
173
169
|
items.push(10);
|
|
174
170
|
}}
|
|
175
|
-
>
|
|
176
|
-
{'ensure all even'}
|
|
177
|
-
</button>
|
|
171
|
+
>{'ensure all even'}</button>
|
|
178
172
|
<pre>{allEven.toString()}</pre>
|
|
179
|
-
|
|
173
|
+
</>
|
|
180
174
|
}
|
|
181
175
|
|
|
182
176
|
render(ArrayTest);
|
|
@@ -199,14 +193,14 @@ describe('RippleArray > derived', () => {
|
|
|
199
193
|
});
|
|
200
194
|
|
|
201
195
|
it('handles flat method with reactivity', () => {
|
|
202
|
-
function ArrayTest() {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
196
|
+
function ArrayTest() @{
|
|
197
|
+
let items = new RippleArray<number | number[]>([1, 2], [3, 4], 5);
|
|
198
|
+
let &[flattened] = track(() => items.flat());
|
|
199
|
+
<>
|
|
206
200
|
<button onClick={() => (items[0] = [6, 7, 8])}>{'change nested'}</button>
|
|
207
201
|
<pre>{JSON.stringify(items)}</pre>
|
|
208
202
|
<pre>{JSON.stringify(flattened)}</pre>
|
|
209
|
-
|
|
203
|
+
</>
|
|
210
204
|
}
|
|
211
205
|
|
|
212
206
|
render(ArrayTest);
|
|
@@ -226,14 +220,14 @@ describe('RippleArray > derived', () => {
|
|
|
226
220
|
});
|
|
227
221
|
|
|
228
222
|
it('handles flatMap method with reactivity', () => {
|
|
229
|
-
function ArrayTest() {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
function ArrayTest() @{
|
|
224
|
+
let items = new RippleArray(1, 2, 3);
|
|
225
|
+
let &[flatMapped] = track(() => items.flatMap((x) => [x, x * 2]));
|
|
226
|
+
<>
|
|
233
227
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
234
228
|
<pre>{JSON.stringify(items)}</pre>
|
|
235
229
|
<pre>{JSON.stringify(flatMapped)}</pre>
|
|
236
|
-
|
|
230
|
+
</>
|
|
237
231
|
}
|
|
238
232
|
|
|
239
233
|
render(ArrayTest);
|
|
@@ -253,14 +247,14 @@ describe('RippleArray > derived', () => {
|
|
|
253
247
|
});
|
|
254
248
|
|
|
255
249
|
it('handles join method with reactivity', () => {
|
|
256
|
-
function ArrayTest() {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
250
|
+
function ArrayTest() @{
|
|
251
|
+
let items = new RippleArray('apple', 'banana', 'cherry');
|
|
252
|
+
let &[joined] = track(() => items.join(', '));
|
|
253
|
+
<>
|
|
260
254
|
<button onClick={() => items.push('date')}>{'add item'}</button>
|
|
261
255
|
<pre>{JSON.stringify(items)}</pre>
|
|
262
256
|
<pre>{joined}</pre>
|
|
263
|
-
|
|
257
|
+
</>
|
|
264
258
|
}
|
|
265
259
|
|
|
266
260
|
render(ArrayTest);
|
|
@@ -282,20 +276,18 @@ describe('RippleArray > derived', () => {
|
|
|
282
276
|
});
|
|
283
277
|
|
|
284
278
|
it('handles lastIndexOf method with reactivity', () => {
|
|
285
|
-
function ArrayTest() {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
279
|
+
function ArrayTest() @{
|
|
280
|
+
let items = new RippleArray(1, 2, 3, 2, 1);
|
|
281
|
+
let &[lastIndex] = track(() => items.lastIndexOf(2));
|
|
282
|
+
<>
|
|
289
283
|
<button
|
|
290
284
|
onClick={() => {
|
|
291
285
|
items.push(2);
|
|
292
286
|
}}
|
|
293
|
-
>
|
|
294
|
-
{'add duplicate'}
|
|
295
|
-
</button>
|
|
287
|
+
>{'add duplicate'}</button>
|
|
296
288
|
<pre>{JSON.stringify(items)}</pre>
|
|
297
289
|
<pre>{lastIndex}</pre>
|
|
298
|
-
|
|
290
|
+
</>
|
|
299
291
|
}
|
|
300
292
|
|
|
301
293
|
render(ArrayTest);
|
|
@@ -315,14 +307,14 @@ describe('RippleArray > derived', () => {
|
|
|
315
307
|
});
|
|
316
308
|
|
|
317
309
|
it('handles reduceRight method with reactivity', () => {
|
|
318
|
-
function ArrayTest() {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
310
|
+
function ArrayTest() @{
|
|
311
|
+
let items = new RippleArray('a', 'b', 'c');
|
|
312
|
+
let &[reduced] = track(() => items.reduceRight((acc, val) => acc + val, ''));
|
|
313
|
+
<>
|
|
322
314
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
323
315
|
<pre>{JSON.stringify(items)}</pre>
|
|
324
316
|
<pre>{reduced}</pre>
|
|
325
|
-
|
|
317
|
+
</>
|
|
326
318
|
}
|
|
327
319
|
|
|
328
320
|
render(ArrayTest);
|
|
@@ -342,21 +334,19 @@ describe('RippleArray > derived', () => {
|
|
|
342
334
|
});
|
|
343
335
|
|
|
344
336
|
it('handles some method with reactivity', () => {
|
|
345
|
-
function ArrayTest() {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
337
|
+
function ArrayTest() @{
|
|
338
|
+
let items = new RippleArray(1, 3, 5, 7);
|
|
339
|
+
let &[hasEven] = track(() => items.some((x) => x % 2 === 0));
|
|
340
|
+
<>
|
|
349
341
|
<button onClick={() => items.push(2)}>{'add even'}</button>
|
|
350
342
|
<button
|
|
351
343
|
onClick={() => {
|
|
352
344
|
items.pop();
|
|
353
345
|
items.push(9);
|
|
354
346
|
}}
|
|
355
|
-
>
|
|
356
|
-
{'ensure all odd'}
|
|
357
|
-
</button>
|
|
347
|
+
>{'ensure all odd'}</button>
|
|
358
348
|
<pre>{hasEven.toString()}</pre>
|
|
359
|
-
|
|
349
|
+
</>
|
|
360
350
|
}
|
|
361
351
|
|
|
362
352
|
render(ArrayTest);
|
|
@@ -379,20 +369,18 @@ describe('RippleArray > derived', () => {
|
|
|
379
369
|
});
|
|
380
370
|
|
|
381
371
|
it('handles toLocaleString method with reactivity', () => {
|
|
382
|
-
function ArrayTest() {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
372
|
+
function ArrayTest() @{
|
|
373
|
+
let items = new RippleArray(1000, 2000, 3000);
|
|
374
|
+
let &[localized] = track(() => items.toLocaleString('en-US'));
|
|
375
|
+
<>
|
|
386
376
|
<button
|
|
387
377
|
onClick={() => {
|
|
388
378
|
items[2] = 4000;
|
|
389
379
|
}}
|
|
390
|
-
>
|
|
391
|
-
{'add item'}
|
|
392
|
-
</button>
|
|
380
|
+
>{'add item'}</button>
|
|
393
381
|
<pre>{JSON.stringify(items)}</pre>
|
|
394
382
|
<pre>{localized}</pre>
|
|
395
|
-
|
|
383
|
+
</>
|
|
396
384
|
}
|
|
397
385
|
|
|
398
386
|
render(ArrayTest);
|
|
@@ -412,14 +400,14 @@ describe('RippleArray > derived', () => {
|
|
|
412
400
|
});
|
|
413
401
|
|
|
414
402
|
it('handles toString method with reactivity', () => {
|
|
415
|
-
function ArrayTest() {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
403
|
+
function ArrayTest() @{
|
|
404
|
+
let items = new RippleArray(1, 2, 3);
|
|
405
|
+
let &[string] = track(() => items.toString());
|
|
406
|
+
<>
|
|
419
407
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
420
408
|
<pre>{JSON.stringify(items)}</pre>
|
|
421
409
|
<pre>{string}</pre>
|
|
422
|
-
|
|
410
|
+
</>
|
|
423
411
|
}
|
|
424
412
|
|
|
425
413
|
render(ArrayTest);
|
|
@@ -443,14 +431,14 @@ describe('RippleArray > derived', () => {
|
|
|
443
431
|
context.skip();
|
|
444
432
|
}
|
|
445
433
|
|
|
446
|
-
function ArrayTest() {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
434
|
+
function ArrayTest() @{
|
|
435
|
+
let items = new RippleArray(1, 2, 3, 4);
|
|
436
|
+
let &[withReplaced] = track(() => items.with(2, 30));
|
|
437
|
+
<>
|
|
450
438
|
<button onClick={() => (items[2] = 50)}>{'change original'}</button>
|
|
451
439
|
<pre>{JSON.stringify(items)}</pre>
|
|
452
440
|
<pre>{JSON.stringify(withReplaced)}</pre>
|
|
453
|
-
|
|
441
|
+
</>
|
|
454
442
|
}
|
|
455
443
|
|
|
456
444
|
render(ArrayTest);
|
|
@@ -470,12 +458,12 @@ describe('RippleArray > derived', () => {
|
|
|
470
458
|
});
|
|
471
459
|
|
|
472
460
|
it('handles toJSON method', () => {
|
|
473
|
-
function ArrayTest() {
|
|
474
|
-
|
|
475
|
-
|
|
461
|
+
function ArrayTest() @{
|
|
462
|
+
let items = new RippleArray(1, 2, 3);
|
|
463
|
+
<>
|
|
476
464
|
<button onClick={() => items.push(4)}>{'add'}</button>
|
|
477
465
|
<pre>{JSON.stringify(items)}</pre>
|
|
478
|
-
|
|
466
|
+
</>
|
|
479
467
|
}
|
|
480
468
|
|
|
481
469
|
render(ArrayTest);
|
|
@@ -493,19 +481,19 @@ describe('RippleArray > derived', () => {
|
|
|
493
481
|
});
|
|
494
482
|
|
|
495
483
|
it('handles at method with reactivity', () => {
|
|
496
|
-
function ArrayTest() {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
484
|
+
function ArrayTest() @{
|
|
485
|
+
let items = new RippleArray(10, 20, 30, 40, 50);
|
|
486
|
+
let &[atIndex2] = track(() => items.at(2));
|
|
487
|
+
let &[atNegative1] = track(() => items.at(-1));
|
|
488
|
+
let &[atNegative2] = track(() => items.at(-2));
|
|
489
|
+
<>
|
|
502
490
|
<button onClick={() => (items[2] = 300)}>{'change index 2'}</button>
|
|
503
491
|
<button onClick={() => (items[items.length - 1] = 500)}>{'change last'}</button>
|
|
504
492
|
<pre>{JSON.stringify(items)}</pre>
|
|
505
493
|
<pre>{atIndex2}</pre>
|
|
506
494
|
<pre>{atNegative1}</pre>
|
|
507
495
|
<pre>{atNegative2}</pre>
|
|
508
|
-
|
|
496
|
+
</>
|
|
509
497
|
}
|
|
510
498
|
|
|
511
499
|
render(ArrayTest);
|
|
@@ -2,14 +2,14 @@ import { RippleArray, effect, flushSync, track, untrack } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('RippleArray > iteration', () => {
|
|
4
4
|
it('handles entries method with reactivity', () => {
|
|
5
|
-
function ArrayTest() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function ArrayTest() @{
|
|
6
|
+
let items = new RippleArray('a', 'b', 'c');
|
|
7
|
+
let &[entries] = track(() => Array.from(items.entries()));
|
|
8
|
+
<>
|
|
9
9
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
10
10
|
<pre>{JSON.stringify(items)}</pre>
|
|
11
11
|
<pre>{JSON.stringify(entries)}</pre>
|
|
12
|
-
|
|
12
|
+
</>
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
render(ArrayTest);
|
|
@@ -31,14 +31,14 @@ describe('RippleArray > iteration', () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
it('handles keys method with reactivity', () => {
|
|
34
|
-
function ArrayTest() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
function ArrayTest() @{
|
|
35
|
+
let items = new RippleArray('a', 'b', 'c');
|
|
36
|
+
let &[keys] = track(() => Array.from(items.keys()));
|
|
37
|
+
<>
|
|
38
38
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
39
39
|
<pre>{JSON.stringify(items)}</pre>
|
|
40
40
|
<pre>{JSON.stringify(keys)}</pre>
|
|
41
|
-
|
|
41
|
+
</>
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
render(ArrayTest);
|
|
@@ -58,14 +58,14 @@ describe('RippleArray > iteration', () => {
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
it('handles values method with reactivity', () => {
|
|
61
|
-
function ArrayTest() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
function ArrayTest() @{
|
|
62
|
+
let items = new RippleArray('a', 'b', 'c');
|
|
63
|
+
let &[values] = track(() => Array.from(items.values()));
|
|
64
|
+
<>
|
|
65
65
|
<button onClick={() => items.push('d')}>{'add item'}</button>
|
|
66
66
|
<pre>{JSON.stringify(items)}</pre>
|
|
67
67
|
<pre>{JSON.stringify(values)}</pre>
|
|
68
|
-
|
|
68
|
+
</>
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
render(ArrayTest);
|
|
@@ -85,22 +85,22 @@ describe('RippleArray > iteration', () => {
|
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
it('handles Symbol.iterator with reactivity', () => {
|
|
88
|
-
function ArrayTest() {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
function ArrayTest() @{
|
|
89
|
+
let items = new RippleArray(1, 2, 3);
|
|
90
|
+
let &[sum] = track(0);
|
|
91
|
+
effect(() => {
|
|
92
|
+
sum = 0;
|
|
93
|
+
for (const item of items) {
|
|
94
|
+
untrack(() => {
|
|
95
|
+
sum += item;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
<>
|
|
100
100
|
<button onClick={() => items.push(4)}>{'add item'}</button>
|
|
101
101
|
<pre>{JSON.stringify(items)}</pre>
|
|
102
102
|
<pre>{sum}</pre>
|
|
103
|
-
|
|
103
|
+
</>
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
render(ArrayTest);
|