ripple 0.3.7 → 0.3.9
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 +14 -0
- package/package.json +2 -2
- package/src/compiler/phases/1-parse/index.js +48 -349
- package/src/compiler/phases/2-analyze/index.js +343 -52
- package/src/compiler/phases/3-transform/client/index.js +28 -160
- package/src/compiler/phases/3-transform/segments.js +0 -7
- package/src/compiler/phases/3-transform/server/index.js +31 -154
- package/src/compiler/types/acorn.d.ts +1 -1
- package/src/compiler/types/estree.d.ts +1 -1
- package/src/compiler/types/import.d.ts +0 -2
- package/src/compiler/types/index.d.ts +5 -17
- package/src/compiler/types/parse.d.ts +1 -17
- package/src/compiler/utils.js +53 -20
- package/src/runtime/index-client.js +2 -13
- package/src/runtime/index-server.js +2 -2
- package/src/runtime/internal/client/bindings.js +3 -1
- package/src/runtime/internal/client/composite.js +3 -2
- package/src/runtime/internal/client/events.js +1 -1
- package/src/runtime/internal/client/head.js +3 -4
- package/src/runtime/internal/client/index.js +0 -1
- package/src/runtime/internal/client/runtime.js +0 -52
- package/src/runtime/internal/server/index.js +31 -55
- package/tests/client/array/array.copy-within.test.ripple +12 -12
- package/tests/client/array/array.derived.test.ripple +46 -46
- package/tests/client/array/array.iteration.test.ripple +10 -10
- package/tests/client/array/array.mutations.test.ripple +20 -20
- package/tests/client/array/array.to-methods.test.ripple +6 -6
- package/tests/client/async-suspend.test.ripple +5 -5
- package/tests/client/basic/basic.attributes.test.ripple +81 -81
- package/tests/client/basic/basic.collections.test.ripple +9 -9
- package/tests/client/basic/basic.components.test.ripple +28 -28
- package/tests/client/basic/basic.errors.test.ripple +46 -18
- package/tests/client/basic/basic.events.test.ripple +37 -37
- package/tests/client/basic/basic.get-set.test.ripple +6 -6
- package/tests/client/basic/basic.reactivity.test.ripple +58 -203
- package/tests/client/basic/basic.rendering.test.ripple +19 -19
- package/tests/client/basic/basic.utilities.test.ripple +3 -3
- package/tests/client/boundaries.test.ripple +12 -12
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.ripple.snap +5 -5
- package/tests/client/compiler/compiler.assignments.test.ripple +19 -19
- package/tests/client/compiler/compiler.basic.test.ripple +46 -27
- package/tests/client/compiler/compiler.tracked-access.test.ripple +2 -2
- package/tests/client/composite/composite.dynamic-components.test.ripple +9 -9
- package/tests/client/composite/composite.props.test.ripple +14 -16
- package/tests/client/composite/composite.reactivity.test.ripple +69 -70
- package/tests/client/composite/composite.render.test.ripple +3 -3
- package/tests/client/computed-properties.test.ripple +4 -4
- package/tests/client/date.test.ripple +42 -42
- package/tests/client/dynamic-elements.test.ripple +44 -45
- package/tests/client/events.test.ripple +70 -70
- package/tests/client/for.test.ripple +25 -25
- package/tests/client/head.test.ripple +19 -19
- package/tests/client/html.test.ripple +3 -3
- package/tests/client/input-value.test.ripple +84 -84
- package/tests/client/lazy-destructuring.test.ripple +138 -26
- package/tests/client/map.test.ripple +16 -16
- package/tests/client/media-query.test.ripple +7 -7
- package/tests/client/portal.test.ripple +11 -11
- package/tests/client/ref.test.ripple +4 -4
- package/tests/client/return.test.ripple +52 -52
- package/tests/client/set.test.ripple +6 -6
- package/tests/client/svg.test.ripple +5 -5
- package/tests/client/switch.test.ripple +44 -44
- package/tests/client/try.test.ripple +5 -5
- package/tests/client/url/url.derived.test.ripple +6 -6
- package/tests/client/url-search-params/url-search-params.derived.test.ripple +8 -8
- package/tests/client/url-search-params/url-search-params.iteration.test.ripple +10 -10
- package/tests/client/url-search-params/url-search-params.mutation.test.ripple +10 -10
- package/tests/client/url-search-params/url-search-params.retrieval.test.ripple +18 -18
- package/tests/client/url-search-params/url-search-params.serialization.test.ripple +2 -2
- package/tests/hydration/compiled/client/events.js +25 -25
- package/tests/hydration/compiled/client/for.js +70 -66
- package/tests/hydration/compiled/client/head.js +25 -25
- package/tests/hydration/compiled/client/hmr.js +2 -2
- package/tests/hydration/compiled/client/html.js +3 -3
- package/tests/hydration/compiled/client/if-children.js +24 -24
- package/tests/hydration/compiled/client/if.js +18 -18
- package/tests/hydration/compiled/client/mixed-control-flow.js +9 -9
- package/tests/hydration/compiled/client/portal.js +3 -3
- package/tests/hydration/compiled/client/reactivity.js +16 -16
- package/tests/hydration/compiled/client/return.js +40 -40
- package/tests/hydration/compiled/client/switch.js +12 -12
- package/tests/hydration/compiled/server/events.js +19 -19
- package/tests/hydration/compiled/server/for.js +41 -41
- package/tests/hydration/compiled/server/head.js +26 -26
- package/tests/hydration/compiled/server/hmr.js +2 -2
- package/tests/hydration/compiled/server/html.js +2 -2
- package/tests/hydration/compiled/server/if-children.js +16 -16
- package/tests/hydration/compiled/server/if.js +11 -11
- package/tests/hydration/compiled/server/mixed-control-flow.js +6 -6
- package/tests/hydration/compiled/server/portal.js +2 -2
- package/tests/hydration/compiled/server/reactivity.js +16 -16
- package/tests/hydration/compiled/server/return.js +25 -25
- package/tests/hydration/compiled/server/switch.js +8 -8
- package/tests/hydration/components/events.ripple +25 -25
- package/tests/hydration/components/for.ripple +66 -66
- package/tests/hydration/components/head.ripple +16 -16
- package/tests/hydration/components/hmr.ripple +2 -2
- package/tests/hydration/components/html.ripple +3 -3
- package/tests/hydration/components/if-children.ripple +24 -24
- package/tests/hydration/components/if.ripple +18 -18
- package/tests/hydration/components/mixed-control-flow.ripple +9 -9
- package/tests/hydration/components/portal.ripple +3 -3
- package/tests/hydration/components/reactivity.ripple +16 -16
- package/tests/hydration/components/return.ripple +40 -40
- package/tests/hydration/components/switch.ripple +20 -20
- package/tests/server/await.test.ripple +3 -3
- package/tests/server/basic.attributes.test.ripple +34 -34
- package/tests/server/basic.components.test.ripple +10 -10
- package/tests/server/basic.test.ripple +38 -40
- package/tests/server/compiler.test.ripple +22 -0
- package/tests/server/composite.props.test.ripple +12 -14
- package/tests/server/dynamic-elements.test.ripple +15 -15
- package/tests/server/head.test.ripple +11 -11
- package/tests/server/lazy-destructuring.test.ripple +92 -13
- package/tsconfig.typecheck.json +4 -0
- package/types/index.d.ts +0 -19
- package/tests/client/__snapshots__/tracked-expression.test.ripple.snap +0 -34
- package/tests/client/tracked-expression.test.ripple +0 -26
|
@@ -14,16 +14,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
14
14
|
|
|
15
15
|
it('render dynamic class attribute', () => {
|
|
16
16
|
component Basic() {
|
|
17
|
-
let active = track(false);
|
|
17
|
+
let &[active] = track(false);
|
|
18
18
|
|
|
19
19
|
<button
|
|
20
20
|
onClick={() => {
|
|
21
|
-
|
|
21
|
+
active = !active;
|
|
22
22
|
}}
|
|
23
23
|
>
|
|
24
24
|
{'Toggle'}
|
|
25
25
|
</button>
|
|
26
|
-
<div class={
|
|
26
|
+
<div class={active ? 'active' : 'inactive'}>{'Dynamic Class'}</div>
|
|
27
27
|
|
|
28
28
|
<style>
|
|
29
29
|
.active {
|
|
@@ -98,16 +98,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
98
98
|
|
|
99
99
|
it('render dynamic class object', () => {
|
|
100
100
|
component Basic() {
|
|
101
|
-
let active = track(false);
|
|
101
|
+
let &[active] = track(false);
|
|
102
102
|
|
|
103
103
|
<button
|
|
104
104
|
onClick={() => {
|
|
105
|
-
|
|
105
|
+
active = !active;
|
|
106
106
|
}}
|
|
107
107
|
>
|
|
108
108
|
{'Toggle'}
|
|
109
109
|
</button>
|
|
110
|
-
<div class={{ active:
|
|
110
|
+
<div class={{ active: active, inactive: !active }}>{'Dynamic Class'}</div>
|
|
111
111
|
|
|
112
112
|
<style>
|
|
113
113
|
.active {
|
|
@@ -141,10 +141,10 @@ describe('basic client > attribute rendering', () => {
|
|
|
141
141
|
|
|
142
142
|
it('applies scoped ripple class to multiple elements with dynamic class expressions', () => {
|
|
143
143
|
component Basic() {
|
|
144
|
-
let selected = track(1);
|
|
144
|
+
let &[selected] = track(1);
|
|
145
145
|
|
|
146
|
-
<div class={
|
|
147
|
-
<div class={
|
|
146
|
+
<div class={selected === 0 ? 'selected' : ''}>{`div 1`}</div>
|
|
147
|
+
<div class={selected === 0 ? 'selected' : ''}>{`div 2`}</div>
|
|
148
148
|
|
|
149
149
|
<style>
|
|
150
150
|
div {
|
|
@@ -170,16 +170,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
170
170
|
|
|
171
171
|
it('render dynamic id attribute', () => {
|
|
172
172
|
component Basic() {
|
|
173
|
-
let count = track(0);
|
|
173
|
+
let &[count] = track(0);
|
|
174
174
|
|
|
175
175
|
<button
|
|
176
176
|
onClick={() => {
|
|
177
|
-
|
|
177
|
+
count++;
|
|
178
178
|
}}
|
|
179
179
|
>
|
|
180
180
|
{'Increment'}
|
|
181
181
|
</button>
|
|
182
|
-
<div id={`item-${
|
|
182
|
+
<div id={`item-${count}`}>{'Dynamic ID'}</div>
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
render(Basic);
|
|
@@ -202,16 +202,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
202
202
|
|
|
203
203
|
it('render dynamic style attribute', () => {
|
|
204
204
|
component Basic() {
|
|
205
|
-
let color = track('red');
|
|
205
|
+
let &[color] = track('red');
|
|
206
206
|
|
|
207
207
|
<button
|
|
208
208
|
onClick={() => {
|
|
209
|
-
|
|
209
|
+
color = color === 'red' ? 'blue' : 'red';
|
|
210
210
|
}}
|
|
211
211
|
>
|
|
212
212
|
{'Change Color'}
|
|
213
213
|
</button>
|
|
214
|
-
<div style={`color: ${
|
|
214
|
+
<div style={`color: ${color}; font-weight: bold;`}>{'Dynamic Style'}</div>
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
render(Basic);
|
|
@@ -231,16 +231,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
231
231
|
|
|
232
232
|
it('render style attribute as dynamic object', () => {
|
|
233
233
|
component Basic() {
|
|
234
|
-
let color = track('red');
|
|
234
|
+
let &[color] = track('red');
|
|
235
235
|
|
|
236
236
|
<button
|
|
237
237
|
onClick={() => {
|
|
238
|
-
|
|
238
|
+
color = color === 'red' ? 'blue' : 'red';
|
|
239
239
|
}}
|
|
240
240
|
>
|
|
241
241
|
{'Change Color'}
|
|
242
242
|
</button>
|
|
243
|
-
<div style={{ color:
|
|
243
|
+
<div style={{ color: color, fontWeight: 'bold' }}>{'Dynamic Style'}</div>
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
render(Basic);
|
|
@@ -260,14 +260,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
260
260
|
|
|
261
261
|
it('render tracked variable as style attribute', () => {
|
|
262
262
|
component Basic() {
|
|
263
|
-
let style = track({ color: 'red', fontWeight: 'bold' });
|
|
263
|
+
let &[style] = track({ color: 'red', fontWeight: 'bold' });
|
|
264
264
|
|
|
265
265
|
function toggleColor() {
|
|
266
|
-
|
|
266
|
+
style = { ...style, color: style.color === 'red' ? 'blue' : 'red' };
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
<button onClick={toggleColor}>{'Change Color'}</button>
|
|
270
|
-
<div {
|
|
270
|
+
<div {style}>{'Dynamic Style'}</div>
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
render(Basic);
|
|
@@ -360,18 +360,18 @@ describe('basic client > attribute rendering', () => {
|
|
|
360
360
|
|
|
361
361
|
it('render dynamic boolean attributes', () => {
|
|
362
362
|
component Basic() {
|
|
363
|
-
let disabled = track(false);
|
|
364
|
-
let checked = track(false);
|
|
363
|
+
let &[disabled] = track(false);
|
|
364
|
+
let &[checked] = track(false);
|
|
365
365
|
|
|
366
366
|
<button
|
|
367
367
|
onClick={() => {
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
disabled = !disabled;
|
|
369
|
+
checked = !checked;
|
|
370
370
|
}}
|
|
371
371
|
>
|
|
372
372
|
{'Toggle'}
|
|
373
373
|
</button>
|
|
374
|
-
<input type="checkbox" {
|
|
374
|
+
<input type="checkbox" {disabled} {checked} />
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
render(Basic);
|
|
@@ -391,18 +391,18 @@ describe('basic client > attribute rendering', () => {
|
|
|
391
391
|
|
|
392
392
|
it('render multiple dynamic attributes', () => {
|
|
393
393
|
component Basic() {
|
|
394
|
-
let theme = track('light');
|
|
395
|
-
let size = track('medium');
|
|
394
|
+
let &[theme] = track('light');
|
|
395
|
+
let &[size] = track('medium');
|
|
396
396
|
|
|
397
397
|
<button
|
|
398
398
|
onClick={() => {
|
|
399
|
-
|
|
400
|
-
|
|
399
|
+
theme = theme === 'light' ? 'dark' : 'light';
|
|
400
|
+
size = size === 'medium' ? 'large' : 'medium';
|
|
401
401
|
}}
|
|
402
402
|
>
|
|
403
403
|
{'Toggle Theme & Size'}
|
|
404
404
|
</button>
|
|
405
|
-
<div class={`theme-${
|
|
405
|
+
<div class={`theme-${theme} size-${size}`} data-theme={theme} data-size={size}>
|
|
406
406
|
{'Multiple Dynamic Attributes'}
|
|
407
407
|
</div>
|
|
408
408
|
}
|
|
@@ -426,20 +426,20 @@ describe('basic client > attribute rendering', () => {
|
|
|
426
426
|
|
|
427
427
|
it('render conditional attributes', () => {
|
|
428
428
|
component Basic() {
|
|
429
|
-
let showTitle = track(false);
|
|
430
|
-
let showAria = track(false);
|
|
429
|
+
let &[showTitle] = track(false);
|
|
430
|
+
let &[showAria] = track(false);
|
|
431
431
|
|
|
432
432
|
<button
|
|
433
433
|
onClick={() => {
|
|
434
|
-
|
|
435
|
-
|
|
434
|
+
showTitle = !showTitle;
|
|
435
|
+
showAria = !showAria;
|
|
436
436
|
}}
|
|
437
437
|
>
|
|
438
438
|
{'Toggle Attributes'}
|
|
439
439
|
</button>
|
|
440
440
|
<div
|
|
441
|
-
title={
|
|
442
|
-
aria-label={
|
|
441
|
+
title={showTitle ? 'This is a title' : undefined}
|
|
442
|
+
aria-label={showAria ? 'Accessible label' : undefined}
|
|
443
443
|
>
|
|
444
444
|
{'Conditional Attributes'}
|
|
445
445
|
</div>
|
|
@@ -468,7 +468,7 @@ describe('basic client > attribute rendering', () => {
|
|
|
468
468
|
|
|
469
469
|
it('render spread attributes', () => {
|
|
470
470
|
component Basic() {
|
|
471
|
-
let attrs = track<TestAttributes>(
|
|
471
|
+
let &[attrs] = track<TestAttributes>(
|
|
472
472
|
{
|
|
473
473
|
class: 'initial',
|
|
474
474
|
id: 'test-1',
|
|
@@ -477,7 +477,7 @@ describe('basic client > attribute rendering', () => {
|
|
|
477
477
|
|
|
478
478
|
<button
|
|
479
479
|
onClick={() => {
|
|
480
|
-
|
|
480
|
+
attrs = {
|
|
481
481
|
class: 'updated',
|
|
482
482
|
id: 'test-2',
|
|
483
483
|
'data-extra': 'value',
|
|
@@ -486,7 +486,7 @@ describe('basic client > attribute rendering', () => {
|
|
|
486
486
|
>
|
|
487
487
|
{'Update Attributes'}
|
|
488
488
|
</button>
|
|
489
|
-
<div {
|
|
489
|
+
<div {...attrs}>{'Spread Attributes'}</div>
|
|
490
490
|
}
|
|
491
491
|
|
|
492
492
|
render(Basic);
|
|
@@ -508,14 +508,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
508
508
|
|
|
509
509
|
it('renders with reactive attributes with nested reactive attributes', () => {
|
|
510
510
|
component App() {
|
|
511
|
-
let value = track('parent-class');
|
|
511
|
+
let &[value] = track('parent-class');
|
|
512
512
|
|
|
513
|
-
<p class={
|
|
513
|
+
<p class={value}>{'Colored parent value'}</p>
|
|
514
514
|
|
|
515
515
|
<div>
|
|
516
|
-
let nested = track('nested-class');
|
|
516
|
+
let &[nested] = track('nested-class');
|
|
517
517
|
|
|
518
|
-
<p class={
|
|
518
|
+
<p class={nested}>{'Colored nested value'}</p>
|
|
519
519
|
</div>
|
|
520
520
|
}
|
|
521
521
|
|
|
@@ -556,29 +556,29 @@ describe('basic client > attribute rendering', () => {
|
|
|
556
556
|
|
|
557
557
|
it('handles reactive event handler changes', () => {
|
|
558
558
|
component Basic() {
|
|
559
|
-
let count = track(0);
|
|
560
|
-
let mode = track<'increment' | 'decrement'>('increment');
|
|
559
|
+
let &[count] = track(0);
|
|
560
|
+
let &[mode] = track<'increment' | 'decrement'>('increment');
|
|
561
561
|
|
|
562
562
|
const incrementHandler = () => {
|
|
563
|
-
|
|
563
|
+
count++;
|
|
564
564
|
};
|
|
565
565
|
|
|
566
566
|
const decrementHandler = () => {
|
|
567
|
-
|
|
567
|
+
count--;
|
|
568
568
|
};
|
|
569
569
|
|
|
570
570
|
<button
|
|
571
571
|
onClick={() => {
|
|
572
|
-
|
|
572
|
+
mode = mode === 'increment' ? 'decrement' : 'increment';
|
|
573
573
|
}}
|
|
574
574
|
class="toggle-mode"
|
|
575
575
|
>
|
|
576
576
|
{'Toggle Mode'}
|
|
577
577
|
</button>
|
|
578
|
-
<button onClick={
|
|
579
|
-
{
|
|
578
|
+
<button onClick={mode === 'increment' ? incrementHandler : decrementHandler} class="action">
|
|
579
|
+
{mode === 'increment' ? '+' : '-'}
|
|
580
580
|
</button>
|
|
581
|
-
<div class="count">{
|
|
581
|
+
<div class="count">{count}</div>
|
|
582
582
|
}
|
|
583
583
|
|
|
584
584
|
render(Basic);
|
|
@@ -678,18 +678,18 @@ describe('basic client > attribute rendering', () => {
|
|
|
678
678
|
|
|
679
679
|
it('handles custom events with customName option', () => {
|
|
680
680
|
component Basic() {
|
|
681
|
-
let customEventCount = track(0);
|
|
681
|
+
let &[customEventCount] = track(0);
|
|
682
682
|
|
|
683
683
|
const handleCustom = {
|
|
684
684
|
handleEvent(event: CustomEvent) {
|
|
685
|
-
|
|
685
|
+
customEventCount += event.detail.value;
|
|
686
686
|
},
|
|
687
687
|
customName: 'MyCustomEvent',
|
|
688
688
|
};
|
|
689
689
|
|
|
690
690
|
<div>
|
|
691
691
|
<div onMyCustomEvent={handleCustom} class="custom-target">{'Custom'}</div>
|
|
692
|
-
<div class="custom-count">{
|
|
692
|
+
<div class="custom-count">{customEventCount}</div>
|
|
693
693
|
</div>
|
|
694
694
|
}
|
|
695
695
|
|
|
@@ -713,16 +713,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
713
713
|
|
|
714
714
|
it('handles events with delegated: false option to bypass delegation', () => {
|
|
715
715
|
component Basic() {
|
|
716
|
-
let delegatedCount = track(0);
|
|
717
|
-
let nonDelegatedCount = track(0);
|
|
716
|
+
let &[delegatedCount] = track(0);
|
|
717
|
+
let &[nonDelegatedCount] = track(0);
|
|
718
718
|
|
|
719
719
|
const delegatedHandler = () => {
|
|
720
|
-
|
|
720
|
+
delegatedCount++;
|
|
721
721
|
};
|
|
722
722
|
|
|
723
723
|
const nonDelegatedHandler = {
|
|
724
724
|
handleEvent() {
|
|
725
|
-
|
|
725
|
+
nonDelegatedCount++;
|
|
726
726
|
},
|
|
727
727
|
delegated: false,
|
|
728
728
|
};
|
|
@@ -730,8 +730,8 @@ describe('basic client > attribute rendering', () => {
|
|
|
730
730
|
<div>
|
|
731
731
|
<button onClick={delegatedHandler} class="delegated-btn">{'Delegated'}</button>
|
|
732
732
|
<button onClick={nonDelegatedHandler} class="non-delegated-btn">{'Non-Delegated'}</button>
|
|
733
|
-
<div class="delegated-count">{
|
|
734
|
-
<div class="non-delegated-count">{
|
|
733
|
+
<div class="delegated-count">{delegatedCount}</div>
|
|
734
|
+
<div class="non-delegated-count">{nonDelegatedCount}</div>
|
|
735
735
|
</div>
|
|
736
736
|
}
|
|
737
737
|
|
|
@@ -827,24 +827,24 @@ describe('basic client > attribute rendering', () => {
|
|
|
827
827
|
|
|
828
828
|
it('handles events defined as function directly vs as object', () => {
|
|
829
829
|
component Basic() {
|
|
830
|
-
let functionCount = track(0);
|
|
831
|
-
let objectCount = track(0);
|
|
830
|
+
let &[functionCount] = track(0);
|
|
831
|
+
let &[objectCount] = track(0);
|
|
832
832
|
|
|
833
833
|
const functionHandler = () => {
|
|
834
|
-
|
|
834
|
+
functionCount++;
|
|
835
835
|
};
|
|
836
836
|
|
|
837
837
|
const objectHandler = {
|
|
838
838
|
handleEvent() {
|
|
839
|
-
|
|
839
|
+
objectCount++;
|
|
840
840
|
},
|
|
841
841
|
};
|
|
842
842
|
|
|
843
843
|
<div>
|
|
844
844
|
<button onClick={functionHandler} class="function-btn">{'Function'}</button>
|
|
845
845
|
<button onClick={objectHandler} class="object-btn">{'Object'}</button>
|
|
846
|
-
<div class="function-count">{
|
|
847
|
-
<div class="object-count">{
|
|
846
|
+
<div class="function-count">{functionCount}</div>
|
|
847
|
+
<div class="object-count">{objectCount}</div>
|
|
848
848
|
</div>
|
|
849
849
|
}
|
|
850
850
|
|
|
@@ -880,14 +880,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
880
880
|
|
|
881
881
|
it('handles passive event option', () => {
|
|
882
882
|
component Basic() {
|
|
883
|
-
let passiveDefaultPrevented = track<boolean | null>(null);
|
|
884
|
-
let nonPassiveDefaultPrevented = track<boolean | null>(null);
|
|
883
|
+
let &[passiveDefaultPrevented] = track<boolean | null>(null);
|
|
884
|
+
let &[nonPassiveDefaultPrevented] = track<boolean | null>(null);
|
|
885
885
|
|
|
886
886
|
const passiveHandler = {
|
|
887
887
|
handleEvent(event: Event) {
|
|
888
888
|
event.preventDefault();
|
|
889
889
|
// In passive listeners, preventDefault() is ignored
|
|
890
|
-
|
|
890
|
+
passiveDefaultPrevented = event.defaultPrevented;
|
|
891
891
|
},
|
|
892
892
|
passive: true,
|
|
893
893
|
delegated: false, // Need to ensure it's not delegated to test passive properly
|
|
@@ -897,7 +897,7 @@ describe('basic client > attribute rendering', () => {
|
|
|
897
897
|
handleEvent(event: Event) {
|
|
898
898
|
event.preventDefault();
|
|
899
899
|
// In non-passive listeners, preventDefault() works
|
|
900
|
-
|
|
900
|
+
nonPassiveDefaultPrevented = event.defaultPrevented;
|
|
901
901
|
},
|
|
902
902
|
delegated: false,
|
|
903
903
|
};
|
|
@@ -906,16 +906,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
906
906
|
<div onWheel={passiveHandler} class="passive-target">{'Passive'}</div>
|
|
907
907
|
<div onWheel={nonPassiveHandler} class="non-passive-target">{'Non-Passive'}</div>
|
|
908
908
|
<div class="passive-result">
|
|
909
|
-
{
|
|
909
|
+
{passiveDefaultPrevented === null
|
|
910
910
|
? 'not-tested'
|
|
911
|
-
:
|
|
911
|
+
: passiveDefaultPrevented
|
|
912
912
|
? 'prevented'
|
|
913
913
|
: 'not-prevented'}
|
|
914
914
|
</div>
|
|
915
915
|
<div class="non-passive-result">
|
|
916
|
-
{
|
|
916
|
+
{nonPassiveDefaultPrevented === null
|
|
917
917
|
? 'not-tested'
|
|
918
|
-
:
|
|
918
|
+
: nonPassiveDefaultPrevented
|
|
919
919
|
? 'prevented'
|
|
920
920
|
: 'not-prevented'}
|
|
921
921
|
</div>
|
|
@@ -945,25 +945,25 @@ describe('basic client > attribute rendering', () => {
|
|
|
945
945
|
|
|
946
946
|
it('handles once option to fire event only once', () => {
|
|
947
947
|
component Basic() {
|
|
948
|
-
let onceCount = track(0);
|
|
949
|
-
let regularCount = track(0);
|
|
948
|
+
let &[onceCount] = track(0);
|
|
949
|
+
let &[regularCount] = track(0);
|
|
950
950
|
|
|
951
951
|
const onceHandler = {
|
|
952
952
|
handleEvent() {
|
|
953
|
-
|
|
953
|
+
onceCount++;
|
|
954
954
|
},
|
|
955
955
|
once: true,
|
|
956
956
|
};
|
|
957
957
|
|
|
958
958
|
const regularHandler = () => {
|
|
959
|
-
|
|
959
|
+
regularCount++;
|
|
960
960
|
};
|
|
961
961
|
|
|
962
962
|
<div>
|
|
963
963
|
<button onClick={onceHandler} class="once-btn">{'Once'}</button>
|
|
964
964
|
<button onClick={regularHandler} class="regular-btn">{'Regular'}</button>
|
|
965
|
-
<div class="once-count">{
|
|
966
|
-
<div class="regular-count">{
|
|
965
|
+
<div class="once-count">{onceCount}</div>
|
|
966
|
+
<div class="regular-count">{regularCount}</div>
|
|
967
967
|
</div>
|
|
968
968
|
}
|
|
969
969
|
|
|
@@ -4,18 +4,18 @@ import { TRACKED_ARRAY } from '../../../src/runtime/internal/client/constants.js
|
|
|
4
4
|
describe('basic client > collections', () => {
|
|
5
5
|
it('renders with simple reactive objects', () => {
|
|
6
6
|
component Basic() {
|
|
7
|
-
let user = track(
|
|
7
|
+
let &[user] = track(
|
|
8
8
|
{
|
|
9
9
|
name: 'John',
|
|
10
10
|
age: 25,
|
|
11
11
|
},
|
|
12
12
|
);
|
|
13
13
|
|
|
14
|
-
<div class="name">{
|
|
15
|
-
<div class="age">{
|
|
14
|
+
<div class="name">{user.name}</div>
|
|
15
|
+
<div class="age">{user.age}</div>
|
|
16
16
|
<button
|
|
17
17
|
onClick={() => {
|
|
18
|
-
|
|
18
|
+
user = { ...user, name: 'Jane', age: 30 };
|
|
19
19
|
}}
|
|
20
20
|
>
|
|
21
21
|
{'Update User'}
|
|
@@ -40,19 +40,19 @@ describe('basic client > collections', () => {
|
|
|
40
40
|
|
|
41
41
|
it('renders with nested reactive objects', () => {
|
|
42
42
|
component Basic() {
|
|
43
|
-
let user = track(
|
|
43
|
+
let &[user] = track(
|
|
44
44
|
{
|
|
45
45
|
name: track('John'),
|
|
46
46
|
age: track(25),
|
|
47
47
|
},
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
<div class="name">{
|
|
51
|
-
<div class="age">{
|
|
50
|
+
<div class="name">{user.name.value}</div>
|
|
51
|
+
<div class="age">{user.age.value}</div>
|
|
52
52
|
<button
|
|
53
53
|
onClick={() => {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
user.name.value = 'Jane';
|
|
55
|
+
user.age.value = 30;
|
|
56
56
|
}}
|
|
57
57
|
>
|
|
58
58
|
{'Update User'}
|
|
@@ -69,13 +69,13 @@ describe('basic client > components & composition', () => {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
component Basic() {
|
|
72
|
-
let test = track(false);
|
|
72
|
+
let &[test] = track(false);
|
|
73
73
|
<Card>
|
|
74
74
|
component test() {
|
|
75
75
|
<p>{'Card content here'}</p>
|
|
76
76
|
}
|
|
77
77
|
</Card>
|
|
78
|
-
<div>{
|
|
78
|
+
<div>{test ? 'yes' : 'no'}</div>
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
render(Basic);
|
|
@@ -134,15 +134,15 @@ describe('basic client > components & composition', () => {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
component Basic() {
|
|
137
|
-
let clicked = track(false);
|
|
137
|
+
let &[clicked] = track(false);
|
|
138
138
|
|
|
139
139
|
<Card
|
|
140
140
|
title="Test Card"
|
|
141
141
|
content="This is a test card"
|
|
142
142
|
buttonText="Click me"
|
|
143
|
-
onAction={() => (
|
|
143
|
+
onAction={() => (clicked = true)}
|
|
144
144
|
/>
|
|
145
|
-
<div class="status">{
|
|
145
|
+
<div class="status">{clicked ? 'Clicked' : 'Not clicked'}</div>
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
render(Basic);
|
|
@@ -170,19 +170,19 @@ describe('basic client > components & composition', () => {
|
|
|
170
170
|
text: Tracked<string>;
|
|
171
171
|
count: Tracked<number>;
|
|
172
172
|
}>) {
|
|
173
|
-
<div class="child-content">{props
|
|
174
|
-
<div class="child-count">{props
|
|
173
|
+
<div class="child-content">{props.text.value}</div>
|
|
174
|
+
<div class="child-count">{props.count.value}</div>
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
component Basic() {
|
|
178
|
-
let message = track('Hello');
|
|
179
|
-
let number = track(1);
|
|
178
|
+
let &[message, messageTracked] = track('Hello');
|
|
179
|
+
let &[number, numberTracked] = track(1);
|
|
180
180
|
|
|
181
|
-
<ChildComponent text={
|
|
181
|
+
<ChildComponent text={messageTracked} count={numberTracked} />
|
|
182
182
|
<button
|
|
183
183
|
onClick={() => {
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
message = message === 'Hello' ? 'Goodbye' : 'Hello';
|
|
185
|
+
number++;
|
|
186
186
|
}}
|
|
187
187
|
>
|
|
188
188
|
{'Update Props'}
|
|
@@ -214,7 +214,7 @@ describe('basic client > components & composition', () => {
|
|
|
214
214
|
it('it retains this context with bracketed prop functions and keeps original chaining', () => {
|
|
215
215
|
component App() {
|
|
216
216
|
const SYMBOL_PROP = Symbol();
|
|
217
|
-
let hasError = track(false);
|
|
217
|
+
let &[hasError] = track(false);
|
|
218
218
|
const obj: {
|
|
219
219
|
count: Tracked<number>;
|
|
220
220
|
increment: () => void;
|
|
@@ -223,12 +223,12 @@ describe('basic client > components & composition', () => {
|
|
|
223
223
|
} = {
|
|
224
224
|
count: track(0),
|
|
225
225
|
increment() {
|
|
226
|
-
this
|
|
226
|
+
this.count.value++;
|
|
227
227
|
},
|
|
228
228
|
[SYMBOL_PROP]() {
|
|
229
|
-
this
|
|
229
|
+
this.count.value++;
|
|
230
230
|
},
|
|
231
|
-
arr: [() => obj
|
|
231
|
+
arr: [() => obj.count.value++, () => obj.count.value--],
|
|
232
232
|
};
|
|
233
233
|
|
|
234
234
|
const obj2 = null;
|
|
@@ -237,12 +237,12 @@ describe('basic client > components & composition', () => {
|
|
|
237
237
|
<button onClick={() => obj[SYMBOL_PROP]()}>{'Increment'}</button>
|
|
238
238
|
<button
|
|
239
239
|
onClick={() => {
|
|
240
|
-
|
|
240
|
+
hasError = false;
|
|
241
241
|
try {
|
|
242
242
|
// @ts-ignore
|
|
243
243
|
obj['nonexistent']();
|
|
244
244
|
} catch {
|
|
245
|
-
|
|
245
|
+
hasError = true;
|
|
246
246
|
}
|
|
247
247
|
}}
|
|
248
248
|
>
|
|
@@ -250,12 +250,12 @@ describe('basic client > components & composition', () => {
|
|
|
250
250
|
</button>
|
|
251
251
|
<button
|
|
252
252
|
onClick={() => {
|
|
253
|
-
|
|
253
|
+
hasError = false;
|
|
254
254
|
try {
|
|
255
255
|
// @ts-ignore
|
|
256
256
|
obj['nonexistent']?.();
|
|
257
257
|
} catch {
|
|
258
|
-
|
|
258
|
+
hasError = true;
|
|
259
259
|
}
|
|
260
260
|
}}
|
|
261
261
|
>
|
|
@@ -263,12 +263,12 @@ describe('basic client > components & composition', () => {
|
|
|
263
263
|
</button>
|
|
264
264
|
<button
|
|
265
265
|
onClick={() => {
|
|
266
|
-
|
|
266
|
+
hasError = false;
|
|
267
267
|
try {
|
|
268
268
|
// @ts-ignore
|
|
269
269
|
obj2['nonexistent']();
|
|
270
270
|
} catch {
|
|
271
|
-
|
|
271
|
+
hasError = true;
|
|
272
272
|
}
|
|
273
273
|
}}
|
|
274
274
|
>
|
|
@@ -276,12 +276,12 @@ describe('basic client > components & composition', () => {
|
|
|
276
276
|
</button>
|
|
277
277
|
<button
|
|
278
278
|
onClick={() => {
|
|
279
|
-
|
|
279
|
+
hasError = false;
|
|
280
280
|
try {
|
|
281
281
|
// @ts-ignore
|
|
282
282
|
obj2?.['nonexistent']?.();
|
|
283
283
|
} catch {
|
|
284
|
-
|
|
284
|
+
hasError = true;
|
|
285
285
|
}
|
|
286
286
|
}}
|
|
287
287
|
>
|
|
@@ -289,8 +289,8 @@ describe('basic client > components & composition', () => {
|
|
|
289
289
|
</button>
|
|
290
290
|
<button onClick={() => obj.arr[obj.arr.length - 1]()}>{'BinaryExpression prop'}</button>
|
|
291
291
|
|
|
292
|
-
<span>{obj
|
|
293
|
-
<span>{
|
|
292
|
+
<span>{obj.count.value}</span>
|
|
293
|
+
<span>{hasError}</span>
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
render(App);
|
|
@@ -402,10 +402,10 @@ describe('basic client > components & composition', () => {
|
|
|
402
402
|
}
|
|
403
403
|
|
|
404
404
|
component App() {
|
|
405
|
-
let Content = track(() => Noop);
|
|
405
|
+
let &[Content] = track(() => Noop);
|
|
406
406
|
<@Content />
|
|
407
407
|
|
|
408
|
-
<button onClick={() => (
|
|
408
|
+
<button onClick={() => (Content = Op)}>{'Show Op'}</button>
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
render(App);
|