ripple 0.3.128 → 0.4.0
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 +267 -0
- package/package.json +10 -4
- package/src/runtime/element.js +23 -6
- package/src/runtime/index-client.js +81 -41
- package/src/runtime/index-server.js +1 -0
- package/src/runtime/internal/client/blocks.js +173 -91
- package/src/runtime/internal/client/component.js +4 -30
- package/src/runtime/internal/client/composite.js +12 -13
- package/src/runtime/internal/client/constants.js +9 -0
- package/src/runtime/internal/client/context.js +12 -19
- package/src/runtime/internal/client/css.js +7 -9
- package/src/runtime/internal/client/events.js +178 -90
- package/src/runtime/internal/client/expression.js +45 -25
- package/src/runtime/internal/client/for.js +409 -129
- package/src/runtime/internal/client/head.js +10 -5
- package/src/runtime/internal/client/html.js +1 -0
- package/src/runtime/internal/client/hydration.js +152 -10
- package/src/runtime/internal/client/if.js +239 -50
- package/src/runtime/internal/client/index.js +4 -12
- package/src/runtime/internal/client/operations.js +40 -61
- package/src/runtime/internal/client/portal.js +163 -85
- package/src/runtime/internal/client/render.js +39 -39
- package/src/runtime/internal/client/rpc.js +3 -3
- package/src/runtime/internal/client/runtime.js +592 -433
- package/src/runtime/internal/client/selector.js +5 -2
- package/src/runtime/internal/client/template.js +133 -158
- package/src/runtime/internal/client/transport.js +38 -0
- package/src/runtime/internal/client/try.js +465 -426
- package/src/runtime/internal/client/types.d.ts +56 -23
- package/src/runtime/internal/client/utils.js +1 -3
- package/src/runtime/internal/server/dynamic.js +20 -21
- package/src/runtime/internal/server/index.js +325 -275
- package/src/runtime/internal/server/rpc.js +3 -2
- package/src/runtime/internal/server/transport.js +16 -0
- package/src/runtime/transport.js +21 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +0 -5
- package/tests/client/array/array.copy-within.test.tsrx +12 -12
- package/tests/client/array/array.derived.test.tsrx +46 -46
- package/tests/client/array/array.iteration.test.tsrx +10 -10
- package/tests/client/array/array.mutations.test.tsrx +20 -20
- package/tests/client/array/array.static.test.tsrx +11 -11
- package/tests/client/array/array.to-methods.test.tsrx +6 -6
- package/tests/client/async-suspend.test.tsrx +74 -75
- package/tests/client/basic/basic.attributes.test.tsrx +86 -83
- package/tests/client/basic/basic.collections.test.tsrx +12 -12
- package/tests/client/basic/basic.components.test.tsrx +99 -25
- package/tests/client/basic/basic.errors.test.tsrx +18 -18
- package/tests/client/basic/basic.events.test.tsrx +42 -42
- package/tests/client/basic/basic.get-set.test.tsrx +8 -8
- package/tests/client/basic/basic.reactivity.test.tsrx +73 -38
- package/tests/client/basic/basic.rendering.test.tsrx +25 -25
- package/tests/client/basic/basic.utilities.test.tsrx +3 -3
- package/tests/client/boundaries.test.tsrx +8 -8
- package/tests/client/boxed-locals.test.tsrx +452 -0
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.tsrx.snap +6 -6
- package/tests/client/compiler/compiler.assignments.test.tsrx +9 -73
- package/tests/client/compiler/compiler.attributes.test.tsrx +23 -23
- package/tests/client/compiler/compiler.basic.test.tsrx +15 -60
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +18 -43
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +2 -2
- package/tests/client/composite/__snapshots__/composite.render.test.tsrx.snap +0 -1
- package/tests/client/composite/composite.dynamic-components.test.tsrx +77 -6
- package/tests/client/composite/composite.props.test.tsrx +149 -12
- package/tests/client/composite/composite.reactivity.test.tsrx +51 -52
- package/tests/client/composite/composite.render.test.tsrx +26 -9
- package/tests/client/css/scoped-styles.test.tsrx +8 -8
- package/tests/client/date.test.tsrx +42 -42
- package/tests/client/derived-release.test.tsrx +370 -0
- package/tests/client/dynamic-elements.test.tsrx +45 -45
- package/tests/client/events.test.tsrx +97 -71
- package/tests/client/for-selector.test.tsrx +14 -14
- package/tests/client/for-single-root-items.test.tsrx +118 -3
- package/tests/client/for.test.tsrx +332 -31
- package/tests/client/head.test.tsrx +19 -19
- package/tests/client/html.test.tsrx +11 -9
- package/tests/client/if-block.test.tsrx +80 -0
- package/tests/client/map.test.tsrx +16 -16
- package/tests/client/media-query.test.tsrx +7 -7
- package/tests/client/portal.test.tsrx +224 -26
- package/tests/client/primitive-text.test.tsrx +50 -0
- package/tests/client/prop-kind-switch.test.tsrx +141 -0
- package/tests/client/ref.test.tsrx +17 -17
- package/tests/client/return.test.tsrx +26 -3
- package/tests/client/root-boundary.test.tsrx +42 -0
- package/tests/client/scoped-flush.test.tsrx +8 -8
- package/tests/client/set.test.tsrx +6 -6
- package/tests/client/svg.test.tsrx +11 -11
- package/tests/client/switch.test.tsrx +44 -44
- package/tests/client/track-async-hydration.test.tsrx +4 -4
- package/tests/client/try.test.tsrx +151 -83
- package/tests/client/tsx.test.tsrx +43 -40
- package/tests/client/url/url.derived.test.tsrx +6 -6
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +10 -10
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +10 -10
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +18 -18
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +2 -2
- package/tests/hydration/basic.test.js +74 -1
- package/tests/hydration/build-components.js +22 -1
- package/tests/hydration/compiled/client/basic.js +1142 -713
- package/tests/hydration/compiled/client/composite.js +151 -100
- package/tests/hydration/compiled/client/events.js +184 -171
- package/tests/hydration/compiled/client/for.js +1472 -1132
- package/tests/hydration/compiled/client/fragment-cursor.js +2341 -0
- package/tests/hydration/compiled/client/head.js +254 -201
- package/tests/hydration/compiled/client/hmr.js +54 -41
- package/tests/hydration/compiled/client/html-in-template.js +54 -39
- package/tests/hydration/compiled/client/html.js +1633 -1263
- package/tests/hydration/compiled/client/if-children.js +420 -270
- package/tests/hydration/compiled/client/if-fragment-controlflow.js +363 -317
- package/tests/hydration/compiled/client/if.js +229 -219
- package/tests/hydration/compiled/client/mixed-control-flow.js +420 -404
- package/tests/hydration/compiled/client/nested-control-flow.js +1326 -1277
- package/tests/hydration/compiled/client/portal.js +87 -95
- package/tests/hydration/compiled/client/reactivity.js +135 -101
- package/tests/hydration/compiled/client/return.js +28 -19
- package/tests/hydration/compiled/client/streaming.js +390 -306
- package/tests/hydration/compiled/client/switch.js +258 -266
- package/tests/hydration/compiled/client/track-async-serialization.js +448 -280
- package/tests/hydration/compiled/client/try.js +173 -129
- package/tests/hydration/compiled/client/typed-text.js +71 -0
- package/tests/hydration/compiled/fixtures/money.js +10 -0
- package/tests/hydration/compiled/server/basic.js +123 -6
- package/tests/hydration/compiled/server/composite.js +16 -30
- package/tests/hydration/compiled/server/events.js +66 -18
- package/tests/hydration/compiled/server/for.js +117 -41
- package/tests/hydration/compiled/server/fragment-cursor.js +1687 -0
- package/tests/hydration/compiled/server/head.js +20 -20
- package/tests/hydration/compiled/server/hmr.js +2 -2
- package/tests/hydration/compiled/server/html.js +70 -238
- package/tests/hydration/compiled/server/if-children.js +107 -15
- package/tests/hydration/compiled/server/if.js +11 -15
- package/tests/hydration/compiled/server/mixed-control-flow.js +8 -8
- package/tests/hydration/compiled/server/portal.js +14 -22
- package/tests/hydration/compiled/server/reactivity.js +14 -14
- package/tests/hydration/compiled/server/streaming.js +19 -19
- package/tests/hydration/compiled/server/switch.js +8 -8
- package/tests/hydration/compiled/server/track-async-serialization.js +150 -23
- package/tests/hydration/compiled/server/try.js +8 -8
- package/tests/hydration/compiled/server/typed-text.js +17 -0
- package/tests/hydration/components/basic.tsrx +44 -8
- package/tests/hydration/components/composite.tsrx +2 -2
- package/tests/hydration/components/events.tsrx +25 -25
- package/tests/hydration/components/for.tsrx +115 -67
- package/tests/hydration/components/fragment-cursor.tsrx +650 -0
- package/tests/hydration/components/head.tsrx +16 -16
- package/tests/hydration/components/hmr.tsrx +2 -2
- package/tests/hydration/components/html.tsrx +7 -7
- package/tests/hydration/components/if-children.tsrx +72 -25
- package/tests/hydration/components/if.tsrx +18 -18
- package/tests/hydration/components/mixed-control-flow.tsrx +11 -11
- package/tests/hydration/components/portal.tsrx +3 -3
- package/tests/hydration/components/reactivity.tsrx +16 -16
- package/tests/hydration/components/streaming.tsrx +20 -20
- package/tests/hydration/components/switch.tsrx +20 -20
- package/tests/hydration/components/text-types.ts +4 -0
- package/tests/hydration/components/track-async-serialization.tsrx +80 -26
- package/tests/hydration/components/try.tsrx +8 -8
- package/tests/hydration/components/typed-text.tsrx +22 -0
- package/tests/hydration/fixtures/money.js +10 -0
- package/tests/hydration/for.test.js +36 -0
- package/tests/hydration/fragment-cursor.test.js +111 -0
- package/tests/hydration/if-children.test.js +24 -0
- package/tests/hydration/streaming.test.js +19 -0
- package/tests/hydration/track-async-serialization.test.js +87 -2
- package/tests/hydration/tsconfig.text-types.json +10 -0
- package/tests/hydration/typed-text.test.js +34 -0
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +42 -42
- package/tests/server/basic.components.test.tsrx +64 -8
- package/tests/server/basic.test.tsrx +34 -32
- package/tests/server/compiler.test.tsrx +1 -70
- package/tests/server/composite.props.test.tsrx +6 -6
- package/tests/server/dynamic-elements.test.tsrx +31 -8
- package/tests/server/for.test.tsrx +94 -0
- package/tests/server/head.test.tsrx +11 -11
- package/tests/server/scoped-styles.test.tsrx +2 -2
- package/tests/server/streaming-ssr.test.tsrx +48 -43
- package/tests/server/track-async-serialization.test.tsrx +204 -21
- package/tests/server/try.test.tsrx +48 -48
- package/tests/types/transport.ts +40 -0
- package/tests/utils/vite-plugin-config.test.js +23 -0
- package/types/index.d.ts +48 -7
- package/types/server.d.ts +3 -0
- package/types/transport.d.ts +15 -0
- package/src/runtime/internal/client/switch.js +0 -113
- package/src/utils/errors.js +0 -13
- package/tests/client/lazy-array.test.tsrx +0 -31
- package/tests/client/lazy-destructuring.test.tsrx +0 -438
- package/tests/client/tracked-index-access.test.tsrx +0 -113
- package/tests/server/lazy-destructuring.test.tsrx +0 -595
- package/tests/server/tracked-index-access.test.tsrx +0 -76
|
@@ -14,14 +14,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
14
14
|
|
|
15
15
|
it('render dynamic class attribute', () => {
|
|
16
16
|
function Basic() @{
|
|
17
|
-
|
|
17
|
+
const active = track(false);
|
|
18
18
|
<>
|
|
19
19
|
<button
|
|
20
20
|
onClick={() => {
|
|
21
|
-
active = !active;
|
|
21
|
+
active.value = !active.value;
|
|
22
22
|
}}
|
|
23
23
|
>{'Toggle'}</button>
|
|
24
|
-
<div class={active ? 'active' : 'inactive'}>{'Dynamic Class'}</div>
|
|
24
|
+
<div class={active.value ? 'active' : 'inactive'}>{'Dynamic Class'}</div>
|
|
25
25
|
<style>
|
|
26
26
|
.active {
|
|
27
27
|
color: green;
|
|
@@ -91,14 +91,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
91
91
|
|
|
92
92
|
it('render dynamic class object', () => {
|
|
93
93
|
function Basic() @{
|
|
94
|
-
|
|
94
|
+
const active = track(false);
|
|
95
95
|
<>
|
|
96
96
|
<button
|
|
97
97
|
onClick={() => {
|
|
98
|
-
active = !active;
|
|
98
|
+
active.value = !active.value;
|
|
99
99
|
}}
|
|
100
100
|
>{'Toggle'}</button>
|
|
101
|
-
<div class={{ active: active, inactive: !active }}>{'Dynamic Class'}</div>
|
|
101
|
+
<div class={{ active: active.value, inactive: !active.value }}>{'Dynamic Class'}</div>
|
|
102
102
|
<style>
|
|
103
103
|
.active {
|
|
104
104
|
color: green;
|
|
@@ -130,10 +130,10 @@ describe('basic client > attribute rendering', () => {
|
|
|
130
130
|
|
|
131
131
|
it('applies scoped ripple class to multiple elements with dynamic class expressions', () => {
|
|
132
132
|
function Basic() @{
|
|
133
|
-
|
|
133
|
+
const selected = track(1);
|
|
134
134
|
<>
|
|
135
|
-
<div class={selected === 0 ? 'selected' : ''}>{`div 1`}</div>
|
|
136
|
-
<div class={selected === 0 ? 'selected' : ''}>{`div 2`}</div>
|
|
135
|
+
<div class={selected.value === 0 ? 'selected' : ''}>{`div 1`}</div>
|
|
136
|
+
<div class={selected.value === 0 ? 'selected' : ''}>{`div 2`}</div>
|
|
137
137
|
<style>
|
|
138
138
|
div {
|
|
139
139
|
background: green;
|
|
@@ -159,14 +159,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
159
159
|
|
|
160
160
|
it('render dynamic id attribute', () => {
|
|
161
161
|
function Basic() @{
|
|
162
|
-
|
|
162
|
+
const count = track(0);
|
|
163
163
|
<>
|
|
164
164
|
<button
|
|
165
165
|
onClick={() => {
|
|
166
|
-
count++;
|
|
166
|
+
count.value++;
|
|
167
167
|
}}
|
|
168
168
|
>{'Increment'}</button>
|
|
169
|
-
<div id={`item-${count}`}>{'Dynamic ID'}</div>
|
|
169
|
+
<div id={`item-${count.value}`}>{'Dynamic ID'}</div>
|
|
170
170
|
</>
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -190,14 +190,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
190
190
|
|
|
191
191
|
it('render dynamic style attribute', () => {
|
|
192
192
|
function Basic() @{
|
|
193
|
-
|
|
193
|
+
const color = track('red');
|
|
194
194
|
<>
|
|
195
195
|
<button
|
|
196
196
|
onClick={() => {
|
|
197
|
-
color = color === 'red' ? 'blue' : 'red';
|
|
197
|
+
color.value = color.value === 'red' ? 'blue' : 'red';
|
|
198
198
|
}}
|
|
199
199
|
>{'Change Color'}</button>
|
|
200
|
-
<div style={`color: ${color}; font-weight: bold;`}>{'Dynamic Style'}</div>
|
|
200
|
+
<div style={`color: ${color.value}; font-weight: bold;`}>{'Dynamic Style'}</div>
|
|
201
201
|
</>
|
|
202
202
|
}
|
|
203
203
|
|
|
@@ -218,14 +218,14 @@ describe('basic client > attribute rendering', () => {
|
|
|
218
218
|
|
|
219
219
|
it('render style attribute as dynamic object', () => {
|
|
220
220
|
function Basic() @{
|
|
221
|
-
|
|
221
|
+
const color = track('red');
|
|
222
222
|
<>
|
|
223
223
|
<button
|
|
224
224
|
onClick={() => {
|
|
225
|
-
color = color === 'red' ? 'blue' : 'red';
|
|
225
|
+
color.value = color.value === 'red' ? 'blue' : 'red';
|
|
226
226
|
}}
|
|
227
227
|
>{'Change Color'}</button>
|
|
228
|
-
<div style={{ color: color, fontWeight: 'bold' }}>{'Dynamic Style'}</div>
|
|
228
|
+
<div style={{ color: color.value, fontWeight: 'bold' }}>{'Dynamic Style'}</div>
|
|
229
229
|
</>
|
|
230
230
|
}
|
|
231
231
|
|
|
@@ -246,13 +246,13 @@ describe('basic client > attribute rendering', () => {
|
|
|
246
246
|
|
|
247
247
|
it('render tracked variable as style attribute', () => {
|
|
248
248
|
function Basic() @{
|
|
249
|
-
|
|
249
|
+
const style = track({ color: 'red', fontWeight: 'bold' });
|
|
250
250
|
function toggleColor() {
|
|
251
|
-
style = { ...style, color: style.color === 'red' ? 'blue' : 'red' };
|
|
251
|
+
style.value = { ...style.value, color: style.value.color === 'red' ? 'blue' : 'red' };
|
|
252
252
|
}
|
|
253
253
|
<>
|
|
254
254
|
<button onClick={toggleColor}>{'Change Color'}</button>
|
|
255
|
-
<div {style}>{'Dynamic Style'}</div>
|
|
255
|
+
<div style={style.value}>{'Dynamic Style'}</div>
|
|
256
256
|
</>
|
|
257
257
|
}
|
|
258
258
|
|
|
@@ -344,16 +344,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
344
344
|
|
|
345
345
|
it('render dynamic boolean attributes', () => {
|
|
346
346
|
function Basic() @{
|
|
347
|
-
|
|
348
|
-
|
|
347
|
+
const disabled = track(false);
|
|
348
|
+
const checked = track(false);
|
|
349
349
|
<>
|
|
350
350
|
<button
|
|
351
351
|
onClick={() => {
|
|
352
|
-
disabled = !disabled;
|
|
353
|
-
checked = !checked;
|
|
352
|
+
disabled.value = !disabled.value;
|
|
353
|
+
checked.value = !checked.value;
|
|
354
354
|
}}
|
|
355
355
|
>{'Toggle'}</button>
|
|
356
|
-
<input type="checkbox" {disabled} {checked} />
|
|
356
|
+
<input type="checkbox" disabled={disabled.value} checked={checked.value} />
|
|
357
357
|
</>
|
|
358
358
|
}
|
|
359
359
|
|
|
@@ -374,19 +374,19 @@ describe('basic client > attribute rendering', () => {
|
|
|
374
374
|
|
|
375
375
|
it('render multiple dynamic attributes', () => {
|
|
376
376
|
function Basic() @{
|
|
377
|
-
|
|
378
|
-
|
|
377
|
+
const theme = track('light');
|
|
378
|
+
const size = track('medium');
|
|
379
379
|
<>
|
|
380
380
|
<button
|
|
381
381
|
onClick={() => {
|
|
382
|
-
theme = theme === 'light' ? 'dark' : 'light';
|
|
383
|
-
size = size === 'medium' ? 'large' : 'medium';
|
|
382
|
+
theme.value = theme.value === 'light' ? 'dark' : 'light';
|
|
383
|
+
size.value = size.value === 'medium' ? 'large' : 'medium';
|
|
384
384
|
}}
|
|
385
385
|
>{'Toggle Theme & Size'}</button>
|
|
386
386
|
<div
|
|
387
|
-
class={`theme-${theme} size-${size}`}
|
|
388
|
-
data-theme={theme}
|
|
389
|
-
data-size={size}
|
|
387
|
+
class={`theme-${theme.value} size-${size.value}`}
|
|
388
|
+
data-theme={theme.value}
|
|
389
|
+
data-size={size.value}
|
|
390
390
|
>{'Multiple Dynamic Attributes'}</div>
|
|
391
391
|
</>
|
|
392
392
|
}
|
|
@@ -410,18 +410,18 @@ describe('basic client > attribute rendering', () => {
|
|
|
410
410
|
|
|
411
411
|
it('render conditional attributes', () => {
|
|
412
412
|
function Basic() @{
|
|
413
|
-
|
|
414
|
-
|
|
413
|
+
const showTitle = track(false);
|
|
414
|
+
const showAria = track(false);
|
|
415
415
|
<>
|
|
416
416
|
<button
|
|
417
417
|
onClick={() => {
|
|
418
|
-
showTitle = !showTitle;
|
|
419
|
-
showAria = !showAria;
|
|
418
|
+
showTitle.value = !showTitle.value;
|
|
419
|
+
showAria.value = !showAria.value;
|
|
420
420
|
}}
|
|
421
421
|
>{'Toggle Attributes'}</button>
|
|
422
422
|
<div
|
|
423
|
-
title={showTitle ? 'This is a title' : undefined}
|
|
424
|
-
aria-label={showAria ? 'Accessible label' : undefined}
|
|
423
|
+
title={showTitle.value ? 'This is a title' : undefined}
|
|
424
|
+
aria-label={showAria.value ? 'Accessible label' : undefined}
|
|
425
425
|
>{'Conditional Attributes'}</div>
|
|
426
426
|
</>
|
|
427
427
|
}
|
|
@@ -449,21 +449,21 @@ describe('basic client > attribute rendering', () => {
|
|
|
449
449
|
|
|
450
450
|
it('render spread attributes', () => {
|
|
451
451
|
function Basic() @{
|
|
452
|
-
|
|
452
|
+
const attrs = track<TestAttributes>({
|
|
453
453
|
class: 'initial',
|
|
454
454
|
id: 'test-1',
|
|
455
455
|
});
|
|
456
456
|
<>
|
|
457
457
|
<button
|
|
458
458
|
onClick={() => {
|
|
459
|
-
attrs = {
|
|
459
|
+
attrs.value = {
|
|
460
460
|
class: 'updated',
|
|
461
461
|
id: 'test-2',
|
|
462
462
|
'data-extra': 'value',
|
|
463
463
|
};
|
|
464
464
|
}}
|
|
465
465
|
>{'Update Attributes'}</button>
|
|
466
|
-
<div {...attrs}>{'Spread Attributes'}</div>
|
|
466
|
+
<div {...attrs.value}>{'Spread Attributes'}</div>
|
|
467
467
|
</>
|
|
468
468
|
}
|
|
469
469
|
|
|
@@ -486,12 +486,12 @@ describe('basic client > attribute rendering', () => {
|
|
|
486
486
|
|
|
487
487
|
it('renders with reactive attributes with nested reactive attributes', () => {
|
|
488
488
|
function App() @{
|
|
489
|
-
|
|
490
|
-
|
|
489
|
+
const value = track('parent-class');
|
|
490
|
+
const nested = track('nested-class');
|
|
491
491
|
<>
|
|
492
|
-
<p class={value}>{'Colored parent value'}</p>
|
|
492
|
+
<p class={value.value}>{'Colored parent value'}</p>
|
|
493
493
|
<div>
|
|
494
|
-
<p class={nested}>{'Colored nested value'}</p>
|
|
494
|
+
<p class={nested.value}>{'Colored nested value'}</p>
|
|
495
495
|
</div>
|
|
496
496
|
</>
|
|
497
497
|
}
|
|
@@ -534,25 +534,28 @@ describe('basic client > attribute rendering', () => {
|
|
|
534
534
|
|
|
535
535
|
it('handles reactive event handler changes', () => {
|
|
536
536
|
function Basic() @{
|
|
537
|
-
|
|
538
|
-
|
|
537
|
+
const count = track(0);
|
|
538
|
+
const mode = track<'increment' | 'decrement'>('increment');
|
|
539
539
|
const incrementHandler = () => {
|
|
540
|
-
count++;
|
|
540
|
+
count.value++;
|
|
541
541
|
};
|
|
542
542
|
const decrementHandler = () => {
|
|
543
|
-
count--;
|
|
543
|
+
count.value--;
|
|
544
544
|
};
|
|
545
545
|
<>
|
|
546
546
|
<button
|
|
547
547
|
onClick={() => {
|
|
548
|
-
mode = mode === 'increment' ? 'decrement' : 'increment';
|
|
548
|
+
mode.value = mode.value === 'increment' ? 'decrement' : 'increment';
|
|
549
549
|
}}
|
|
550
550
|
class="toggle-mode"
|
|
551
551
|
>{'Toggle Mode'}</button>
|
|
552
|
-
<button
|
|
553
|
-
{mode === 'increment' ?
|
|
552
|
+
<button
|
|
553
|
+
onClick={mode.value === 'increment' ? incrementHandler : decrementHandler}
|
|
554
|
+
class="action"
|
|
555
|
+
>
|
|
556
|
+
{mode.value === 'increment' ? '+' : '-'}
|
|
554
557
|
</button>
|
|
555
|
-
<div class="count">{count}</div>
|
|
558
|
+
<div class="count">{count.value}</div>
|
|
556
559
|
</>
|
|
557
560
|
}
|
|
558
561
|
|
|
@@ -647,16 +650,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
647
650
|
|
|
648
651
|
it('handles custom events with customName option', () => {
|
|
649
652
|
function Basic() @{
|
|
650
|
-
|
|
653
|
+
const customEventCount = track(0);
|
|
651
654
|
const handleCustom = {
|
|
652
655
|
handleEvent(event: CustomEvent) {
|
|
653
|
-
customEventCount += event.detail.value;
|
|
656
|
+
customEventCount.value += event.detail.value;
|
|
654
657
|
},
|
|
655
658
|
customName: 'MyCustomEvent',
|
|
656
659
|
};
|
|
657
660
|
<div>
|
|
658
661
|
<div onMyCustomEvent={handleCustom} class="custom-target">{'Custom'}</div>
|
|
659
|
-
<div class="custom-count">{customEventCount}</div>
|
|
662
|
+
<div class="custom-count">{customEventCount.value}</div>
|
|
660
663
|
</div>
|
|
661
664
|
}
|
|
662
665
|
|
|
@@ -680,22 +683,22 @@ describe('basic client > attribute rendering', () => {
|
|
|
680
683
|
|
|
681
684
|
it('handles events with delegated: false option to bypass delegation', () => {
|
|
682
685
|
function Basic() @{
|
|
683
|
-
|
|
684
|
-
|
|
686
|
+
const delegatedCount = track(0);
|
|
687
|
+
const nonDelegatedCount = track(0);
|
|
685
688
|
const delegatedHandler = () => {
|
|
686
|
-
delegatedCount++;
|
|
689
|
+
delegatedCount.value++;
|
|
687
690
|
};
|
|
688
691
|
const nonDelegatedHandler = {
|
|
689
692
|
handleEvent() {
|
|
690
|
-
nonDelegatedCount++;
|
|
693
|
+
nonDelegatedCount.value++;
|
|
691
694
|
},
|
|
692
695
|
delegated: false,
|
|
693
696
|
};
|
|
694
697
|
<div>
|
|
695
698
|
<button onClick={delegatedHandler} class="delegated-btn">{'Delegated'}</button>
|
|
696
699
|
<button onClick={nonDelegatedHandler} class="non-delegated-btn">{'Non-Delegated'}</button>
|
|
697
|
-
<div class="delegated-count">{delegatedCount}</div>
|
|
698
|
-
<div class="non-delegated-count">{nonDelegatedCount}</div>
|
|
700
|
+
<div class="delegated-count">{delegatedCount.value}</div>
|
|
701
|
+
<div class="non-delegated-count">{nonDelegatedCount.value}</div>
|
|
699
702
|
</div>
|
|
700
703
|
}
|
|
701
704
|
|
|
@@ -789,21 +792,21 @@ describe('basic client > attribute rendering', () => {
|
|
|
789
792
|
|
|
790
793
|
it('handles events defined as function directly vs as object', () => {
|
|
791
794
|
function Basic() @{
|
|
792
|
-
|
|
793
|
-
|
|
795
|
+
const functionCount = track(0);
|
|
796
|
+
const objectCount = track(0);
|
|
794
797
|
const functionHandler = () => {
|
|
795
|
-
functionCount++;
|
|
798
|
+
functionCount.value++;
|
|
796
799
|
};
|
|
797
800
|
const objectHandler = {
|
|
798
801
|
handleEvent() {
|
|
799
|
-
objectCount++;
|
|
802
|
+
objectCount.value++;
|
|
800
803
|
},
|
|
801
804
|
};
|
|
802
805
|
<div>
|
|
803
806
|
<button onClick={functionHandler} class="function-btn">{'Function'}</button>
|
|
804
807
|
<button onClick={objectHandler} class="object-btn">{'Object'}</button>
|
|
805
|
-
<div class="function-count">{functionCount}</div>
|
|
806
|
-
<div class="object-count">{objectCount}</div>
|
|
808
|
+
<div class="function-count">{functionCount.value}</div>
|
|
809
|
+
<div class="object-count">{objectCount.value}</div>
|
|
807
810
|
</div>
|
|
808
811
|
}
|
|
809
812
|
|
|
@@ -839,13 +842,13 @@ describe('basic client > attribute rendering', () => {
|
|
|
839
842
|
|
|
840
843
|
it('handles passive event option', () => {
|
|
841
844
|
function Basic() @{
|
|
842
|
-
|
|
843
|
-
|
|
845
|
+
const passiveDefaultPrevented = track<boolean | null>(null);
|
|
846
|
+
const nonPassiveDefaultPrevented = track<boolean | null>(null);
|
|
844
847
|
const passiveHandler = {
|
|
845
848
|
handleEvent(event: Event) {
|
|
846
849
|
event.preventDefault();
|
|
847
850
|
// In passive listeners, preventDefault() is ignored
|
|
848
|
-
passiveDefaultPrevented = event.defaultPrevented;
|
|
851
|
+
passiveDefaultPrevented.value = event.defaultPrevented;
|
|
849
852
|
},
|
|
850
853
|
passive: true,
|
|
851
854
|
delegated: false, // Need to ensure it's not delegated to test passive properly
|
|
@@ -854,7 +857,7 @@ describe('basic client > attribute rendering', () => {
|
|
|
854
857
|
handleEvent(event: Event) {
|
|
855
858
|
event.preventDefault();
|
|
856
859
|
// In non-passive listeners, preventDefault() works
|
|
857
|
-
nonPassiveDefaultPrevented = event.defaultPrevented;
|
|
860
|
+
nonPassiveDefaultPrevented.value = event.defaultPrevented;
|
|
858
861
|
},
|
|
859
862
|
delegated: false,
|
|
860
863
|
};
|
|
@@ -862,16 +865,16 @@ describe('basic client > attribute rendering', () => {
|
|
|
862
865
|
<div onWheel={passiveHandler} class="passive-target">{'Passive'}</div>
|
|
863
866
|
<div onWheel={nonPassiveHandler} class="non-passive-target">{'Non-Passive'}</div>
|
|
864
867
|
<div class="passive-result">
|
|
865
|
-
{passiveDefaultPrevented === null
|
|
868
|
+
{passiveDefaultPrevented.value === null
|
|
866
869
|
? 'not-tested'
|
|
867
|
-
: passiveDefaultPrevented
|
|
870
|
+
: passiveDefaultPrevented.value
|
|
868
871
|
? 'prevented'
|
|
869
872
|
: 'not-prevented'}
|
|
870
873
|
</div>
|
|
871
874
|
<div class="non-passive-result">
|
|
872
|
-
{nonPassiveDefaultPrevented === null
|
|
875
|
+
{nonPassiveDefaultPrevented.value === null
|
|
873
876
|
? 'not-tested'
|
|
874
|
-
: nonPassiveDefaultPrevented
|
|
877
|
+
: nonPassiveDefaultPrevented.value
|
|
875
878
|
? 'prevented'
|
|
876
879
|
: 'not-prevented'}
|
|
877
880
|
</div>
|
|
@@ -901,22 +904,22 @@ describe('basic client > attribute rendering', () => {
|
|
|
901
904
|
|
|
902
905
|
it('handles once option to fire event only once', () => {
|
|
903
906
|
function Basic() @{
|
|
904
|
-
|
|
905
|
-
|
|
907
|
+
const onceCount = track(0);
|
|
908
|
+
const regularCount = track(0);
|
|
906
909
|
const onceHandler = {
|
|
907
910
|
handleEvent() {
|
|
908
|
-
onceCount++;
|
|
911
|
+
onceCount.value++;
|
|
909
912
|
},
|
|
910
913
|
once: true,
|
|
911
914
|
};
|
|
912
915
|
const regularHandler = () => {
|
|
913
|
-
regularCount++;
|
|
916
|
+
regularCount.value++;
|
|
914
917
|
};
|
|
915
918
|
<div>
|
|
916
919
|
<button onClick={onceHandler} class="once-btn">{'Once'}</button>
|
|
917
920
|
<button onClick={regularHandler} class="regular-btn">{'Regular'}</button>
|
|
918
|
-
<div class="once-count">{onceCount}</div>
|
|
919
|
-
<div class="regular-count">{regularCount}</div>
|
|
921
|
+
<div class="once-count">{onceCount.value}</div>
|
|
922
|
+
<div class="regular-count">{regularCount.value}</div>
|
|
920
923
|
</div>
|
|
921
924
|
}
|
|
922
925
|
|
|
@@ -15,16 +15,16 @@ describe('basic client > collections', () => {
|
|
|
15
15
|
|
|
16
16
|
it('renders with simple reactive objects', () => {
|
|
17
17
|
function Basic() @{
|
|
18
|
-
|
|
18
|
+
const user = track({
|
|
19
19
|
name: 'John',
|
|
20
20
|
age: 25,
|
|
21
21
|
});
|
|
22
22
|
<>
|
|
23
|
-
<div class="name">{user.name}</div>
|
|
24
|
-
<div class="age">{user.age}</div>
|
|
23
|
+
<div class="name">{user.value.name}</div>
|
|
24
|
+
<div class="age">{user.value.age}</div>
|
|
25
25
|
<button
|
|
26
26
|
onClick={() => {
|
|
27
|
-
user = { ...user, name: 'Jane', age: 30 };
|
|
27
|
+
user.value = { ...user.value, name: 'Jane', age: 30 };
|
|
28
28
|
}}
|
|
29
29
|
>{'Update User'}</button>
|
|
30
30
|
</>
|
|
@@ -48,17 +48,17 @@ describe('basic client > collections', () => {
|
|
|
48
48
|
|
|
49
49
|
it('renders with nested reactive objects', () => {
|
|
50
50
|
function Basic() @{
|
|
51
|
-
|
|
51
|
+
const user = track({
|
|
52
52
|
name: track('John'),
|
|
53
53
|
age: track(25),
|
|
54
54
|
});
|
|
55
55
|
<>
|
|
56
|
-
<div class="name">{user.name.value}</div>
|
|
57
|
-
<div class="age">{user.age.value}</div>
|
|
56
|
+
<div class="name">{user.value.name.value}</div>
|
|
57
|
+
<div class="age">{user.value.age.value}</div>
|
|
58
58
|
<button
|
|
59
59
|
onClick={() => {
|
|
60
|
-
user.name.value = 'Jane';
|
|
61
|
-
user.age.value = 30;
|
|
60
|
+
user.value.name.value = 'Jane';
|
|
61
|
+
user.value.age.value = 30;
|
|
62
62
|
}}
|
|
63
63
|
>{'Update User'}</button>
|
|
64
64
|
</>
|
|
@@ -116,11 +116,11 @@ describe('basic client > collections', () => {
|
|
|
116
116
|
|
|
117
117
|
it('cleans up mixed tsrx collection sentinels and trailing text on rerender', () => {
|
|
118
118
|
function App() @{
|
|
119
|
-
|
|
119
|
+
const primary = track(true);
|
|
120
120
|
<>
|
|
121
121
|
<div class="frame">
|
|
122
122
|
{<>
|
|
123
|
-
{primary
|
|
123
|
+
{primary.value
|
|
124
124
|
? [
|
|
125
125
|
'first:',
|
|
126
126
|
<strong class="middle">{'one'}</strong>,
|
|
@@ -135,7 +135,7 @@ describe('basic client > collections', () => {
|
|
|
135
135
|
</div>
|
|
136
136
|
<button
|
|
137
137
|
onClick={() => {
|
|
138
|
-
primary = !primary;
|
|
138
|
+
primary.value = !primary.value;
|
|
139
139
|
}}
|
|
140
140
|
>{'toggle'}</button>
|
|
141
141
|
</>
|