ripple 0.3.72 → 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 +66 -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 +55 -61
- package/tests/client/basic/basic.components.test.tsrx +196 -218
- package/tests/client/basic/basic.errors.test.tsrx +70 -76
- 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 +357 -288
- 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 +286 -292
- 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 +390 -319
- 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 -258
- 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 +117 -162
- package/tests/server/basic.components.test.tsrx +163 -193
- package/tests/server/basic.test.tsrx +298 -198
- 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
|
@@ -3,30 +3,23 @@ import { RippleObject, effect, flushSync, track } from 'ripple';
|
|
|
3
3
|
|
|
4
4
|
describe('composite > reactivity', () => {
|
|
5
5
|
it('renders composite components with object state', () => {
|
|
6
|
-
function Button({ obj }: { obj: { count: Tracked<number> } }) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
>
|
|
14
|
-
{obj.count.value}
|
|
15
|
-
</button>
|
|
16
|
-
</>;
|
|
6
|
+
function Button({ obj }: { obj: { count: Tracked<number> } }) @{
|
|
7
|
+
<button
|
|
8
|
+
class="count2"
|
|
9
|
+
onClick={() => {
|
|
10
|
+
obj.count.value++;
|
|
11
|
+
}}
|
|
12
|
+
>{obj.count.value}</button>
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
function App() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<Button {obj} />
|
|
28
|
-
</div>
|
|
29
|
-
</>;
|
|
15
|
+
function App() @{
|
|
16
|
+
let obj = {
|
|
17
|
+
count: track(0),
|
|
18
|
+
};
|
|
19
|
+
<div>
|
|
20
|
+
<span class="count">{obj.count.value}</span>
|
|
21
|
+
<Button {obj} />
|
|
22
|
+
</div>
|
|
30
23
|
}
|
|
31
24
|
|
|
32
25
|
render(App);
|
|
@@ -41,41 +34,34 @@ describe('composite > reactivity', () => {
|
|
|
41
34
|
});
|
|
42
35
|
|
|
43
36
|
it('renders composite components with object state wrapped in an if statement', () => {
|
|
44
|
-
function Button({ obj }: { obj: { count: Tracked<number> } }) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
{obj.count.value}
|
|
53
|
-
</button>
|
|
54
|
-
</>;
|
|
37
|
+
function Button({ obj }: { obj: { count: Tracked<number> } }) @{
|
|
38
|
+
<button
|
|
39
|
+
class="count2"
|
|
40
|
+
onClick={() => {
|
|
41
|
+
obj.count.value++;
|
|
42
|
+
}}
|
|
43
|
+
>{obj.count.value}</button>
|
|
55
44
|
}
|
|
56
45
|
|
|
57
|
-
function OtherComponent({ obj }: { obj: { count: Tracked<number> } }) {
|
|
58
|
-
|
|
46
|
+
function OtherComponent({ obj }: { obj: { count: Tracked<number> } }) @{
|
|
47
|
+
<div class="count3">{obj.count.value}</div>
|
|
59
48
|
}
|
|
60
49
|
|
|
61
|
-
function App() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
</div>
|
|
78
|
-
</>;
|
|
50
|
+
function App() @{
|
|
51
|
+
let obj = {
|
|
52
|
+
count: track(0),
|
|
53
|
+
};
|
|
54
|
+
<div>
|
|
55
|
+
<span class="count">{obj.count.value}</span>
|
|
56
|
+
<span>{' '}</span>
|
|
57
|
+
@if (obj) {
|
|
58
|
+
<Button {obj} />
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@if (obj) {
|
|
62
|
+
<OtherComponent {obj} />
|
|
63
|
+
}
|
|
64
|
+
</div>
|
|
79
65
|
}
|
|
80
66
|
|
|
81
67
|
render(App);
|
|
@@ -91,34 +77,29 @@ describe('composite > reactivity', () => {
|
|
|
91
77
|
});
|
|
92
78
|
|
|
93
79
|
it('parents and children have isolated state', () => {
|
|
94
|
-
function Button(props: { count: number }) {
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
function Button(props: { count: number }) @{
|
|
81
|
+
let &[count] = track(() => props.count);
|
|
82
|
+
<button
|
|
83
|
+
onClick={() => {
|
|
84
|
+
count++;
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
{'child: ' + count}
|
|
88
|
+
</button>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function App() @{
|
|
92
|
+
let &[count] = track(0);
|
|
93
|
+
<div>
|
|
97
94
|
<button
|
|
98
95
|
onClick={() => {
|
|
99
96
|
count++;
|
|
100
97
|
}}
|
|
101
98
|
>
|
|
102
|
-
{'
|
|
99
|
+
{'parent: ' + count}
|
|
103
100
|
</button>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
function App() {
|
|
108
|
-
return <>
|
|
109
|
-
<div>
|
|
110
|
-
let &[count] = track(0);
|
|
111
|
-
|
|
112
|
-
<button
|
|
113
|
-
onClick={() => {
|
|
114
|
-
count++;
|
|
115
|
-
}}
|
|
116
|
-
>
|
|
117
|
-
{'parent: ' + count}
|
|
118
|
-
</button>
|
|
119
|
-
<Button {count} />
|
|
120
|
-
</div>
|
|
121
|
-
</>;
|
|
101
|
+
<Button {count} />
|
|
102
|
+
</div>
|
|
122
103
|
}
|
|
123
104
|
|
|
124
105
|
render(App);
|
|
@@ -142,34 +123,29 @@ describe('composite > reactivity', () => {
|
|
|
142
123
|
});
|
|
143
124
|
|
|
144
125
|
it('parents and children have isolated connected state (destructured props)', () => {
|
|
145
|
-
function Button(&{ count }: { count: number }) {
|
|
146
|
-
|
|
147
|
-
|
|
126
|
+
function Button(&{ count }: { count: number }) @{
|
|
127
|
+
let &[local_count] = track(() => count);
|
|
128
|
+
<button
|
|
129
|
+
onClick={() => {
|
|
130
|
+
local_count++;
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
{'child: ' + local_count}
|
|
134
|
+
</button>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function App() @{
|
|
138
|
+
let &[count] = track(0);
|
|
139
|
+
<div>
|
|
148
140
|
<button
|
|
149
141
|
onClick={() => {
|
|
150
|
-
|
|
142
|
+
count++;
|
|
151
143
|
}}
|
|
152
144
|
>
|
|
153
|
-
{'
|
|
145
|
+
{'parent: ' + count}
|
|
154
146
|
</button>
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
function App() {
|
|
159
|
-
return <>
|
|
160
|
-
<div>
|
|
161
|
-
let &[count] = track(0);
|
|
162
|
-
|
|
163
|
-
<button
|
|
164
|
-
onClick={() => {
|
|
165
|
-
count++;
|
|
166
|
-
}}
|
|
167
|
-
>
|
|
168
|
-
{'parent: ' + count}
|
|
169
|
-
</button>
|
|
170
|
-
<Button {count} />
|
|
171
|
-
</div>
|
|
172
|
-
</>;
|
|
147
|
+
<Button {count} />
|
|
148
|
+
</div>
|
|
173
149
|
}
|
|
174
150
|
|
|
175
151
|
render(App);
|
|
@@ -195,18 +171,18 @@ describe('composite > reactivity', () => {
|
|
|
195
171
|
it('handles spreading of props', () => {
|
|
196
172
|
let logs: string[] = [];
|
|
197
173
|
|
|
198
|
-
function App() {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
174
|
+
function App() @{
|
|
175
|
+
let &[a] = track(1);
|
|
176
|
+
let &[b] = track(2);
|
|
177
|
+
let &[c] = track(3);
|
|
178
|
+
let &[obj] = track(
|
|
179
|
+
() => ({
|
|
180
|
+
a,
|
|
181
|
+
b,
|
|
182
|
+
c,
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
<>
|
|
210
186
|
<Child {...obj} />
|
|
211
187
|
<button
|
|
212
188
|
onClick={() => {
|
|
@@ -214,19 +190,17 @@ describe('composite > reactivity', () => {
|
|
|
214
190
|
b++;
|
|
215
191
|
c++;
|
|
216
192
|
}}
|
|
217
|
-
>
|
|
218
|
-
|
|
219
|
-
</button>
|
|
220
|
-
</>;
|
|
193
|
+
>{'Increment all'}</button>
|
|
194
|
+
</>
|
|
221
195
|
}
|
|
222
196
|
|
|
223
|
-
function Child(&{ a, b, c }: { a: number; b: number; c: number }) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
197
|
+
function Child(&{ a, b, c }: { a: number; b: number; c: number }) @{
|
|
198
|
+
effect(() => {
|
|
199
|
+
logs.push(`Child effect: ${a}, ${b}, ${c}`);
|
|
200
|
+
});
|
|
201
|
+
<div>
|
|
202
|
+
{a + ' ' + b + ' ' + c}
|
|
203
|
+
</div>
|
|
230
204
|
}
|
|
231
205
|
|
|
232
206
|
render(App);
|
|
@@ -244,27 +218,23 @@ describe('composite > reactivity', () => {
|
|
|
244
218
|
});
|
|
245
219
|
|
|
246
220
|
it('keeps reactivity for spread props via intermediate components and lazy destructuring', () => {
|
|
247
|
-
function App() {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
<CounterWrapper {count} up={() => count++} down={() => count--} />
|
|
251
|
-
</>;
|
|
221
|
+
function App() @{
|
|
222
|
+
let &[count] = track(0);
|
|
223
|
+
<CounterWrapper {count} up={() => count++} down={() => count--} />
|
|
252
224
|
}
|
|
253
225
|
|
|
254
|
-
function CounterWrapper(props: Props) {
|
|
255
|
-
|
|
256
|
-
<
|
|
257
|
-
|
|
258
|
-
</div>
|
|
259
|
-
</>;
|
|
226
|
+
function CounterWrapper(props: Props) @{
|
|
227
|
+
<div>
|
|
228
|
+
<Counter {...props} />
|
|
229
|
+
</div>
|
|
260
230
|
}
|
|
261
231
|
|
|
262
|
-
function Counter(&{ count, up, down, ...rest }: Props) {
|
|
263
|
-
|
|
232
|
+
function Counter(&{ count, up, down, ...rest }: Props) @{
|
|
233
|
+
<>
|
|
264
234
|
<button onClick={() => up()}>{'UP'}</button>
|
|
265
235
|
<button onClick={() => down()}>{'DOWN'}</button>
|
|
266
236
|
<span {...rest}>{`Counter: ${count}`}</span>
|
|
267
|
-
|
|
237
|
+
</>
|
|
268
238
|
}
|
|
269
239
|
|
|
270
240
|
render(App);
|
|
@@ -287,36 +257,32 @@ describe('composite > reactivity', () => {
|
|
|
287
257
|
});
|
|
288
258
|
|
|
289
259
|
it('keeps reactivity on elements for element spreads and adds / removes dynamic props', () => {
|
|
290
|
-
function App() {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
<CounterWrapper {count} up={() => count++} />
|
|
294
|
-
</>;
|
|
260
|
+
function App() @{
|
|
261
|
+
let &[count] = track(0);
|
|
262
|
+
<CounterWrapper {count} up={() => count++} />
|
|
295
263
|
}
|
|
296
264
|
|
|
297
|
-
function CounterWrapper(props: { count: number; up: () => void }) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
<
|
|
317
|
-
|
|
318
|
-
</div>
|
|
319
|
-
</>;
|
|
265
|
+
function CounterWrapper(props: { count: number; up: () => void }) @{
|
|
266
|
+
const more: {
|
|
267
|
+
double: Tracked<number>;
|
|
268
|
+
another?: number;
|
|
269
|
+
extra: number;
|
|
270
|
+
} = new RippleObject({
|
|
271
|
+
double: track(() => props.count * 2),
|
|
272
|
+
another: 0,
|
|
273
|
+
extra: 100,
|
|
274
|
+
});
|
|
275
|
+
effect(() => {
|
|
276
|
+
props.count;
|
|
277
|
+
if (props.count === 1) {
|
|
278
|
+
delete more.another;
|
|
279
|
+
} else if (props.count === 2) {
|
|
280
|
+
more.another = 0;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
<div>
|
|
284
|
+
<Counter {...props} double={more.double} another={more.another} extra={more.extra} />
|
|
285
|
+
</div>
|
|
320
286
|
}
|
|
321
287
|
|
|
322
288
|
function Counter(&{
|
|
@@ -329,11 +295,11 @@ describe('composite > reactivity', () => {
|
|
|
329
295
|
double: Tracked<number>;
|
|
330
296
|
another?: number;
|
|
331
297
|
extra: number;
|
|
332
|
-
}) {
|
|
333
|
-
|
|
298
|
+
}) @{
|
|
299
|
+
<>
|
|
334
300
|
<div {...rest}>{`Counter: ${count} Double: ${rest.double.value}`}</div>
|
|
335
301
|
<button onClick={() => up()}>{'UP'}</button>
|
|
336
|
-
|
|
302
|
+
</>
|
|
337
303
|
}
|
|
338
304
|
|
|
339
305
|
render(App);
|
|
@@ -2,16 +2,16 @@ import { RippleArray, flushSync, track, type Component } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('composite > render', () => {
|
|
4
4
|
it('renders composite components', () => {
|
|
5
|
-
function Button(&{ count }: { count: number }) {
|
|
6
|
-
|
|
5
|
+
function Button(&{ count }: { count: number }) @{
|
|
6
|
+
<div>{count}</div>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function App() {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
function App() @{
|
|
10
|
+
let &[count] = track(0);
|
|
11
|
+
<>
|
|
12
12
|
<button onClick={() => count++}>{'Increment'}</button>
|
|
13
13
|
<Button {count} />
|
|
14
|
-
|
|
14
|
+
</>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
render(App);
|
|
@@ -30,28 +30,26 @@ describe('composite > render', () => {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('correct handles passing through component props and children', () => {
|
|
33
|
-
function Button({ A, B, children }: { A: () => void; B: () => void; children: () => void }) {
|
|
34
|
-
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
</div>
|
|
40
|
-
</>;
|
|
33
|
+
function Button({ A, B, children }: { A: () => void; B: () => void; children: () => void }) @{
|
|
34
|
+
<div>
|
|
35
|
+
<A />
|
|
36
|
+
{children}
|
|
37
|
+
<B />
|
|
38
|
+
</div>
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</
|
|
54
|
-
|
|
41
|
+
function A() @{
|
|
42
|
+
<div>{'I am A'}</div>
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function B() @{
|
|
46
|
+
<div>{'I am B'}</div>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function App() @{
|
|
50
|
+
<Button {A} {B}>
|
|
51
|
+
<div>{'other text'}</div>
|
|
52
|
+
</Button>
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
render(App);
|
|
@@ -60,15 +58,13 @@ describe('composite > render', () => {
|
|
|
60
58
|
});
|
|
61
59
|
|
|
62
60
|
it('render simple text as children', () => {
|
|
63
|
-
function App() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<Child class="my-button">{name}</Child>
|
|
67
|
-
</>;
|
|
61
|
+
function App() @{
|
|
62
|
+
let name = 'Click Me';
|
|
63
|
+
<Child class="my-button">{name}</Child>
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
function Child({ children, ...rest }: { children: string; class: string }) {
|
|
71
|
-
|
|
66
|
+
function Child({ children, ...rest }: { children: string; class: string }) @{
|
|
67
|
+
<button {...rest}>{children}</button>
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
render(App);
|
|
@@ -76,22 +72,18 @@ describe('composite > render', () => {
|
|
|
76
72
|
});
|
|
77
73
|
|
|
78
74
|
it('renders explicit text around children', () => {
|
|
79
|
-
function Frame({ children }) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</div>
|
|
86
|
-
</>;
|
|
75
|
+
function Frame({ children }) @{
|
|
76
|
+
<div class="frame">
|
|
77
|
+
{'before'}
|
|
78
|
+
{children}
|
|
79
|
+
{'after'}
|
|
80
|
+
</div>
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
function App() {
|
|
90
|
-
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
</Frame>
|
|
94
|
-
</>;
|
|
83
|
+
function App() @{
|
|
84
|
+
<Frame>
|
|
85
|
+
<span class="middle">{'middle'}</span>
|
|
86
|
+
</Frame>
|
|
95
87
|
}
|
|
96
88
|
|
|
97
89
|
render(App);
|
|
@@ -112,35 +104,35 @@ describe('composite > render', () => {
|
|
|
112
104
|
});
|
|
113
105
|
|
|
114
106
|
it('preserves distinct scoped ripple hashes for wrapper and child content', () => {
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
function Wrapper({ children }) @{
|
|
108
|
+
<>
|
|
109
|
+
<div class="green">
|
|
110
|
+
{'Wrapper'}
|
|
111
|
+
{children}
|
|
112
|
+
</div>
|
|
113
|
+
<style>
|
|
114
|
+
.green {
|
|
115
|
+
color: green;
|
|
116
|
+
}
|
|
117
|
+
</style>
|
|
118
|
+
</>
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function Child() @{
|
|
122
|
+
<>
|
|
123
|
+
<div class="red">{'Child'}</div>
|
|
124
|
+
<style>
|
|
125
|
+
.red {
|
|
126
|
+
color: red;
|
|
127
|
+
}
|
|
128
|
+
</style>
|
|
129
|
+
</>
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function App() @{
|
|
133
|
+
<Wrapper>
|
|
134
|
+
<Child />
|
|
135
|
+
</Wrapper>
|
|
144
136
|
}
|
|
145
137
|
|
|
146
138
|
render(App);
|
|
@@ -160,12 +152,12 @@ describe('composite > render', () => {
|
|
|
160
152
|
});
|
|
161
153
|
|
|
162
154
|
it('handles generics', () => {
|
|
163
|
-
function ArrayTest() {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
155
|
+
function ArrayTest() @{
|
|
156
|
+
let items = new RippleArray<number>();
|
|
157
|
+
items.push.apply(items, [1, 2, 3, 4, 5]);
|
|
158
|
+
<pre>
|
|
159
|
+
{items ? JSON.stringify(items) : 'Loading...'}
|
|
160
|
+
</pre>
|
|
169
161
|
}
|
|
170
162
|
|
|
171
163
|
render(ArrayTest);
|
|
@@ -180,18 +172,17 @@ describe('composite > render', () => {
|
|
|
180
172
|
children?: Component;
|
|
181
173
|
NonExistent?: Component;
|
|
182
174
|
[key: string]: any;
|
|
183
|
-
}) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
</>;
|
|
175
|
+
}) @{
|
|
176
|
+
<div {...props}>
|
|
177
|
+
{children}
|
|
178
|
+
|
|
179
|
+
<NonExistent />
|
|
180
|
+
// @ts-expect-error - intentionally testing behavior when a component is undefined
|
|
181
|
+
</div>
|
|
191
182
|
}
|
|
192
183
|
|
|
193
|
-
function App() {
|
|
194
|
-
|
|
184
|
+
function App() @{
|
|
185
|
+
<Child />
|
|
195
186
|
}
|
|
196
187
|
|
|
197
188
|
render(App);
|
|
@@ -206,8 +197,8 @@ describe('composite > render', () => {
|
|
|
206
197
|
|
|
207
198
|
describe('scoped styles with children', () => {
|
|
208
199
|
it('generates correct CSS hashes for wrapper and child with empty style in App', () => {
|
|
209
|
-
function Wrapper(&{ children }: { children?: Component }) {
|
|
210
|
-
|
|
200
|
+
function Wrapper(&{ children }: { children?: Component }) @{
|
|
201
|
+
<>
|
|
211
202
|
<div class="green">
|
|
212
203
|
{'Wrapper'}
|
|
213
204
|
{children}
|
|
@@ -217,27 +208,27 @@ describe('scoped styles with children', () => {
|
|
|
217
208
|
color: green;
|
|
218
209
|
}
|
|
219
210
|
</style>
|
|
220
|
-
|
|
211
|
+
</>
|
|
221
212
|
}
|
|
222
213
|
|
|
223
|
-
function Child() {
|
|
224
|
-
|
|
214
|
+
function Child() @{
|
|
215
|
+
<>
|
|
225
216
|
<div class="red">{'Child'}</div>
|
|
226
217
|
<style>
|
|
227
218
|
.red {
|
|
228
219
|
color: red;
|
|
229
220
|
}
|
|
230
221
|
</style>
|
|
231
|
-
|
|
222
|
+
</>
|
|
232
223
|
}
|
|
233
224
|
|
|
234
|
-
function App() {
|
|
235
|
-
|
|
225
|
+
function App() @{
|
|
226
|
+
<>
|
|
236
227
|
<Wrapper>
|
|
237
228
|
<Child />
|
|
238
229
|
</Wrapper>
|
|
239
230
|
<style></style>
|
|
240
|
-
|
|
231
|
+
</>
|
|
241
232
|
}
|
|
242
233
|
|
|
243
234
|
render(App);
|