ripple 0.2.215 → 0.3.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 +86 -0
- package/package.json +16 -7
- package/src/compiler/errors.js +1 -1
- package/src/compiler/identifier-utils.js +2 -0
- package/src/compiler/index.d.ts +2 -6
- package/src/compiler/phases/1-parse/index.js +171 -233
- package/src/compiler/phases/2-analyze/index.js +216 -16
- package/src/compiler/phases/2-analyze/prune.js +2 -2
- package/src/compiler/phases/3-transform/client/index.js +326 -94
- package/src/compiler/phases/3-transform/segments.js +43 -15
- package/src/compiler/phases/3-transform/server/index.js +71 -21
- package/src/compiler/scope.js +31 -12
- package/src/compiler/source-map-utils.js +4 -6
- package/src/compiler/types/acorn.d.ts +11 -0
- package/src/compiler/types/estree-jsx.d.ts +11 -0
- package/src/compiler/types/estree.d.ts +11 -0
- package/src/compiler/types/import.d.ts +32 -18
- package/src/compiler/types/index.d.ts +75 -23
- package/src/compiler/types/parse.d.ts +7 -10
- package/src/compiler/utils.js +48 -0
- package/src/runtime/array.js +53 -22
- package/src/runtime/date.js +15 -5
- package/src/runtime/index-client.js +41 -7
- package/src/runtime/index-server.js +7 -7
- package/src/runtime/internal/client/bindings.js +2 -2
- package/src/runtime/internal/client/blocks.js +40 -1
- package/src/runtime/internal/client/context.js +8 -0
- package/src/runtime/internal/client/for.js +3 -3
- package/src/runtime/internal/client/index.js +32 -5
- package/src/runtime/internal/client/render.js +20 -8
- package/src/runtime/internal/client/runtime.js +9 -7
- package/src/runtime/internal/client/template.js +1 -1
- package/src/runtime/internal/client/try.js +15 -22
- package/src/runtime/internal/client/utils.js +1 -1
- package/src/runtime/internal/server/context.js +8 -0
- package/src/runtime/internal/server/index.js +99 -6
- package/src/runtime/map.js +7 -7
- package/src/runtime/media-query.js +10 -1
- package/src/runtime/object.js +6 -6
- package/src/runtime/proxy.js +6 -6
- package/src/runtime/set.js +11 -11
- package/src/runtime/url-search-params.js +13 -2
- package/src/runtime/url.js +15 -5
- package/src/utils/builders.js +13 -3
- package/tests/client/array/array.copy-within.test.ripple +11 -11
- package/tests/client/array/array.derived.test.ripple +42 -42
- package/tests/client/array/array.iteration.test.ripple +12 -12
- package/tests/client/array/array.mutations.test.ripple +25 -25
- package/tests/client/array/array.static.test.ripple +103 -106
- package/tests/client/array/array.to-methods.test.ripple +8 -8
- package/tests/client/async-suspend.test.ripple +94 -0
- package/tests/client/basic/basic.attributes.test.ripple +31 -31
- package/tests/client/basic/basic.collections.test.ripple +7 -7
- package/tests/client/basic/basic.components.test.ripple +48 -10
- package/tests/client/basic/basic.errors.test.ripple +111 -30
- package/tests/client/basic/basic.events.test.ripple +11 -11
- package/tests/client/basic/basic.get-set.test.ripple +18 -18
- package/tests/client/basic/basic.reactivity.test.ripple +47 -42
- package/tests/client/basic/basic.rendering.test.ripple +7 -7
- package/tests/client/basic/basic.utilities.test.ripple +4 -4
- package/tests/client/boundaries.test.ripple +7 -7
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.ripple.snap +2 -2
- package/tests/client/compiler/compiler.assignments.test.ripple +21 -21
- package/tests/client/compiler/compiler.basic.test.ripple +223 -82
- package/tests/client/compiler/compiler.tracked-access.test.ripple +8 -9
- package/tests/client/composite/composite.dynamic-components.test.ripple +8 -8
- package/tests/client/composite/composite.generics.test.ripple +4 -4
- package/tests/client/composite/composite.props.test.ripple +9 -9
- package/tests/client/composite/composite.reactivity.test.ripple +32 -26
- package/tests/client/composite/composite.render.test.ripple +13 -4
- package/tests/client/computed-properties.test.ripple +3 -3
- package/tests/client/context.test.ripple +3 -3
- package/tests/client/css/global-additional-cases.test.ripple +4 -4
- package/tests/client/css/style-identifier.test.ripple +49 -41
- package/tests/client/date.test.ripple +40 -40
- package/tests/client/dynamic-elements.test.ripple +165 -30
- package/tests/client/events.test.ripple +25 -25
- package/tests/client/for.test.ripple +76 -8
- package/tests/client/function-overload.test.ripple +0 -1
- package/tests/client/head.test.ripple +7 -7
- package/tests/client/html.test.ripple +2 -2
- package/tests/client/input-value.test.ripple +174 -176
- package/tests/client/map.test.ripple +21 -21
- package/tests/client/media-query.test.ripple +4 -4
- package/tests/client/object.test.ripple +12 -12
- package/tests/client/portal.test.ripple +4 -4
- package/tests/client/ref.test.ripple +5 -5
- package/tests/client/return.test.ripple +17 -17
- package/tests/client/set.test.ripple +16 -16
- package/tests/client/svg.test.ripple +6 -7
- package/tests/client/switch.test.ripple +10 -10
- package/tests/client/tracked-expression.test.ripple +1 -3
- package/tests/client/try.test.ripple +56 -4
- package/tests/client/url/url.derived.test.ripple +10 -9
- package/tests/client/url/url.parsing.test.ripple +10 -10
- package/tests/client/url/url.partial-removal.test.ripple +10 -10
- package/tests/client/url/url.reactivity.test.ripple +17 -17
- package/tests/client/url/url.serialization.test.ripple +4 -4
- package/tests/client/url-search-params/url-search-params.derived.test.ripple +11 -10
- package/tests/client/url-search-params/url-search-params.initialization.test.ripple +5 -7
- package/tests/client/url-search-params/url-search-params.iteration.test.ripple +13 -13
- package/tests/client/url-search-params/url-search-params.mutation.test.ripple +19 -19
- package/tests/client/url-search-params/url-search-params.retrieval.test.ripple +17 -17
- package/tests/client/url-search-params/url-search-params.serialization.test.ripple +5 -5
- package/tests/client/url-search-params/url-search-params.tracked-url.test.ripple +5 -5
- package/tests/hydration/compiled/client/events.js +8 -11
- package/tests/hydration/compiled/client/for.js +20 -23
- package/tests/hydration/compiled/client/head.js +17 -19
- package/tests/hydration/compiled/client/hmr.js +84 -0
- package/tests/hydration/compiled/client/html.js +1 -15
- package/tests/hydration/compiled/client/if-children.js +7 -9
- package/tests/hydration/compiled/client/if.js +5 -7
- package/tests/hydration/compiled/client/mixed-control-flow.js +3 -5
- package/tests/hydration/compiled/client/portal.js +1 -1
- package/tests/hydration/compiled/client/reactivity.js +9 -11
- package/tests/hydration/compiled/client/return.js +11 -13
- package/tests/hydration/compiled/client/switch.js +4 -6
- package/tests/hydration/compiled/server/basic.js +0 -1
- package/tests/hydration/compiled/server/composite.js +0 -3
- package/tests/hydration/compiled/server/events.js +8 -12
- package/tests/hydration/compiled/server/for.js +20 -23
- package/tests/hydration/compiled/server/head.js +17 -19
- package/tests/hydration/compiled/server/hmr.js +107 -0
- package/tests/hydration/compiled/server/html.js +1 -35
- package/tests/hydration/compiled/server/if-children.js +7 -11
- package/tests/hydration/compiled/server/if.js +5 -7
- package/tests/hydration/compiled/server/mixed-control-flow.js +3 -5
- package/tests/hydration/compiled/server/portal.js +1 -9
- package/tests/hydration/compiled/server/reactivity.js +9 -11
- package/tests/hydration/compiled/server/return.js +11 -13
- package/tests/hydration/compiled/server/switch.js +4 -6
- package/tests/hydration/components/events.ripple +8 -9
- package/tests/hydration/components/for.ripple +20 -21
- package/tests/hydration/components/head.ripple +6 -8
- package/tests/hydration/components/hmr.ripple +34 -0
- package/tests/hydration/components/html.ripple +1 -3
- package/tests/hydration/components/if-children.ripple +7 -8
- package/tests/hydration/components/if.ripple +5 -6
- package/tests/hydration/components/mixed-control-flow.ripple +4 -6
- package/tests/hydration/components/portal.ripple +1 -1
- package/tests/hydration/components/reactivity.ripple +9 -10
- package/tests/hydration/components/return.ripple +11 -12
- package/tests/hydration/components/switch.ripple +6 -8
- package/tests/hydration/hmr.test.js +74 -0
- package/tests/server/await.test.ripple +2 -2
- package/tests/server/basic.attributes.test.ripple +19 -21
- package/tests/server/basic.components.test.ripple +13 -7
- package/tests/server/basic.test.ripple +20 -21
- package/tests/server/compiler.test.ripple +5 -5
- package/tests/server/composite.props.test.ripple +6 -7
- package/tests/server/composite.test.ripple +4 -4
- package/tests/server/context.test.ripple +1 -3
- package/tests/server/dynamic-elements.test.ripple +24 -24
- package/tests/server/head.test.ripple +5 -7
- package/tests/server/style-identifier.test.ripple +16 -17
- package/types/index.d.ts +266 -62
- package/types/server.d.ts +6 -6
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PropsWithChildren, Tracked } from 'ripple';
|
|
2
|
+
import { flushSync } from 'ripple';
|
|
2
3
|
|
|
3
4
|
describe('basic client > reactivity', () => {
|
|
4
5
|
it('renders multiple reactive lexical blocks', () => {
|
|
5
6
|
component Basic() {
|
|
6
7
|
<div>
|
|
7
8
|
let obj = {
|
|
8
|
-
count: track(0),
|
|
9
|
+
count: #ripple.track(0),
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
<span>{obj.@count}</span>
|
|
12
13
|
</div>
|
|
13
14
|
<div>
|
|
14
15
|
let b = {
|
|
15
|
-
count: track(0),
|
|
16
|
+
count: #ripple.track(0),
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
<button
|
|
@@ -53,27 +54,27 @@ describe('basic client > reactivity', () => {
|
|
|
53
54
|
|
|
54
55
|
<div>
|
|
55
56
|
let obj = {
|
|
56
|
-
count: track(0),
|
|
57
|
+
count: #ripple.track(0),
|
|
57
58
|
};
|
|
58
59
|
|
|
59
|
-
<span>{obj[
|
|
60
|
+
<span>{obj.@[count]}</span>
|
|
60
61
|
</div>
|
|
61
62
|
<div>
|
|
62
63
|
let b = {
|
|
63
|
-
count: track(0),
|
|
64
|
+
count: #ripple.track(0),
|
|
64
65
|
};
|
|
65
66
|
|
|
66
67
|
<button
|
|
67
68
|
onClick={() => {
|
|
68
|
-
b[
|
|
69
|
+
b.@[count]--;
|
|
69
70
|
}}
|
|
70
71
|
>
|
|
71
72
|
{'-'}
|
|
72
73
|
</button>
|
|
73
|
-
<span class="count">{b[
|
|
74
|
+
<span class="count">{b.@[count]}</span>
|
|
74
75
|
<button
|
|
75
76
|
onClick={() => {
|
|
76
|
-
b[
|
|
77
|
+
b.@[count]++;
|
|
77
78
|
}}
|
|
78
79
|
>
|
|
79
80
|
{'+'}
|
|
@@ -97,7 +98,7 @@ describe('basic client > reactivity', () => {
|
|
|
97
98
|
|
|
98
99
|
it('renders with computed reactive state', () => {
|
|
99
100
|
component Basic() {
|
|
100
|
-
let count = track(5);
|
|
101
|
+
let count = #ripple.track(5);
|
|
101
102
|
|
|
102
103
|
<div class="count">{@count}</div>
|
|
103
104
|
<div class="doubled">{@count * 2}</div>
|
|
@@ -134,11 +135,11 @@ describe('basic client > reactivity', () => {
|
|
|
134
135
|
let logs: string[] = [];
|
|
135
136
|
|
|
136
137
|
component App() {
|
|
137
|
-
let first = track(0);
|
|
138
|
-
let second = track(0);
|
|
138
|
+
let first = #ripple.track(0);
|
|
139
|
+
let second = #ripple.track(0);
|
|
139
140
|
const arr = [first, second];
|
|
140
141
|
|
|
141
|
-
const total = track(() => arr.reduce((a, b) => a + @b, 0));
|
|
142
|
+
const total = #ripple.track(() => arr.reduce((a, b) => a + @b, 0));
|
|
142
143
|
|
|
143
144
|
<button
|
|
144
145
|
onClick={() => {
|
|
@@ -155,7 +156,7 @@ describe('basic client > reactivity', () => {
|
|
|
155
156
|
{'second: ' + @second}
|
|
156
157
|
</button>
|
|
157
158
|
|
|
158
|
-
effect(() => {
|
|
159
|
+
#ripple.effect(() => {
|
|
159
160
|
let _arr: number[] = [];
|
|
160
161
|
|
|
161
162
|
arr.forEach((item) => {
|
|
@@ -165,7 +166,7 @@ describe('basic client > reactivity', () => {
|
|
|
165
166
|
logs.push(_arr.join(', '));
|
|
166
167
|
});
|
|
167
168
|
|
|
168
|
-
effect(() => {
|
|
169
|
+
#ripple.effect(() => {
|
|
169
170
|
if (arr.map((a) => @a).includes(1)) {
|
|
170
171
|
logs.push('arr includes 1');
|
|
171
172
|
}
|
|
@@ -210,7 +211,7 @@ describe('basic client > reactivity', () => {
|
|
|
210
211
|
|
|
211
212
|
it('uses track get and set where both mutate value', () => {
|
|
212
213
|
component App() {
|
|
213
|
-
let count = track(0, (v) => v + 1, (v) => v * 2);
|
|
214
|
+
let count = #ripple.track(0, (v) => v + 1, (v) => v * 2);
|
|
214
215
|
|
|
215
216
|
<div class="count">{@count}</div>
|
|
216
217
|
<button
|
|
@@ -236,7 +237,7 @@ describe('basic client > reactivity', () => {
|
|
|
236
237
|
|
|
237
238
|
it('uses track get and set where set only mutates value', () => {
|
|
238
239
|
component App() {
|
|
239
|
-
let count = track(1, (v) => v, (v) => v * 2);
|
|
240
|
+
let count = #ripple.track(1, (v) => v, (v) => v * 2);
|
|
240
241
|
|
|
241
242
|
<div class="count">{@count}</div>
|
|
242
243
|
<button
|
|
@@ -262,7 +263,7 @@ describe('basic client > reactivity', () => {
|
|
|
262
263
|
|
|
263
264
|
it('uses track get and set where get only mutates value', () => {
|
|
264
265
|
component App() {
|
|
265
|
-
let count = track(0, (v) => v + 1, (v) => v);
|
|
266
|
+
let count = #ripple.track(0, (v) => v + 1, (v) => v);
|
|
266
267
|
|
|
267
268
|
<div class="count">{@count}</div>
|
|
268
269
|
<button
|
|
@@ -290,7 +291,7 @@ describe('basic client > reactivity', () => {
|
|
|
290
291
|
let logs: number[] = [];
|
|
291
292
|
|
|
292
293
|
component App() {
|
|
293
|
-
let count = track(0, (v) => v, (next, prev) => {
|
|
294
|
+
let count = #ripple.track(0, (v) => v, (next, prev) => {
|
|
294
295
|
logs.push(prev, next);
|
|
295
296
|
return next;
|
|
296
297
|
});
|
|
@@ -313,11 +314,11 @@ describe('basic client > reactivity', () => {
|
|
|
313
314
|
expect(logs).toEqual([0, 1]);
|
|
314
315
|
});
|
|
315
316
|
|
|
316
|
-
it('doesn\'t error on mutating a tracked variable in track() setter', () => {
|
|
317
|
+
it('doesn\'t error on mutating a tracked variable in #ripple.track() setter', () => {
|
|
317
318
|
component Basic() {
|
|
318
|
-
let count = track(0);
|
|
319
|
+
let count = #ripple.track(0);
|
|
319
320
|
|
|
320
|
-
const doubled = track(0, undefined, (value) => {
|
|
321
|
+
const doubled = #ripple.track(0, undefined, (value) => {
|
|
321
322
|
@count += value;
|
|
322
323
|
return value;
|
|
323
324
|
});
|
|
@@ -334,9 +335,9 @@ describe('basic client > reactivity', () => {
|
|
|
334
335
|
let state: { count?: number } = {};
|
|
335
336
|
|
|
336
337
|
component Basic() {
|
|
337
|
-
let count = track(0);
|
|
338
|
+
let count = #ripple.track(0);
|
|
338
339
|
|
|
339
|
-
effect(() => {
|
|
340
|
+
#ripple.effect(() => {
|
|
340
341
|
state.count = @count;
|
|
341
342
|
});
|
|
342
343
|
}
|
|
@@ -358,10 +359,10 @@ describe('basic client > reactivity', () => {
|
|
|
358
359
|
} = {};
|
|
359
360
|
|
|
360
361
|
component Basic() {
|
|
361
|
-
let count = track(5);
|
|
362
|
+
let count = #ripple.track(5);
|
|
362
363
|
|
|
363
|
-
effect(() => {
|
|
364
|
-
untrack(() => {
|
|
364
|
+
#ripple.effect(() => {
|
|
365
|
+
#ripple.untrack(() => {
|
|
365
366
|
state.initialValue = @count;
|
|
366
367
|
state.preIncrement = ++@count;
|
|
367
368
|
state.postIncrement = @count++;
|
|
@@ -386,10 +387,10 @@ describe('basic client > reactivity', () => {
|
|
|
386
387
|
describe('track/trackSplit APIs', () => {
|
|
387
388
|
it('errors on invalid value as null for track with trackSplit', () => {
|
|
388
389
|
component App() {
|
|
389
|
-
let message = track('');
|
|
390
|
+
let message = #ripple.track('');
|
|
390
391
|
|
|
391
392
|
try {
|
|
392
|
-
const [a, b, rest] = trackSplit(null, ['a', 'b']);
|
|
393
|
+
const [a, b, rest] = #ripple.trackSplit(null, ['a', 'b']);
|
|
393
394
|
} catch (e) {
|
|
394
395
|
@message = (e as Error).message;
|
|
395
396
|
}
|
|
@@ -405,10 +406,10 @@ describe('basic client > reactivity', () => {
|
|
|
405
406
|
|
|
406
407
|
it('errors on invalid value as array for track with trackSplit', () => {
|
|
407
408
|
component App() {
|
|
408
|
-
let message = track('');
|
|
409
|
+
let message = #ripple.track('');
|
|
409
410
|
|
|
410
411
|
try {
|
|
411
|
-
const [a, b, rest] = trackSplit([1, 2, 3], ['a', 'b']);
|
|
412
|
+
const [a, b, rest] = #ripple.trackSplit([1, 2, 3], ['a', 'b']);
|
|
412
413
|
} catch (e) {
|
|
413
414
|
@message = (e as Error).message;
|
|
414
415
|
}
|
|
@@ -424,11 +425,11 @@ describe('basic client > reactivity', () => {
|
|
|
424
425
|
|
|
425
426
|
it('errors on invalid value as tracked for track with trackSplit', () => {
|
|
426
427
|
component App() {
|
|
427
|
-
const t = track({ a: 1, b: 2, c: 3 });
|
|
428
|
-
let message = track('');
|
|
428
|
+
const t = #ripple.track({ a: 1, b: 2, c: 3 });
|
|
429
|
+
let message = #ripple.track('');
|
|
429
430
|
|
|
430
431
|
try {
|
|
431
|
-
const [a, b, rest] = trackSplit(t, ['a', 'b']);
|
|
432
|
+
const [a, b, rest] = #ripple.trackSplit(t, ['a', 'b']);
|
|
432
433
|
} catch (e) {
|
|
433
434
|
@message = (e as Error).message;
|
|
434
435
|
}
|
|
@@ -444,7 +445,7 @@ describe('basic client > reactivity', () => {
|
|
|
444
445
|
|
|
445
446
|
it('returns undefined for non-existent props in track with trackSplit', () => {
|
|
446
447
|
component App() {
|
|
447
|
-
const [a, b, rest] = trackSplit({ a: 1, c: 1 }, ['a', 'b']);
|
|
448
|
+
const [a, b, rest] = #ripple.trackSplit({ a: 1, c: 1 }, ['a', 'b']);
|
|
448
449
|
|
|
449
450
|
<pre>{@a}</pre>
|
|
450
451
|
<pre>{String(@b)}</pre>
|
|
@@ -464,8 +465,8 @@ describe('basic client > reactivity', () => {
|
|
|
464
465
|
|
|
465
466
|
it('returns the same tracked object if plain track is called with a tracked object', () => {
|
|
466
467
|
component App() {
|
|
467
|
-
const t = track({ a: 1, b: 2, c: 3 });
|
|
468
|
-
const doublet = track(t);
|
|
468
|
+
const t = #ripple.track({ a: 1, b: 2, c: 3 });
|
|
469
|
+
const doublet = #ripple.track(t);
|
|
469
470
|
|
|
470
471
|
<pre>{t === doublet}</pre>
|
|
471
472
|
}
|
|
@@ -480,8 +481,8 @@ describe('basic client > reactivity', () => {
|
|
|
480
481
|
let logs: string[] = [];
|
|
481
482
|
|
|
482
483
|
component App() {
|
|
483
|
-
let count = track(0);
|
|
484
|
-
let name = track('Click Me');
|
|
484
|
+
let count = #ripple.track(0);
|
|
485
|
+
let name = #ripple.track('Click Me');
|
|
485
486
|
|
|
486
487
|
function buttonRef(el: HTMLButtonElement) {
|
|
487
488
|
logs.push('ref called');
|
|
@@ -493,7 +494,7 @@ describe('basic client > reactivity', () => {
|
|
|
493
494
|
<Child
|
|
494
495
|
class="my-button"
|
|
495
496
|
onClick={() => @name === 'Click Me' ? @name = 'Clicked' : @name = 'Click Me'}
|
|
496
|
-
{
|
|
497
|
+
{count}
|
|
497
498
|
{ref buttonRef}
|
|
498
499
|
>
|
|
499
500
|
{@name}
|
|
@@ -502,8 +503,12 @@ describe('basic client > reactivity', () => {
|
|
|
502
503
|
<button onClick={() => @count++}>{'Increment Count'}</button>
|
|
503
504
|
}
|
|
504
505
|
|
|
505
|
-
component Child(props: PropsWithChildren<{
|
|
506
|
-
|
|
506
|
+
component Child(props: PropsWithChildren<{
|
|
507
|
+
count: Tracked<number>;
|
|
508
|
+
class: string;
|
|
509
|
+
onClick: () => void;
|
|
510
|
+
}>) {
|
|
511
|
+
const [children, count, rest] = #ripple.trackSplit(props, ['children', 'count']);
|
|
507
512
|
|
|
508
513
|
if (@count < 2) {
|
|
509
514
|
<button {...@rest}>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { flushSync } from 'ripple';
|
|
3
3
|
|
|
4
4
|
describe('basic client > rendering & text', () => {
|
|
5
5
|
it('renders static text', () => {
|
|
@@ -27,7 +27,7 @@ describe('basic client > rendering & text', () => {
|
|
|
27
27
|
|
|
28
28
|
it('renders dynamic text', () => {
|
|
29
29
|
component Basic() {
|
|
30
|
-
let text = track('Hello World');
|
|
30
|
+
let text = #ripple.track('Hello World');
|
|
31
31
|
|
|
32
32
|
<button
|
|
33
33
|
onClick={() => {
|
|
@@ -104,8 +104,8 @@ describe('basic client > rendering & text', () => {
|
|
|
104
104
|
|
|
105
105
|
it('renders with mixed static and dynamic content', () => {
|
|
106
106
|
component Basic() {
|
|
107
|
-
let name = track('World');
|
|
108
|
-
let count = track(0);
|
|
107
|
+
let name = #ripple.track('World');
|
|
108
|
+
let count = #ripple.track(0);
|
|
109
109
|
const staticMessage = 'Welcome to Ripple!';
|
|
110
110
|
|
|
111
111
|
<div class="mixed-content">
|
|
@@ -151,7 +151,7 @@ describe('basic client > rendering & text', () => {
|
|
|
151
151
|
|
|
152
152
|
it('basic operations', () => {
|
|
153
153
|
component App() {
|
|
154
|
-
let count = track(0);
|
|
154
|
+
let count = #ripple.track(0);
|
|
155
155
|
<div>{@count++}</div>
|
|
156
156
|
<div>{++@count}</div>
|
|
157
157
|
<div>{5}</div>
|
|
@@ -164,8 +164,8 @@ describe('basic client > rendering & text', () => {
|
|
|
164
164
|
|
|
165
165
|
it('renders with conditional rendering using if statements', () => {
|
|
166
166
|
component Basic() {
|
|
167
|
-
let showContent = track(false);
|
|
168
|
-
let userRole = track('guest');
|
|
167
|
+
let showContent = #ripple.track(false);
|
|
168
|
+
let userRole = #ripple.track('guest');
|
|
169
169
|
|
|
170
170
|
<button
|
|
171
171
|
onClick={() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tick } from 'ripple';
|
|
2
2
|
|
|
3
3
|
describe('basic client > utilities', () => {
|
|
4
4
|
it('tick function', async () => {
|
|
@@ -6,9 +6,9 @@ describe('basic client > utilities', () => {
|
|
|
6
6
|
const promise = new Promise<void>((res) => (resolve = res));
|
|
7
7
|
|
|
8
8
|
component Basic() {
|
|
9
|
-
let value = track(0);
|
|
10
|
-
effect(() => {
|
|
11
|
-
untrack(() => {
|
|
9
|
+
let value = #ripple.track(0);
|
|
10
|
+
#ripple.effect(() => {
|
|
11
|
+
#ripple.untrack(() => {
|
|
12
12
|
@value++;
|
|
13
13
|
tick().then(() => resolve());
|
|
14
14
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { flushSync,
|
|
1
|
+
import { flushSync, type Tracked } from 'ripple';
|
|
2
2
|
|
|
3
3
|
describe('passing reactivity between boundaries tests', () => {
|
|
4
4
|
it('can pass reactivity between functions with simple arrays and destructuring', () => {
|
|
5
5
|
let log: string[] = [];
|
|
6
6
|
|
|
7
7
|
function createDouble([count]: [Tracked<number>]) {
|
|
8
|
-
const double = track(() => @count * 2);
|
|
8
|
+
const double = #ripple.track(() => @count * 2);
|
|
9
9
|
|
|
10
|
-
effect(() => {
|
|
10
|
+
#ripple.effect(() => {
|
|
11
11
|
log.push('Count:' + @count);
|
|
12
12
|
});
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ describe('passing reactivity between boundaries tests', () => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
component App() {
|
|
18
|
-
let count = track(0);
|
|
18
|
+
let count = #ripple.track(0);
|
|
19
19
|
|
|
20
20
|
const [double] = createDouble([count]);
|
|
21
21
|
|
|
@@ -54,9 +54,9 @@ describe('passing reactivity between boundaries tests', () => {
|
|
|
54
54
|
let log: string[] = [];
|
|
55
55
|
|
|
56
56
|
function createDouble({ count }: { count: Tracked<number> }) {
|
|
57
|
-
const double = track(() => @count * 2);
|
|
57
|
+
const double = #ripple.track(() => @count * 2);
|
|
58
58
|
|
|
59
|
-
effect(() => {
|
|
59
|
+
#ripple.effect(() => {
|
|
60
60
|
log.push('Count:' + @count);
|
|
61
61
|
});
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ describe('passing reactivity between boundaries tests', () => {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
component App() {
|
|
67
|
-
let count = track(0);
|
|
67
|
+
let count = #ripple.track(0);
|
|
68
68
|
|
|
69
69
|
const { double } = createDouble({ count });
|
|
70
70
|
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
exports[`compiler > assignments > compiles tracked values in effect with assignment expression 1`] = `"state.count = _$_.get(count);"`;
|
|
4
4
|
|
|
5
5
|
exports[`compiler > assignments > compiles tracked values in effect with update expressions 1`] = `
|
|
6
|
-
"_$_.
|
|
6
|
+
"_$_.untrack(() => {
|
|
7
7
|
state.preIncrement = _$_.update_pre(count);
|
|
8
8
|
state.postIncrement = _$_.update(count);
|
|
9
9
|
state.preDecrement = _$_.update_pre(count, -1);
|
|
10
10
|
state.postDecrement = _$_.update(count, -1);
|
|
11
|
-
})
|
|
11
|
+
});"
|
|
12
12
|
`;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RippleArray } from 'ripple';
|
|
2
2
|
import { compile } from 'ripple/compiler';
|
|
3
3
|
|
|
4
|
+
const EFFECT_BODY_REGEX = /_\$\_\.effect\(\(\) => \{([\s\S]*?)\n\t\}\);/;
|
|
5
|
+
|
|
4
6
|
describe('compiler > assignments', () => {
|
|
5
7
|
it('properly handles JS assignments, reads and updates to array indices', () => {
|
|
6
8
|
const logs: (number | undefined)[] = [];
|
|
7
9
|
|
|
8
10
|
component App() {
|
|
9
11
|
let items: number[] = [];
|
|
10
|
-
let tracked_items = track<number[]>([]);
|
|
12
|
+
let tracked_items = #ripple.track<number[]>([]);
|
|
11
13
|
let items2 = new Array();
|
|
12
|
-
let items3
|
|
14
|
+
let items3: RippleArray<number> = #ripple[];
|
|
13
15
|
let i = 0;
|
|
14
16
|
|
|
15
17
|
logs.push(items[0]);
|
|
@@ -107,34 +109,32 @@ describe('compiler > assignments', () => {
|
|
|
107
109
|
|
|
108
110
|
it('compiles tracked values in effect with assignment expression', () => {
|
|
109
111
|
const source = `component App() {
|
|
110
|
-
let count = track(0);
|
|
112
|
+
let count = #ripple.track(0);
|
|
111
113
|
|
|
112
|
-
effect(() => {
|
|
113
|
-
|
|
114
|
-
})
|
|
114
|
+
#ripple.effect(() => {
|
|
115
|
+
state.count = @count;
|
|
116
|
+
});
|
|
115
117
|
}`;
|
|
116
118
|
const result = compile(source, 'test.ripple');
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
expect(effectMatch?.[1].trim()).toMatchSnapshot();
|
|
119
|
+
const effect_match = result.js.code.match(EFFECT_BODY_REGEX);
|
|
120
|
+
expect(effect_match?.[1].trim()).toMatchSnapshot();
|
|
120
121
|
});
|
|
121
122
|
|
|
122
123
|
it('compiles tracked values in effect with update expressions', () => {
|
|
123
124
|
const source = `component App() {
|
|
124
|
-
let count = track(5);
|
|
125
|
+
let count = #ripple.track(5);
|
|
125
126
|
|
|
126
|
-
effect(() => {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
#ripple.effect(() => {
|
|
128
|
+
#ripple.untrack(() => {
|
|
129
|
+
state.preIncrement = ++@count;
|
|
130
|
+
state.postIncrement = @count++;
|
|
131
|
+
state.preDecrement = --@count;
|
|
132
|
+
state.postDecrement = @count--;
|
|
133
|
+
});
|
|
132
134
|
});
|
|
133
|
-
})
|
|
134
135
|
}`;
|
|
135
136
|
const result = compile(source, 'test.ripple');
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
expect(effectMatch?.[1].trim()).toMatchSnapshot();
|
|
137
|
+
const effect_match = result.js.code.match(EFFECT_BODY_REGEX);
|
|
138
|
+
expect(effect_match?.[1].trim()).toMatchSnapshot();
|
|
139
139
|
});
|
|
140
140
|
});
|