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
|
@@ -2,6 +2,41 @@ import type { PropsWithChildren, Tracked } from 'ripple';
|
|
|
2
2
|
import { effect, flushSync, track, untrack } from 'ripple';
|
|
3
3
|
|
|
4
4
|
describe('basic client > reactivity', () => {
|
|
5
|
+
it(
|
|
6
|
+
'keeps the previous value for teardowns after an effect calls flushSync mid-flush',
|
|
7
|
+
async () => {
|
|
8
|
+
const seen: number[] = [];
|
|
9
|
+
|
|
10
|
+
function App() @{
|
|
11
|
+
const count = track(0);
|
|
12
|
+
|
|
13
|
+
// Runs first in the flush; the nested sync flush must not release the
|
|
14
|
+
// previous values the later teardown reads.
|
|
15
|
+
effect(() => {
|
|
16
|
+
count.value;
|
|
17
|
+
flushSync();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
effect(() => {
|
|
21
|
+
count.value;
|
|
22
|
+
return () => {
|
|
23
|
+
seen.push(count.value);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
<button onClick={() => (count.value += 1)}>{count.value}</button>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render(App);
|
|
31
|
+
flushSync();
|
|
32
|
+
container.querySelector('button').click();
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
34
|
+
|
|
35
|
+
expect(container.querySelector('button').textContent).toBe('1');
|
|
36
|
+
expect(seen).toEqual([0]);
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
5
40
|
it('renders multiple reactive lexical blocks', () => {
|
|
6
41
|
function Basic() @{
|
|
7
42
|
let obj = {
|
|
@@ -89,16 +124,16 @@ describe('basic client > reactivity', () => {
|
|
|
89
124
|
|
|
90
125
|
it('renders with computed reactive state', () => {
|
|
91
126
|
function Basic() @{
|
|
92
|
-
|
|
127
|
+
const count = track(5);
|
|
93
128
|
<>
|
|
94
|
-
<div class="count">{count}</div>
|
|
95
|
-
<div class="doubled">{count * 2}</div>
|
|
129
|
+
<div class="count">{count.value}</div>
|
|
130
|
+
<div class="doubled">{count.value * 2}</div>
|
|
96
131
|
<div class="is-even">
|
|
97
|
-
{count % 2 === 0 ? 'Even' : 'Odd'}
|
|
132
|
+
{count.value % 2 === 0 ? 'Even' : 'Odd'}
|
|
98
133
|
</div>
|
|
99
134
|
<button
|
|
100
135
|
onClick={() => {
|
|
101
|
-
count++;
|
|
136
|
+
count.value++;
|
|
102
137
|
}}
|
|
103
138
|
>{'Increment'}</button>
|
|
104
139
|
</>
|
|
@@ -200,12 +235,12 @@ describe('basic client > reactivity', () => {
|
|
|
200
235
|
|
|
201
236
|
it('uses track get and set where both mutate value', () => {
|
|
202
237
|
function App() @{
|
|
203
|
-
|
|
238
|
+
const count = track(0, (v) => v + 1, (v) => v * 2);
|
|
204
239
|
<>
|
|
205
|
-
<div class="count">{count}</div>
|
|
240
|
+
<div class="count">{count.value}</div>
|
|
206
241
|
<button
|
|
207
242
|
onClick={() => {
|
|
208
|
-
count++;
|
|
243
|
+
count.value++;
|
|
209
244
|
}}
|
|
210
245
|
>{'Increment'}</button>
|
|
211
246
|
</>
|
|
@@ -225,12 +260,12 @@ describe('basic client > reactivity', () => {
|
|
|
225
260
|
|
|
226
261
|
it('uses track get and set where set only mutates value', () => {
|
|
227
262
|
function App() @{
|
|
228
|
-
|
|
263
|
+
const count = track(1, (v) => v, (v) => v * 2);
|
|
229
264
|
<>
|
|
230
|
-
<div class="count">{count}</div>
|
|
265
|
+
<div class="count">{count.value}</div>
|
|
231
266
|
<button
|
|
232
267
|
onClick={() => {
|
|
233
|
-
count++;
|
|
268
|
+
count.value++;
|
|
234
269
|
}}
|
|
235
270
|
>{'Increment'}</button>
|
|
236
271
|
</>
|
|
@@ -250,12 +285,12 @@ describe('basic client > reactivity', () => {
|
|
|
250
285
|
|
|
251
286
|
it('uses track get and set where get only mutates value', () => {
|
|
252
287
|
function App() @{
|
|
253
|
-
|
|
288
|
+
const count = track(0, (v) => v + 1, (v) => v);
|
|
254
289
|
<>
|
|
255
|
-
<div class="count">{count}</div>
|
|
290
|
+
<div class="count">{count.value}</div>
|
|
256
291
|
<button
|
|
257
292
|
onClick={() => {
|
|
258
|
-
count++;
|
|
293
|
+
count.value++;
|
|
259
294
|
}}
|
|
260
295
|
>{'Increment'}</button>
|
|
261
296
|
</>
|
|
@@ -277,14 +312,14 @@ describe('basic client > reactivity', () => {
|
|
|
277
312
|
let logs: number[] = [];
|
|
278
313
|
|
|
279
314
|
function App() @{
|
|
280
|
-
|
|
315
|
+
const count = track(0, (v) => v, (next, prev) => {
|
|
281
316
|
logs.push(prev, next);
|
|
282
317
|
return next;
|
|
283
318
|
});
|
|
284
319
|
<>
|
|
285
320
|
<button
|
|
286
321
|
onClick={() => {
|
|
287
|
-
count++;
|
|
322
|
+
count.value++;
|
|
288
323
|
}}
|
|
289
324
|
>{'Increment'}</button>
|
|
290
325
|
</>
|
|
@@ -301,12 +336,12 @@ describe('basic client > reactivity', () => {
|
|
|
301
336
|
|
|
302
337
|
it('doesn\'t error on mutating a tracked variable in track() setter', () => {
|
|
303
338
|
function Basic() @{
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
count += value;
|
|
339
|
+
const count = track(0);
|
|
340
|
+
const doubled = track(0, undefined, (value) => {
|
|
341
|
+
count.value += value;
|
|
307
342
|
return value;
|
|
308
343
|
});
|
|
309
|
-
<p>{doubled}</p>
|
|
344
|
+
<p>{doubled.value}</p>
|
|
310
345
|
}
|
|
311
346
|
|
|
312
347
|
render(Basic);
|
|
@@ -318,9 +353,9 @@ describe('basic client > reactivity', () => {
|
|
|
318
353
|
let state: { count?: number } = {};
|
|
319
354
|
|
|
320
355
|
function Basic() @{
|
|
321
|
-
|
|
356
|
+
const count = track(0);
|
|
322
357
|
effect(() => {
|
|
323
|
-
state.count = count;
|
|
358
|
+
state.count = count.value;
|
|
324
359
|
});
|
|
325
360
|
<></>
|
|
326
361
|
}
|
|
@@ -342,15 +377,15 @@ describe('basic client > reactivity', () => {
|
|
|
342
377
|
} = {};
|
|
343
378
|
|
|
344
379
|
function Basic() @{
|
|
345
|
-
|
|
380
|
+
const count = track(5);
|
|
346
381
|
effect(() => {
|
|
347
382
|
untrack(() => {
|
|
348
|
-
state.initialValue = count;
|
|
349
|
-
state.preIncrement = ++count;
|
|
350
|
-
state.postIncrement = count++;
|
|
351
|
-
state.preDecrement = --count;
|
|
352
|
-
state.postDecrement = count--;
|
|
353
|
-
state.finalValue = count;
|
|
383
|
+
state.initialValue = count.value;
|
|
384
|
+
state.preIncrement = ++count.value;
|
|
385
|
+
state.postIncrement = count.value++;
|
|
386
|
+
state.preDecrement = --count.value;
|
|
387
|
+
state.postDecrement = count.value--;
|
|
388
|
+
state.finalValue = count.value;
|
|
354
389
|
});
|
|
355
390
|
});
|
|
356
391
|
<></>
|
|
@@ -369,21 +404,21 @@ describe('basic client > reactivity', () => {
|
|
|
369
404
|
|
|
370
405
|
it('keeps other subscribers after a destroyed block writes shared state in its cleanup', () => {
|
|
371
406
|
function App() @{
|
|
372
|
-
|
|
373
|
-
|
|
407
|
+
const count = track(0);
|
|
408
|
+
const show = track(true);
|
|
374
409
|
<>
|
|
375
|
-
@if (show) {
|
|
410
|
+
@if (show.value) {
|
|
376
411
|
effect(() => {
|
|
377
|
-
count;
|
|
412
|
+
count.value;
|
|
378
413
|
return () => {
|
|
379
|
-
count = count + 1;
|
|
414
|
+
count.value = count.value + 1;
|
|
380
415
|
};
|
|
381
416
|
});
|
|
382
|
-
<span class="inner">{count}</span>
|
|
417
|
+
<span class="inner">{count.value}</span>
|
|
383
418
|
}
|
|
384
|
-
<span class="outer">{count}</span>
|
|
385
|
-
<button class="hide" onClick={() => (show = false)}>{'hide'}</button>
|
|
386
|
-
<button class="inc" onClick={() => (count = count + 1)}>{'inc'}</button>
|
|
419
|
+
<span class="outer">{count.value}</span>
|
|
420
|
+
<button class="hide" onClick={() => (show.value = false)}>{'hide'}</button>
|
|
421
|
+
<button class="inc" onClick={() => (count.value = count.value + 1)}>{'inc'}</button>
|
|
387
422
|
</>
|
|
388
423
|
}
|
|
389
424
|
|
|
@@ -279,10 +279,10 @@ second
|
|
|
279
279
|
|
|
280
280
|
it('reactively clears interpolated text when a value becomes nullish', () => {
|
|
281
281
|
function Basic() @{
|
|
282
|
-
|
|
282
|
+
const name = track<string | null>('Ada');
|
|
283
283
|
<>
|
|
284
|
-
<div class="label">Name: {name}</div>
|
|
285
|
-
<button onClick={() => (name = name == null ? 'Ada' : null)}>toggle</button>
|
|
284
|
+
<div class="label">Name: {name.value}</div>
|
|
285
|
+
<button onClick={() => (name.value = name.value == null ? 'Ada' : null)}>toggle</button>
|
|
286
286
|
</>
|
|
287
287
|
}
|
|
288
288
|
|
|
@@ -327,14 +327,14 @@ second
|
|
|
327
327
|
|
|
328
328
|
it('renders dynamic text', () => {
|
|
329
329
|
function Basic() @{
|
|
330
|
-
|
|
330
|
+
const message = track('Hello World');
|
|
331
331
|
<>
|
|
332
332
|
<button
|
|
333
333
|
onClick={() => {
|
|
334
|
-
message = 'Hello Ripple';
|
|
334
|
+
message.value = 'Hello Ripple';
|
|
335
335
|
}}
|
|
336
336
|
>{'Change Text'}</button>
|
|
337
|
-
<div>{message}</div>
|
|
337
|
+
<div>{message.value}</div>
|
|
338
338
|
</>
|
|
339
339
|
}
|
|
340
340
|
|
|
@@ -406,21 +406,21 @@ second
|
|
|
406
406
|
|
|
407
407
|
it('renders with mixed static and dynamic content', () => {
|
|
408
408
|
function Basic() @{
|
|
409
|
-
|
|
410
|
-
|
|
409
|
+
const name = track('World');
|
|
410
|
+
const count = track(0);
|
|
411
411
|
const staticMessage = 'Welcome to Ripple!';
|
|
412
412
|
<div class="mixed-content">
|
|
413
413
|
<h1>{staticMessage}</h1>
|
|
414
|
-
<p class="greeting">{'Hello, ' + name + '!'}</p>
|
|
415
|
-
<p class="notifications">{'You have ' + count + ' notifications'}</p>
|
|
414
|
+
<p class="greeting">{'Hello, ' + name.value + '!'}</p>
|
|
415
|
+
<p class="notifications">{'You have ' + count.value + ' notifications'}</p>
|
|
416
416
|
<button
|
|
417
417
|
onClick={() => {
|
|
418
|
-
count++;
|
|
418
|
+
count.value++;
|
|
419
419
|
}}
|
|
420
420
|
>{'Add Notification'}</button>
|
|
421
421
|
<button
|
|
422
422
|
onClick={() => {
|
|
423
|
-
name = name === 'World' ? 'User' : 'World';
|
|
423
|
+
name.value = name.value === 'World' ? 'User' : 'World';
|
|
424
424
|
}}
|
|
425
425
|
>{'Toggle Name'}</button>
|
|
426
426
|
</div>
|
|
@@ -448,14 +448,14 @@ second
|
|
|
448
448
|
|
|
449
449
|
it('basic operations', () => {
|
|
450
450
|
function App() @{
|
|
451
|
-
|
|
452
|
-
const a = count++;
|
|
453
|
-
const b = ++count;
|
|
451
|
+
const count = track(0);
|
|
452
|
+
const a = count.value++;
|
|
453
|
+
const b = ++count.value;
|
|
454
454
|
<>
|
|
455
455
|
<div>{a}</div>
|
|
456
456
|
<div>{b}</div>
|
|
457
457
|
<div>{5}</div>
|
|
458
|
-
<div>{count}</div>
|
|
458
|
+
<div>{count.value}</div>
|
|
459
459
|
</>
|
|
460
460
|
}
|
|
461
461
|
|
|
@@ -465,22 +465,22 @@ second
|
|
|
465
465
|
|
|
466
466
|
it('renders with conditional rendering using if statements', () => {
|
|
467
467
|
function Basic() @{
|
|
468
|
-
|
|
469
|
-
|
|
468
|
+
const showContent = track(false);
|
|
469
|
+
const userRole = track('guest');
|
|
470
470
|
<>
|
|
471
471
|
<button
|
|
472
472
|
onClick={() => {
|
|
473
|
-
showContent = !showContent;
|
|
473
|
+
showContent.value = !showContent.value;
|
|
474
474
|
}}
|
|
475
475
|
>{'Toggle Content'}</button>
|
|
476
476
|
<button
|
|
477
477
|
onClick={() => {
|
|
478
|
-
userRole = userRole === 'guest' ? 'admin' : 'guest';
|
|
478
|
+
userRole.value = userRole.value === 'guest' ? 'admin' : 'guest';
|
|
479
479
|
}}
|
|
480
480
|
>{'Toggle Role'}</button>
|
|
481
481
|
<div class="content">
|
|
482
|
-
@if (showContent) {
|
|
483
|
-
@if (userRole === 'admin') {
|
|
482
|
+
@if (showContent.value) {
|
|
483
|
+
@if (userRole.value === 'admin') {
|
|
484
484
|
<div class="admin-content">{'Admin content'}</div>
|
|
485
485
|
} @else {
|
|
486
486
|
<div class="user-content">{'User content'}</div>
|
|
@@ -620,16 +620,16 @@ second
|
|
|
620
620
|
|
|
621
621
|
it('updates control flow inside an element in an expression container child', () => {
|
|
622
622
|
function App() @{
|
|
623
|
-
|
|
623
|
+
const ok = track(true);
|
|
624
624
|
<>
|
|
625
625
|
<button
|
|
626
626
|
onClick={() => {
|
|
627
|
-
ok = !ok;
|
|
627
|
+
ok.value = !ok.value;
|
|
628
628
|
}}
|
|
629
629
|
>{'toggle'}</button>
|
|
630
630
|
<div>
|
|
631
631
|
{<h1>
|
|
632
|
-
@if (ok) {
|
|
632
|
+
@if (ok.value) {
|
|
633
633
|
<span>{'yes'}</span>
|
|
634
634
|
} @else {
|
|
635
635
|
<span>{'no'}</span>
|
|
@@ -6,14 +6,14 @@ describe('basic client > utilities', () => {
|
|
|
6
6
|
const promise = new Promise<void>((res) => (resolve = res));
|
|
7
7
|
|
|
8
8
|
function Basic() @{
|
|
9
|
-
|
|
9
|
+
const value = track(0);
|
|
10
10
|
effect(() => {
|
|
11
11
|
untrack(() => {
|
|
12
|
-
value++;
|
|
12
|
+
value.value++;
|
|
13
13
|
tick().then(() => resolve());
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
|
-
<p>{value}</p>
|
|
16
|
+
<p>{value.value}</p>
|
|
17
17
|
}
|
|
18
18
|
render(Basic);
|
|
19
19
|
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { effect, flushSync, track, type Tracked } from 'ripple';
|
|
2
2
|
|
|
3
3
|
describe('passing reactivity between boundaries tests', () => {
|
|
4
|
-
it('can pass
|
|
4
|
+
it('can pass a tracked object to a plain function and read the derived it returns', () => {
|
|
5
5
|
let log: string[] = [];
|
|
6
6
|
|
|
7
|
-
function createDouble(
|
|
8
|
-
const double = track(() => count * 2);
|
|
7
|
+
function createDouble(count: Tracked<number>) {
|
|
8
|
+
const double = track(() => count.value * 2);
|
|
9
9
|
|
|
10
10
|
effect(() => {
|
|
11
|
-
log.push('Count:' + count);
|
|
11
|
+
log.push('Count:' + count.value);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
return double;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
function App() @{
|
|
18
|
-
|
|
19
|
-
const
|
|
18
|
+
const count = track(0);
|
|
19
|
+
const double = createDouble(count);
|
|
20
20
|
<>
|
|
21
|
-
<div>{'Double: ' + double}</div>
|
|
21
|
+
<div>{'Double: ' + double.value}</div>
|
|
22
22
|
<button
|
|
23
23
|
onClick={() => {
|
|
24
|
-
count++;
|
|
24
|
+
count.value++;
|
|
25
25
|
}}
|
|
26
26
|
>{'Increment'}</button>
|
|
27
27
|
</>
|