ripple 0.3.7 → 0.3.8
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 +7 -0
- package/package.json +2 -2
- package/src/compiler/phases/1-parse/index.js +37 -194
- package/src/compiler/phases/2-analyze/index.js +63 -18
- package/src/compiler/phases/3-transform/client/index.js +19 -3
- package/src/compiler/phases/3-transform/server/index.js +16 -24
- package/src/compiler/types/parse.d.ts +0 -8
- package/src/runtime/internal/client/composite.js +2 -2
- 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 +18 -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 +68 -68
- 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 +16 -16
- 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 +11 -11
- package/tests/client/composite/composite.reactivity.test.ripple +43 -43
- 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 +42 -42
- 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 +71 -16
- 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/composite.props.test.ripple +9 -9
- package/tests/server/dynamic-elements.test.ripple +13 -12
- package/tests/server/head.test.ripple +11 -11
- package/tests/server/lazy-destructuring.test.ripple +27 -4
|
@@ -4,22 +4,22 @@ import { compile } from 'ripple/compiler';
|
|
|
4
4
|
describe('basic client > errors', () => {
|
|
5
5
|
it('renders with error handling simulation', () => {
|
|
6
6
|
component Basic() {
|
|
7
|
-
let hasError = track(false);
|
|
8
|
-
let errorMessage = track('');
|
|
7
|
+
let &[hasError] = track(false);
|
|
8
|
+
let &[errorMessage] = track('');
|
|
9
9
|
|
|
10
10
|
const triggerError = () => {
|
|
11
11
|
try {
|
|
12
12
|
throw new Error('Test error');
|
|
13
13
|
} catch (e) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
hasError = true;
|
|
15
|
+
errorMessage = (e as Error).message;
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
<div>
|
|
20
20
|
<button onClick={triggerError}>{'Trigger Error'}</button>
|
|
21
|
-
if (
|
|
22
|
-
<div class="error">{'Error caught: ' +
|
|
21
|
+
if (hasError) {
|
|
22
|
+
<div class="error">{'Error caught: ' + errorMessage}</div>
|
|
23
23
|
} else {
|
|
24
24
|
<div class="success">{'No error'}</div>
|
|
25
25
|
}
|
|
@@ -91,17 +91,17 @@ describe('basic client > errors', () => {
|
|
|
91
91
|
|
|
92
92
|
it('errors on mutating tracked value inside computed track() evaluation', () => {
|
|
93
93
|
component Basic() {
|
|
94
|
-
let count = track(0);
|
|
94
|
+
let &[count] = track(0);
|
|
95
95
|
|
|
96
|
-
const doubled = track(() => {
|
|
96
|
+
const &[doubled] = track(() => {
|
|
97
97
|
try {
|
|
98
|
-
|
|
98
|
+
count *= 2;
|
|
99
99
|
} catch (e) {
|
|
100
100
|
error = (e as Error).message;
|
|
101
101
|
}
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
<p>{
|
|
104
|
+
<p>{doubled}</p>
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
render(Basic);
|
|
@@ -113,19 +113,19 @@ describe('basic client > errors', () => {
|
|
|
113
113
|
|
|
114
114
|
it('errors on mutating tracked value inside untrack() in computed track() evaluation', () => {
|
|
115
115
|
component Basic() {
|
|
116
|
-
let count = track(0);
|
|
116
|
+
let &[count] = track(0);
|
|
117
117
|
|
|
118
|
-
const doubled = track(() => {
|
|
118
|
+
const &[doubled] = track(() => {
|
|
119
119
|
try {
|
|
120
120
|
untrack(() => {
|
|
121
|
-
|
|
121
|
+
count *= 2;
|
|
122
122
|
});
|
|
123
123
|
} catch (e) {
|
|
124
124
|
error = (e as Error).message;
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
-
<p>{
|
|
128
|
+
<p>{doubled}</p>
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
render(Basic);
|
|
@@ -137,18 +137,18 @@ describe('basic client > errors', () => {
|
|
|
137
137
|
|
|
138
138
|
it('errors on mutating a tracked variable in track() getter', () => {
|
|
139
139
|
component Basic() {
|
|
140
|
-
let count = track(0);
|
|
140
|
+
let &[count] = track(0);
|
|
141
141
|
|
|
142
|
-
const doubled = track(0, (value) => {
|
|
142
|
+
const &[doubled] = track(0, (value) => {
|
|
143
143
|
try {
|
|
144
|
-
|
|
144
|
+
count += 1;
|
|
145
145
|
} catch (e) {
|
|
146
146
|
error = (e as Error).message;
|
|
147
147
|
}
|
|
148
148
|
return value;
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
<p>{
|
|
151
|
+
<p>{doubled}</p>
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
render(Basic);
|
|
@@ -4,21 +4,21 @@ import { flushSync, track } from 'ripple';
|
|
|
4
4
|
describe('basic client > events', () => {
|
|
5
5
|
it('renders with different event types', () => {
|
|
6
6
|
component Basic() {
|
|
7
|
-
let focusCount = track(0);
|
|
8
|
-
let clickCount = track(0);
|
|
7
|
+
let &[focusCount] = track(0);
|
|
8
|
+
let &[clickCount] = track(0);
|
|
9
9
|
|
|
10
10
|
<button
|
|
11
11
|
onFocus={() => {
|
|
12
|
-
|
|
12
|
+
focusCount++;
|
|
13
13
|
}}
|
|
14
14
|
onClick={() => {
|
|
15
|
-
|
|
15
|
+
clickCount++;
|
|
16
16
|
}}
|
|
17
17
|
>
|
|
18
18
|
{'Test Button'}
|
|
19
19
|
</button>
|
|
20
|
-
<div class="focus-count">{
|
|
21
|
-
<div class="click-count">{
|
|
20
|
+
<div class="focus-count">{focusCount}</div>
|
|
21
|
+
<div class="click-count">{clickCount}</div>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
render(Basic);
|
|
@@ -38,26 +38,26 @@ describe('basic client > events', () => {
|
|
|
38
38
|
|
|
39
39
|
it('renders with capture events', () => {
|
|
40
40
|
component Basic() {
|
|
41
|
-
let captureClicks = track(0);
|
|
42
|
-
let bubbleClicks = track(0);
|
|
41
|
+
let &[captureClicks] = track(0);
|
|
42
|
+
let &[bubbleClicks] = track(0);
|
|
43
43
|
|
|
44
44
|
<div
|
|
45
45
|
onClick={{
|
|
46
46
|
handleEvent: () => {
|
|
47
|
-
|
|
47
|
+
captureClicks++;
|
|
48
48
|
},
|
|
49
49
|
capture: true,
|
|
50
50
|
}}
|
|
51
51
|
>
|
|
52
52
|
<button
|
|
53
53
|
onClick={() => {
|
|
54
|
-
|
|
54
|
+
bubbleClicks++;
|
|
55
55
|
}}
|
|
56
56
|
>
|
|
57
57
|
{'Click me'}
|
|
58
58
|
</button>
|
|
59
|
-
<div class="capture-count">{
|
|
60
|
-
<div class="bubble-count">{
|
|
59
|
+
<div class="capture-count">{captureClicks}</div>
|
|
60
|
+
<div class="bubble-count">{bubbleClicks}</div>
|
|
61
61
|
</div>
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -76,23 +76,23 @@ describe('basic client > events', () => {
|
|
|
76
76
|
|
|
77
77
|
it('renders with event listeners in spread props', () => {
|
|
78
78
|
component Basic() {
|
|
79
|
-
let count = track(0);
|
|
79
|
+
let &[count] = track(0);
|
|
80
80
|
|
|
81
81
|
const minus = {
|
|
82
82
|
onClick() {
|
|
83
|
-
|
|
83
|
+
count--;
|
|
84
84
|
},
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
const plus = {
|
|
88
88
|
onClick() {
|
|
89
|
-
|
|
89
|
+
count++;
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
<div>
|
|
94
94
|
<button {...minus} class="minus">{'-'}</button>
|
|
95
|
-
<span class="count">{
|
|
95
|
+
<span class="count">{count}</span>
|
|
96
96
|
<button {...plus} class="plus">{'+'}</button>
|
|
97
97
|
</div>
|
|
98
98
|
}
|
|
@@ -125,24 +125,24 @@ describe('basic client > events', () => {
|
|
|
125
125
|
|
|
126
126
|
it('handles both delegated and non-delegated events in spread props', () => {
|
|
127
127
|
component Basic() {
|
|
128
|
-
let clickCount = track(0);
|
|
129
|
-
let focusCount = track(0);
|
|
128
|
+
let &[clickCount] = track(0);
|
|
129
|
+
let &[focusCount] = track(0);
|
|
130
130
|
|
|
131
131
|
const mixedHandler = {
|
|
132
132
|
onClick() {
|
|
133
133
|
// Delegated event
|
|
134
|
-
|
|
134
|
+
clickCount++;
|
|
135
135
|
},
|
|
136
136
|
onFocus() {
|
|
137
137
|
// Non-delegated event
|
|
138
|
-
|
|
138
|
+
focusCount++;
|
|
139
139
|
},
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
<div>
|
|
143
143
|
<button {...mixedHandler} class="mixed-button">{'Test'}</button>
|
|
144
|
-
<span class="click-count">{
|
|
145
|
-
<span class="focus-count">{
|
|
144
|
+
<span class="click-count">{clickCount}</span>
|
|
145
|
+
<span class="focus-count">{focusCount}</span>
|
|
146
146
|
</div>
|
|
147
147
|
}
|
|
148
148
|
|
|
@@ -168,31 +168,31 @@ describe('basic client > events', () => {
|
|
|
168
168
|
|
|
169
169
|
it('renders with complex event handling and state updates', () => {
|
|
170
170
|
component Basic() {
|
|
171
|
-
let counter = track(0);
|
|
172
|
-
let history = track<string[]>([]);
|
|
173
|
-
let isEven = track(true);
|
|
171
|
+
let &[counter] = track(0);
|
|
172
|
+
let &[history] = track<string[]>([]);
|
|
173
|
+
let &[isEven] = track(true);
|
|
174
174
|
|
|
175
175
|
const handleIncrement = () => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
counter++;
|
|
177
|
+
history = [...history, `Inc to ${counter}`];
|
|
178
|
+
isEven = counter % 2 === 0;
|
|
179
179
|
};
|
|
180
180
|
|
|
181
181
|
const handleDecrement = () => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
counter--;
|
|
183
|
+
history = [...history, `Dec to ${counter}`];
|
|
184
|
+
isEven = counter % 2 === 0;
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
const handleReset = () => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
counter = 0;
|
|
189
|
+
history = [...history, 'Reset'];
|
|
190
|
+
isEven = true;
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
<div class="counter">{
|
|
194
|
-
<div class="parity">{
|
|
195
|
-
<div class="history-count">{
|
|
193
|
+
<div class="counter">{counter}</div>
|
|
194
|
+
<div class="parity">{isEven ? 'Even' : 'Odd'}</div>
|
|
195
|
+
<div class="history-count">{history.length}</div>
|
|
196
196
|
|
|
197
197
|
<button class="inc-btn" onClick={handleIncrement}>{'+'}</button>
|
|
198
198
|
<button class="dec-btn" onClick={handleDecrement}>{'-'}</button>
|
|
@@ -16,10 +16,10 @@ describe('basic client > get/set functions', () => {
|
|
|
16
16
|
|
|
17
17
|
it('gets tracked value after mutation', () => {
|
|
18
18
|
component Test() {
|
|
19
|
-
let count = track(0);
|
|
19
|
+
let &[count] = track(0);
|
|
20
20
|
|
|
21
21
|
<p>{get(count)}</p>
|
|
22
|
-
<button onClick={() =>
|
|
22
|
+
<button onClick={() => count++}>{'increment'}</button>
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
render(Test);
|
|
@@ -36,14 +36,14 @@ describe('basic client > get/set functions', () => {
|
|
|
36
36
|
|
|
37
37
|
it('gets tracked value after multiple mutations', () => {
|
|
38
38
|
component Test() {
|
|
39
|
-
let count = track(0);
|
|
39
|
+
let &[count] = track(0);
|
|
40
40
|
|
|
41
41
|
<p>{get(count)}</p>
|
|
42
42
|
<button
|
|
43
43
|
onClick={() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
count++;
|
|
45
|
+
count++;
|
|
46
|
+
count++;
|
|
47
47
|
}}
|
|
48
48
|
>
|
|
49
49
|
{'increment'}
|
|
@@ -9,7 +9,7 @@ describe('basic client > reactivity', () => {
|
|
|
9
9
|
count: track(0),
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
<span>{obj
|
|
12
|
+
<span>{obj.count.value}</span>
|
|
13
13
|
</div>
|
|
14
14
|
<div>
|
|
15
15
|
let b = {
|
|
@@ -18,15 +18,15 @@ describe('basic client > reactivity', () => {
|
|
|
18
18
|
|
|
19
19
|
<button
|
|
20
20
|
onClick={() => {
|
|
21
|
-
b
|
|
21
|
+
b.count.value--;
|
|
22
22
|
}}
|
|
23
23
|
>
|
|
24
24
|
{'-'}
|
|
25
25
|
</button>
|
|
26
|
-
<span class="count">{b
|
|
26
|
+
<span class="count">{b.count.value}</span>
|
|
27
27
|
<button
|
|
28
28
|
onClick={() => {
|
|
29
|
-
b
|
|
29
|
+
b.count.value++;
|
|
30
30
|
}}
|
|
31
31
|
>
|
|
32
32
|
{'+'}
|
|
@@ -57,7 +57,7 @@ describe('basic client > reactivity', () => {
|
|
|
57
57
|
count: track(0),
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
<span>{obj
|
|
60
|
+
<span>{obj[count].value}</span>
|
|
61
61
|
</div>
|
|
62
62
|
<div>
|
|
63
63
|
let b = {
|
|
@@ -66,15 +66,15 @@ describe('basic client > reactivity', () => {
|
|
|
66
66
|
|
|
67
67
|
<button
|
|
68
68
|
onClick={() => {
|
|
69
|
-
b
|
|
69
|
+
b[count].value--;
|
|
70
70
|
}}
|
|
71
71
|
>
|
|
72
72
|
{'-'}
|
|
73
73
|
</button>
|
|
74
|
-
<span class="count">{b
|
|
74
|
+
<span class="count">{b[count].value}</span>
|
|
75
75
|
<button
|
|
76
76
|
onClick={() => {
|
|
77
|
-
b
|
|
77
|
+
b[count].value++;
|
|
78
78
|
}}
|
|
79
79
|
>
|
|
80
80
|
{'+'}
|
|
@@ -98,14 +98,14 @@ describe('basic client > reactivity', () => {
|
|
|
98
98
|
|
|
99
99
|
it('renders with computed reactive state', () => {
|
|
100
100
|
component Basic() {
|
|
101
|
-
let count = track(5);
|
|
101
|
+
let &[count] = track(5);
|
|
102
102
|
|
|
103
|
-
<div class="count">{
|
|
104
|
-
<div class="doubled">{
|
|
105
|
-
<div class="is-even">{
|
|
103
|
+
<div class="count">{count}</div>
|
|
104
|
+
<div class="doubled">{count * 2}</div>
|
|
105
|
+
<div class="is-even">{count % 2 === 0 ? 'Even' : 'Odd'}</div>
|
|
106
106
|
<button
|
|
107
107
|
onClick={() => {
|
|
108
|
-
|
|
108
|
+
count++;
|
|
109
109
|
}}
|
|
110
110
|
>
|
|
111
111
|
{'Increment'}
|
|
@@ -139,43 +139,43 @@ describe('basic client > reactivity', () => {
|
|
|
139
139
|
let second = track(0);
|
|
140
140
|
const arr = [first, second];
|
|
141
141
|
|
|
142
|
-
const total = track(() => arr.reduce((a, b) => a +
|
|
142
|
+
const total = track(() => arr.reduce((a, b) => a + b.value, 0));
|
|
143
143
|
|
|
144
144
|
<button
|
|
145
145
|
onClick={() => {
|
|
146
|
-
|
|
146
|
+
first.value++;
|
|
147
147
|
}}
|
|
148
148
|
>
|
|
149
|
-
{'first:' +
|
|
149
|
+
{'first:' + first.value}
|
|
150
150
|
</button>
|
|
151
151
|
<button
|
|
152
152
|
onClick={() => {
|
|
153
|
-
|
|
153
|
+
second.value++;
|
|
154
154
|
}}
|
|
155
155
|
>
|
|
156
|
-
{'second: ' +
|
|
156
|
+
{'second: ' + second.value}
|
|
157
157
|
</button>
|
|
158
158
|
|
|
159
159
|
effect(() => {
|
|
160
160
|
let _arr: number[] = [];
|
|
161
161
|
|
|
162
162
|
arr.forEach((item) => {
|
|
163
|
-
_arr.push(
|
|
163
|
+
_arr.push(item.value);
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
logs.push(_arr.join(', '));
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
effect(() => {
|
|
170
|
-
if (arr.map((a) =>
|
|
170
|
+
if (arr.map((a) => a.value).includes(1)) {
|
|
171
171
|
logs.push('arr includes 1');
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
<div>{'Sum: ' +
|
|
176
|
-
<div>{'Comma Separated: ' + arr.map((a) =>
|
|
177
|
-
<div>{'Number to string: ' + arr.map((a) => String(
|
|
178
|
-
<div>{'Even numbers: ' + arr.map((a) =>
|
|
175
|
+
<div>{'Sum: ' + total.value}</div>
|
|
176
|
+
<div>{'Comma Separated: ' + arr.map((a) => a.value).join(', ')}</div>
|
|
177
|
+
<div>{'Number to string: ' + arr.map((a) => String(a.value))}</div>
|
|
178
|
+
<div>{'Even numbers: ' + arr.map((a) => a.value).filter((a) => a % 2 === 0)}</div>
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
render(App);
|
|
@@ -211,12 +211,12 @@ describe('basic client > reactivity', () => {
|
|
|
211
211
|
|
|
212
212
|
it('uses track get and set where both mutate value', () => {
|
|
213
213
|
component App() {
|
|
214
|
-
let count = track(0, (v) => v + 1, (v) => v * 2);
|
|
214
|
+
let &[count] = track(0, (v) => v + 1, (v) => v * 2);
|
|
215
215
|
|
|
216
|
-
<div class="count">{
|
|
216
|
+
<div class="count">{count}</div>
|
|
217
217
|
<button
|
|
218
218
|
onClick={() => {
|
|
219
|
-
|
|
219
|
+
count++;
|
|
220
220
|
}}
|
|
221
221
|
>
|
|
222
222
|
{'Increment'}
|
|
@@ -237,12 +237,12 @@ describe('basic client > reactivity', () => {
|
|
|
237
237
|
|
|
238
238
|
it('uses track get and set where set only mutates value', () => {
|
|
239
239
|
component App() {
|
|
240
|
-
let count = track(1, (v) => v, (v) => v * 2);
|
|
240
|
+
let &[count] = track(1, (v) => v, (v) => v * 2);
|
|
241
241
|
|
|
242
|
-
<div class="count">{
|
|
242
|
+
<div class="count">{count}</div>
|
|
243
243
|
<button
|
|
244
244
|
onClick={() => {
|
|
245
|
-
|
|
245
|
+
count++;
|
|
246
246
|
}}
|
|
247
247
|
>
|
|
248
248
|
{'Increment'}
|
|
@@ -263,12 +263,12 @@ describe('basic client > reactivity', () => {
|
|
|
263
263
|
|
|
264
264
|
it('uses track get and set where get only mutates value', () => {
|
|
265
265
|
component App() {
|
|
266
|
-
let count = track(0, (v) => v + 1, (v) => v);
|
|
266
|
+
let &[count] = track(0, (v) => v + 1, (v) => v);
|
|
267
267
|
|
|
268
|
-
<div class="count">{
|
|
268
|
+
<div class="count">{count}</div>
|
|
269
269
|
<button
|
|
270
270
|
onClick={() => {
|
|
271
|
-
|
|
271
|
+
count++;
|
|
272
272
|
}}
|
|
273
273
|
>
|
|
274
274
|
{'Increment'}
|
|
@@ -291,14 +291,14 @@ describe('basic client > reactivity', () => {
|
|
|
291
291
|
let logs: number[] = [];
|
|
292
292
|
|
|
293
293
|
component App() {
|
|
294
|
-
let count = track(0, (v) => v, (next, prev) => {
|
|
294
|
+
let &[count] = track(0, (v) => v, (next, prev) => {
|
|
295
295
|
logs.push(prev, next);
|
|
296
296
|
return next;
|
|
297
297
|
});
|
|
298
298
|
|
|
299
299
|
<button
|
|
300
300
|
onClick={() => {
|
|
301
|
-
|
|
301
|
+
count++;
|
|
302
302
|
}}
|
|
303
303
|
>
|
|
304
304
|
{'Increment'}
|
|
@@ -316,14 +316,14 @@ describe('basic client > reactivity', () => {
|
|
|
316
316
|
|
|
317
317
|
it('doesn\'t error on mutating a tracked variable in track() setter', () => {
|
|
318
318
|
component Basic() {
|
|
319
|
-
let count = track(0);
|
|
319
|
+
let &[count] = track(0);
|
|
320
320
|
|
|
321
|
-
const doubled = track(0, undefined, (value) => {
|
|
322
|
-
|
|
321
|
+
const &[doubled] = track(0, undefined, (value) => {
|
|
322
|
+
count += value;
|
|
323
323
|
return value;
|
|
324
324
|
});
|
|
325
325
|
|
|
326
|
-
<p>{
|
|
326
|
+
<p>{doubled}</p>
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
render(Basic);
|
|
@@ -335,10 +335,10 @@ describe('basic client > reactivity', () => {
|
|
|
335
335
|
let state: { count?: number } = {};
|
|
336
336
|
|
|
337
337
|
component Basic() {
|
|
338
|
-
let count = track(0);
|
|
338
|
+
let &[count] = track(0);
|
|
339
339
|
|
|
340
340
|
effect(() => {
|
|
341
|
-
state.count =
|
|
341
|
+
state.count = count;
|
|
342
342
|
});
|
|
343
343
|
}
|
|
344
344
|
|
|
@@ -359,16 +359,16 @@ describe('basic client > reactivity', () => {
|
|
|
359
359
|
} = {};
|
|
360
360
|
|
|
361
361
|
component Basic() {
|
|
362
|
-
let count = track(5);
|
|
362
|
+
let &[count] = track(5);
|
|
363
363
|
|
|
364
364
|
effect(() => {
|
|
365
365
|
untrack(() => {
|
|
366
|
-
state.initialValue =
|
|
367
|
-
state.preIncrement =
|
|
368
|
-
state.postIncrement =
|
|
369
|
-
state.preDecrement =
|
|
370
|
-
state.postDecrement =
|
|
371
|
-
state.finalValue =
|
|
366
|
+
state.initialValue = count;
|
|
367
|
+
state.preIncrement = ++count;
|
|
368
|
+
state.postIncrement = count++;
|
|
369
|
+
state.preDecrement = --count;
|
|
370
|
+
state.postDecrement = count--;
|
|
371
|
+
state.finalValue = count;
|
|
372
372
|
});
|
|
373
373
|
});
|
|
374
374
|
}
|
|
@@ -387,15 +387,15 @@ describe('basic client > reactivity', () => {
|
|
|
387
387
|
describe('track/trackSplit APIs', () => {
|
|
388
388
|
it('errors on invalid value as null for track with trackSplit', () => {
|
|
389
389
|
component App() {
|
|
390
|
-
let message = track('');
|
|
390
|
+
let &[message] = track('');
|
|
391
391
|
|
|
392
392
|
try {
|
|
393
393
|
const [a, b, rest] = trackSplit(null, ['a', 'b']);
|
|
394
394
|
} catch (e) {
|
|
395
|
-
|
|
395
|
+
message = (e as Error).message;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
<pre>{
|
|
398
|
+
<pre>{message}</pre>
|
|
399
399
|
}
|
|
400
400
|
|
|
401
401
|
render(App);
|
|
@@ -406,15 +406,15 @@ describe('basic client > reactivity', () => {
|
|
|
406
406
|
|
|
407
407
|
it('errors on invalid value as array for track with trackSplit', () => {
|
|
408
408
|
component App() {
|
|
409
|
-
let message = track('');
|
|
409
|
+
let &[message] = track('');
|
|
410
410
|
|
|
411
411
|
try {
|
|
412
412
|
const [a, b, rest] = trackSplit([1, 2, 3], ['a', 'b']);
|
|
413
413
|
} catch (e) {
|
|
414
|
-
|
|
414
|
+
message = (e as Error).message;
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
-
<pre>{
|
|
417
|
+
<pre>{message}</pre>
|
|
418
418
|
}
|
|
419
419
|
|
|
420
420
|
render(App);
|
|
@@ -426,15 +426,15 @@ describe('basic client > reactivity', () => {
|
|
|
426
426
|
it('errors on invalid value as tracked for track with trackSplit', () => {
|
|
427
427
|
component App() {
|
|
428
428
|
const t = track({ a: 1, b: 2, c: 3 });
|
|
429
|
-
let message = track('');
|
|
429
|
+
let &[message] = track('');
|
|
430
430
|
|
|
431
431
|
try {
|
|
432
432
|
const [a, b, rest] = trackSplit(t, ['a', 'b']);
|
|
433
433
|
} catch (e) {
|
|
434
|
-
|
|
434
|
+
message = (e as Error).message;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
<pre>{
|
|
437
|
+
<pre>{message}</pre>
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
render(App);
|
|
@@ -447,9 +447,9 @@ describe('basic client > reactivity', () => {
|
|
|
447
447
|
component App() {
|
|
448
448
|
const [a, b, rest] = trackSplit({ a: 1, c: 1 }, ['a', 'b']);
|
|
449
449
|
|
|
450
|
-
<pre>{
|
|
451
|
-
<pre>{String(
|
|
452
|
-
<pre>{
|
|
450
|
+
<pre>{a.value}</pre>
|
|
451
|
+
<pre>{String(b.value)}</pre>
|
|
452
|
+
<pre>{rest.value.c}</pre>
|
|
453
453
|
}
|
|
454
454
|
|
|
455
455
|
render(App);
|
|
@@ -481,8 +481,8 @@ describe('basic client > reactivity', () => {
|
|
|
481
481
|
let logs: string[] = [];
|
|
482
482
|
|
|
483
483
|
component App() {
|
|
484
|
-
let count = track(0);
|
|
485
|
-
let name = track('Click Me');
|
|
484
|
+
let &[count] = track(0);
|
|
485
|
+
let &[name] = track('Click Me');
|
|
486
486
|
|
|
487
487
|
function buttonRef(el: HTMLButtonElement) {
|
|
488
488
|
logs.push('ref called');
|
|
@@ -493,14 +493,14 @@ describe('basic client > reactivity', () => {
|
|
|
493
493
|
|
|
494
494
|
<Child
|
|
495
495
|
class="my-button"
|
|
496
|
-
onClick={() =>
|
|
496
|
+
onClick={() => name === 'Click Me' ? name = 'Clicked' : name = 'Click Me'}
|
|
497
497
|
{count}
|
|
498
498
|
{ref buttonRef}
|
|
499
499
|
>
|
|
500
|
-
{
|
|
500
|
+
{name}
|
|
501
501
|
</Child>
|
|
502
502
|
|
|
503
|
-
<button onClick={() =>
|
|
503
|
+
<button onClick={() => count++}>{'Increment Count'}</button>
|
|
504
504
|
}
|
|
505
505
|
|
|
506
506
|
component Child(props: PropsWithChildren<{
|
|
@@ -510,12 +510,12 @@ describe('basic client > reactivity', () => {
|
|
|
510
510
|
}>) {
|
|
511
511
|
const [children, count, rest] = trackSplit(props, ['children', 'count']);
|
|
512
512
|
|
|
513
|
-
if (
|
|
514
|
-
<button {
|
|
513
|
+
if (count.value < 2) {
|
|
514
|
+
<button {...rest.value}>
|
|
515
515
|
<@children />
|
|
516
516
|
</button>
|
|
517
517
|
}
|
|
518
|
-
<pre>{
|
|
518
|
+
<pre>{count.value}</pre>
|
|
519
519
|
}
|
|
520
520
|
|
|
521
521
|
render(App);
|