ripple 0.3.72 → 0.3.74
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 +66 -0
- package/package.json +3 -3
- package/src/jsx-runtime.d.ts +2 -8
- package/src/runtime/index-client.js +3 -13
- package/src/runtime/internal/client/blocks.js +3 -25
- package/src/runtime/internal/client/for.js +80 -5
- package/src/runtime/internal/client/index.js +0 -2
- package/src/runtime/internal/client/types.d.ts +0 -10
- package/tests/client/__snapshots__/computed-properties.test.tsrx.snap +8 -0
- package/tests/client/__snapshots__/for.test.tsrx.snap +22 -0
- package/tests/client/__snapshots__/html.test.tsrx.snap +4 -0
- package/tests/client/array/array.copy-within.test.tsrx +19 -19
- package/tests/client/array/array.derived.test.tsrx +97 -109
- package/tests/client/array/array.iteration.test.tsrx +28 -28
- package/tests/client/array/array.mutations.test.tsrx +68 -68
- package/tests/client/array/array.static.test.tsrx +82 -92
- package/tests/client/array/array.to-methods.test.tsrx +15 -15
- package/tests/client/async-suspend.test.tsrx +180 -179
- package/tests/client/basic/__snapshots__/basic.attributes.test.tsrx.snap +2 -0
- package/tests/client/basic/__snapshots__/basic.rendering.test.tsrx.snap +4 -0
- package/tests/client/basic/basic.attributes.test.tsrx +273 -317
- package/tests/client/basic/basic.collections.test.tsrx +55 -61
- package/tests/client/basic/basic.components.test.tsrx +196 -218
- package/tests/client/basic/basic.errors.test.tsrx +70 -76
- package/tests/client/basic/basic.events.test.tsrx +80 -85
- package/tests/client/basic/basic.get-set.test.tsrx +54 -64
- package/tests/client/basic/basic.hmr.test.tsrx +15 -19
- package/tests/client/basic/basic.reactivity.test.tsrx +121 -135
- package/tests/client/basic/basic.rendering.test.tsrx +273 -178
- package/tests/client/basic/basic.utilities.test.tsrx +8 -10
- package/tests/client/boundaries.test.tsrx +18 -18
- package/tests/client/compiler/compiler.assignments.test.tsrx +77 -76
- package/tests/client/compiler/compiler.attributes.test.tsrx +18 -14
- package/tests/client/compiler/compiler.basic.test.tsrx +357 -288
- package/tests/client/compiler/compiler.regex.test.tsrx +40 -44
- package/tests/client/compiler/compiler.tracked-access.test.tsrx +57 -38
- package/tests/client/compiler/compiler.try-in-function.test.tsrx +16 -16
- package/tests/client/compiler/compiler.typescript.test.tsrx +4 -3
- package/tests/client/composite/composite.dynamic-components.test.tsrx +41 -44
- package/tests/client/composite/composite.generics.test.tsrx +165 -167
- package/tests/client/composite/composite.props.test.tsrx +66 -74
- package/tests/client/composite/composite.reactivity.test.tsrx +132 -166
- package/tests/client/composite/composite.render.test.tsrx +92 -101
- package/tests/client/computed-properties.test.tsrx +14 -18
- package/tests/client/context.test.tsrx +14 -18
- package/tests/client/css/global-additional-cases.test.tsrx +491 -437
- package/tests/client/css/global-advanced-selectors.test.tsrx +169 -153
- package/tests/client/css/global-at-rules.test.tsrx +71 -66
- package/tests/client/css/global-basic.test.tsrx +105 -98
- package/tests/client/css/global-classes-ids.test.tsrx +128 -114
- package/tests/client/css/global-combinators.test.tsrx +83 -78
- package/tests/client/css/global-complex-nesting.test.tsrx +134 -120
- package/tests/client/css/global-edge-cases.test.tsrx +138 -120
- package/tests/client/css/global-keyframes.test.tsrx +108 -96
- package/tests/client/css/global-nested.test.tsrx +88 -78
- package/tests/client/css/global-pseudo.test.tsrx +104 -98
- package/tests/client/css/global-scoping.test.tsrx +145 -125
- package/tests/client/css/style-identifier.test.tsrx +62 -69
- package/tests/client/date.test.tsrx +83 -83
- package/tests/client/dynamic-elements.test.tsrx +227 -283
- package/tests/client/events.test.tsrx +252 -266
- package/tests/client/for.test.tsrx +120 -127
- package/tests/client/head.test.tsrx +40 -48
- package/tests/client/html.test.tsrx +37 -49
- package/tests/client/input-value.test.tsrx +1125 -1354
- package/tests/client/lazy-array.test.tsrx +10 -16
- package/tests/client/lazy-destructuring.test.tsrx +169 -221
- package/tests/client/map.test.tsrx +39 -41
- package/tests/client/media-query.test.tsrx +15 -19
- package/tests/client/object.test.tsrx +46 -56
- package/tests/client/portal.test.tsrx +31 -37
- package/tests/client/ref.test.tsrx +173 -193
- package/tests/client/return.test.tsrx +62 -37
- package/tests/client/set.test.tsrx +33 -33
- package/tests/client/svg.test.tsrx +195 -215
- package/tests/client/switch.test.tsrx +201 -191
- package/tests/client/track-async-hydration.test.tsrx +14 -18
- package/tests/client/tracked-index-access.test.tsrx +18 -28
- package/tests/client/try.test.tsrx +494 -619
- package/tests/client/tsx.test.tsrx +286 -292
- package/tests/client/typescript-generics.test.tsrx +121 -129
- package/tests/client/url/url.derived.test.tsrx +21 -25
- package/tests/client/url/url.parsing.test.tsrx +35 -35
- package/tests/client/url/url.partial-removal.test.tsrx +32 -32
- package/tests/client/url/url.reactivity.test.tsrx +68 -72
- package/tests/client/url/url.serialization.test.tsrx +8 -8
- package/tests/client/url-search-params/url-search-params.derived.test.tsrx +21 -27
- package/tests/client/url-search-params/url-search-params.initialization.test.tsrx +16 -16
- package/tests/client/url-search-params/url-search-params.iteration.test.tsrx +37 -37
- package/tests/client/url-search-params/url-search-params.mutation.test.tsrx +56 -60
- package/tests/client/url-search-params/url-search-params.retrieval.test.tsrx +32 -34
- package/tests/client/url-search-params/url-search-params.serialization.test.tsrx +9 -9
- package/tests/client/url-search-params/url-search-params.tracked-url.test.tsrx +10 -10
- package/tests/hydration/compiled/client/basic.js +390 -319
- package/tests/hydration/compiled/client/composite.js +52 -44
- package/tests/hydration/compiled/client/for.js +734 -604
- package/tests/hydration/compiled/client/head.js +183 -103
- package/tests/hydration/compiled/client/html.js +93 -86
- package/tests/hydration/compiled/client/if-children.js +95 -71
- package/tests/hydration/compiled/client/if.js +113 -89
- package/tests/hydration/compiled/client/mixed-control-flow.js +225 -209
- package/tests/hydration/compiled/client/nested-control-flow.js +94 -98
- package/tests/hydration/compiled/client/reactivity.js +26 -24
- package/tests/hydration/compiled/client/return.js +8 -42
- package/tests/hydration/compiled/client/switch.js +208 -173
- package/tests/hydration/compiled/client/track-async-serialization.js +176 -128
- package/tests/hydration/compiled/client/try.js +29 -21
- package/tests/hydration/compiled/server/basic.js +210 -221
- package/tests/hydration/compiled/server/composite.js +13 -14
- package/tests/hydration/compiled/server/for.js +427 -444
- package/tests/hydration/compiled/server/head.js +199 -189
- package/tests/hydration/compiled/server/html.js +33 -41
- package/tests/hydration/compiled/server/if-children.js +114 -117
- package/tests/hydration/compiled/server/if.js +77 -83
- package/tests/hydration/compiled/server/mixed-control-flow.js +145 -150
- package/tests/hydration/compiled/server/nested-control-flow.js +10 -0
- package/tests/hydration/compiled/server/reactivity.js +24 -22
- package/tests/hydration/compiled/server/return.js +6 -18
- package/tests/hydration/compiled/server/switch.js +179 -176
- package/tests/hydration/compiled/server/track-async-serialization.js +88 -70
- package/tests/hydration/compiled/server/try.js +31 -35
- package/tests/hydration/components/basic.tsrx +216 -258
- package/tests/hydration/components/composite.tsrx +32 -42
- package/tests/hydration/components/events.tsrx +81 -101
- package/tests/hydration/components/for.tsrx +270 -336
- package/tests/hydration/components/head.tsrx +43 -39
- package/tests/hydration/components/hmr.tsrx +16 -22
- package/tests/hydration/components/html-in-template.tsrx +15 -21
- package/tests/hydration/components/html.tsrx +442 -526
- package/tests/hydration/components/if-children.tsrx +107 -125
- package/tests/hydration/components/if.tsrx +68 -90
- package/tests/hydration/components/mixed-control-flow.tsrx +65 -72
- package/tests/hydration/components/nested-control-flow.tsrx +202 -216
- package/tests/hydration/components/portal.tsrx +33 -41
- package/tests/hydration/components/reactivity.tsrx +26 -34
- package/tests/hydration/components/return.tsrx +4 -6
- package/tests/hydration/components/switch.tsrx +73 -78
- package/tests/hydration/components/track-async-serialization.tsrx +83 -93
- package/tests/hydration/components/try.tsrx +37 -51
- package/tests/hydration/switch.test.js +8 -8
- package/tests/server/await.test.tsrx +3 -3
- package/tests/server/basic.attributes.test.tsrx +117 -162
- package/tests/server/basic.components.test.tsrx +163 -193
- package/tests/server/basic.test.tsrx +298 -198
- package/tests/server/compiler.test.tsrx +142 -72
- package/tests/server/composite.props.test.tsrx +54 -58
- package/tests/server/composite.test.tsrx +165 -167
- package/tests/server/context.test.tsrx +13 -17
- package/tests/server/dynamic-elements.test.tsrx +103 -135
- package/tests/server/for.test.tsrx +115 -84
- package/tests/server/head.test.tsrx +31 -31
- package/tests/server/html-nesting-validation.test.tsrx +16 -8
- package/tests/server/if.test.tsrx +49 -59
- package/tests/server/lazy-destructuring.test.tsrx +288 -366
- package/tests/server/return.test.tsrx +58 -36
- package/tests/server/streaming-ssr.test.tsrx +4 -4
- package/tests/server/style-identifier.test.tsrx +58 -66
- package/tests/server/switch.test.tsrx +89 -97
- package/tests/server/track-async-serialization.test.tsrx +85 -103
- package/tests/server/try.test.tsrx +275 -360
- package/tests/utils/ref-types.test.js +72 -0
- package/tests/utils/vite-plugin-config.test.js +41 -74
- package/types/index.d.ts +1 -0
- package/src/runtime/internal/client/compat.js +0 -40
- package/tests/utils/compiler-compat-config.test.js +0 -38
|
@@ -2,18 +2,18 @@ import { RippleMap, flushSync, track } from 'ripple';
|
|
|
2
2
|
|
|
3
3
|
describe('RippleMap', () => {
|
|
4
4
|
it('handles set with update and delete operations with a reactive size var', () => {
|
|
5
|
-
function MapTest() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
function MapTest() @{
|
|
6
|
+
let map = new RippleMap([['a', 1], ['b', 2], ['c', 3]]);
|
|
7
|
+
let &[value] = track(() => map.get('a'));
|
|
8
|
+
let &[size] = track(() => map.size);
|
|
9
|
+
<>
|
|
10
10
|
<button onClick={() => map.set('d', 4)}>{'set'}</button>
|
|
11
11
|
<button onClick={() => map.delete('b')}>{'delete'}</button>
|
|
12
12
|
<button onClick={() => map.set('a', 5)}>{'update'}</button>
|
|
13
13
|
<pre>{map.get('d')}</pre>
|
|
14
14
|
<pre>{size}</pre>
|
|
15
15
|
<pre>{value}</pre>
|
|
16
|
-
|
|
16
|
+
</>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
render(MapTest);
|
|
@@ -41,12 +41,12 @@ describe('RippleMap', () => {
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('handles clear operation', () => {
|
|
44
|
-
function MapTest() {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
function MapTest() @{
|
|
45
|
+
let map = new RippleMap([['a', 1], ['b', 2], ['c', 3]]);
|
|
46
|
+
<>
|
|
47
47
|
<button onClick={() => map.clear()}>{'clear'}</button>
|
|
48
48
|
<pre>{map.size}</pre>
|
|
49
|
-
|
|
49
|
+
</>
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
render(MapTest);
|
|
@@ -60,13 +60,13 @@ describe('RippleMap', () => {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
it('handles has operation and tracks reactive $has', () => {
|
|
63
|
-
function MapTest() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
function MapTest() @{
|
|
64
|
+
let map = new RippleMap([['a', 1], ['b', 2], ['c', 3]]);
|
|
65
|
+
let &[has] = track(() => map.has('b'));
|
|
66
|
+
<>
|
|
67
67
|
<button onClick={() => map.delete('b')}>{'delete'}</button>
|
|
68
68
|
<pre>{has}</pre>
|
|
69
|
-
|
|
69
|
+
</>
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
render(MapTest);
|
|
@@ -81,17 +81,17 @@ describe('RippleMap', () => {
|
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
it('handles reactivity of keys, values, and entries', () => {
|
|
84
|
-
function MapTest() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
function MapTest() @{
|
|
85
|
+
let map = new RippleMap([['x', 10], ['y', 20]]);
|
|
86
|
+
let &[keys] = track(() => Array.from(map.keys()));
|
|
87
|
+
let &[values] = track(() => Array.from(map.values()));
|
|
88
|
+
let &[entries] = track(() => Array.from(map.entries()));
|
|
89
|
+
<>
|
|
90
90
|
<button onClick={() => map.delete('x')}>{'delete'}</button>
|
|
91
91
|
<pre>{JSON.stringify(keys)}</pre>
|
|
92
92
|
<pre>{JSON.stringify(values)}</pre>
|
|
93
93
|
<pre>{JSON.stringify(entries)}</pre>
|
|
94
|
-
|
|
94
|
+
</>
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
render(MapTest);
|
|
@@ -111,11 +111,9 @@ describe('RippleMap', () => {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it('toJSON returns correct object', () => {
|
|
114
|
-
function MapTest() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
<pre>{JSON.stringify(map)}</pre>
|
|
118
|
-
</>;
|
|
114
|
+
function MapTest() @{
|
|
115
|
+
let map = new RippleMap([['foo', 1], ['bar', 2]]);
|
|
116
|
+
<pre>{JSON.stringify(map)}</pre>
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
render(MapTest);
|
|
@@ -124,12 +122,12 @@ describe('RippleMap', () => {
|
|
|
124
122
|
});
|
|
125
123
|
|
|
126
124
|
it('creates empty RippleMap using RippleMap() shorthand syntax', () => {
|
|
127
|
-
function MapTest() {
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
function MapTest() @{
|
|
126
|
+
let map = new RippleMap();
|
|
127
|
+
<>
|
|
130
128
|
<button onClick={() => map.set('a', 1)}>{'add'}</button>
|
|
131
129
|
<pre>{map.size}</pre>
|
|
132
|
-
|
|
130
|
+
</>
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
render(MapTest);
|
|
@@ -144,14 +142,14 @@ describe('RippleMap', () => {
|
|
|
144
142
|
});
|
|
145
143
|
|
|
146
144
|
it('creates RippleMap with initial entries using RippleMap() shorthand syntax', () => {
|
|
147
|
-
function MapTest() {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
function MapTest() @{
|
|
146
|
+
let map = new RippleMap([['a', 1], ['b', 2], ['c', 3]]);
|
|
147
|
+
let &[value] = track(() => map.get('b'));
|
|
148
|
+
<>
|
|
151
149
|
<button onClick={() => map.set('b', 10)}>{'update'}</button>
|
|
152
150
|
<pre>{map.size}</pre>
|
|
153
151
|
<pre>{value}</pre>
|
|
154
|
-
|
|
152
|
+
</>
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
render(MapTest);
|
|
@@ -167,16 +165,16 @@ describe('RippleMap', () => {
|
|
|
167
165
|
});
|
|
168
166
|
|
|
169
167
|
it('handles all operations with RippleMap() shorthand syntax', () => {
|
|
170
|
-
function MapTest() {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
function MapTest() @{
|
|
169
|
+
let map = new RippleMap([['x', 100], ['y', 200]]);
|
|
170
|
+
let &[keys] = track(() => Array.from(map.keys()));
|
|
171
|
+
<>
|
|
174
172
|
<button onClick={() => map.set('z', 300)}>{'add'}</button>
|
|
175
173
|
<button onClick={() => map.delete('x')}>{'delete'}</button>
|
|
176
174
|
<button onClick={() => map.clear()}>{'clear'}</button>
|
|
177
175
|
<pre>{JSON.stringify(keys)}</pre>
|
|
178
176
|
<pre>{map.size}</pre>
|
|
179
|
-
|
|
177
|
+
</>
|
|
180
178
|
}
|
|
181
179
|
|
|
182
180
|
render(MapTest);
|
|
@@ -50,13 +50,11 @@ describe('MediaQuery', () => {
|
|
|
50
50
|
it('should be reactive if matchMedia changes', () => {
|
|
51
51
|
const media = '(min-width: 600px)';
|
|
52
52
|
|
|
53
|
-
function App() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
</div>
|
|
59
|
-
</>;
|
|
53
|
+
function App() @{
|
|
54
|
+
let &[medium] = new MediaQuery(media);
|
|
55
|
+
<div>
|
|
56
|
+
<p>{medium}</p>
|
|
57
|
+
</div>
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
render(App);
|
|
@@ -86,23 +84,21 @@ describe('MediaQuery', () => {
|
|
|
86
84
|
it('should have cleared event listeners after unmount', async () => {
|
|
87
85
|
const media = '(min-width: 600px)';
|
|
88
86
|
|
|
89
|
-
function App() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (show) {
|
|
87
|
+
function App() @{
|
|
88
|
+
let &[show] = track(true);
|
|
89
|
+
<>
|
|
90
|
+
@if (show) {
|
|
93
91
|
<Child />
|
|
94
92
|
}
|
|
95
93
|
<button onClick={() => (show = !show)}>{'Toggle Child'}</button>
|
|
96
|
-
|
|
94
|
+
</>
|
|
97
95
|
}
|
|
98
96
|
|
|
99
|
-
function Child() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
</div>
|
|
105
|
-
</>;
|
|
97
|
+
function Child() @{
|
|
98
|
+
let &[medium] = new MediaQuery(media);
|
|
99
|
+
<div>
|
|
100
|
+
<p>{medium}</p>
|
|
101
|
+
</div>
|
|
106
102
|
}
|
|
107
103
|
|
|
108
104
|
render(App);
|
|
@@ -3,19 +3,17 @@ import { TRACKED_OBJECT } from '../../src/runtime/internal/client/constants.js';
|
|
|
3
3
|
|
|
4
4
|
describe('RippleObject', () => {
|
|
5
5
|
it('makes new properties reactive', () => {
|
|
6
|
-
function ObjectTest() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
function ObjectTest() @{
|
|
7
|
+
const obj = new RippleObject({ a: -1 });
|
|
8
|
+
obj.a = 0;
|
|
9
|
+
<>
|
|
10
10
|
<pre>{obj.a}</pre>
|
|
11
11
|
<button
|
|
12
12
|
onClick={() => {
|
|
13
13
|
obj.a++;
|
|
14
14
|
}}
|
|
15
|
-
>
|
|
16
|
-
|
|
17
|
-
</button>
|
|
18
|
-
</>;
|
|
15
|
+
>{'Increment A'}</button>
|
|
16
|
+
</>
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
render(ObjectTest);
|
|
@@ -32,18 +30,16 @@ describe('RippleObject', () => {
|
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
it('makes existing object properties reactive', () => {
|
|
35
|
-
function ObjectTest() {
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
function ObjectTest() @{
|
|
34
|
+
const obj = new RippleObject({ a: 0 });
|
|
35
|
+
<>
|
|
38
36
|
<pre>{obj.a}</pre>
|
|
39
37
|
<button
|
|
40
38
|
onClick={() => {
|
|
41
39
|
obj.a++;
|
|
42
40
|
}}
|
|
43
|
-
>
|
|
44
|
-
|
|
45
|
-
</button>
|
|
46
|
-
</>;
|
|
41
|
+
>{'Increment A'}</button>
|
|
42
|
+
</>
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
render(ObjectTest);
|
|
@@ -60,12 +56,12 @@ describe('RippleObject', () => {
|
|
|
60
56
|
});
|
|
61
57
|
|
|
62
58
|
it('checks if property exists via the has trap', () => {
|
|
63
|
-
function ObjectTest() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
function ObjectTest() @{
|
|
60
|
+
const obj = new RippleObject({ a: -1, b: 1 });
|
|
61
|
+
obj.a = 0;
|
|
62
|
+
<pre>
|
|
63
|
+
{'a' in obj && 'b' in obj}
|
|
64
|
+
</pre>
|
|
69
65
|
}
|
|
70
66
|
|
|
71
67
|
render(ObjectTest);
|
|
@@ -76,18 +72,16 @@ describe('RippleObject', () => {
|
|
|
76
72
|
});
|
|
77
73
|
|
|
78
74
|
it('deletes properties via the delete trap', () => {
|
|
79
|
-
function ObjectTest() {
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
function ObjectTest() @{
|
|
76
|
+
const obj = new RippleObject<{ a?: number; b: number }>({ a: 0, b: 1 });
|
|
77
|
+
<>
|
|
82
78
|
<pre>{String(obj.a)}</pre>
|
|
83
79
|
<button
|
|
84
80
|
onClick={() => {
|
|
85
81
|
delete obj.a;
|
|
86
82
|
}}
|
|
87
|
-
>
|
|
88
|
-
|
|
89
|
-
</button>
|
|
90
|
-
</>;
|
|
83
|
+
>{'Delete A'}</button>
|
|
84
|
+
</>
|
|
91
85
|
}
|
|
92
86
|
|
|
93
87
|
render(ObjectTest);
|
|
@@ -104,18 +98,16 @@ describe('RippleObject', () => {
|
|
|
104
98
|
});
|
|
105
99
|
|
|
106
100
|
it('checks if non-existent property is reactive when added later', () => {
|
|
107
|
-
function ObjectTest() {
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
function ObjectTest() @{
|
|
102
|
+
const obj = new RippleObject<{ a?: number }>({});
|
|
103
|
+
<>
|
|
110
104
|
<pre>{String(obj.a)}</pre>
|
|
111
105
|
<button
|
|
112
106
|
onClick={() => {
|
|
113
107
|
obj.a = 1;
|
|
114
108
|
}}
|
|
115
|
-
>
|
|
116
|
-
|
|
117
|
-
</button>
|
|
118
|
-
</>;
|
|
109
|
+
>{'Add A'}</button>
|
|
110
|
+
</>
|
|
119
111
|
}
|
|
120
112
|
|
|
121
113
|
render(ObjectTest);
|
|
@@ -132,18 +124,16 @@ describe('RippleObject', () => {
|
|
|
132
124
|
});
|
|
133
125
|
|
|
134
126
|
it('checks that deeply nested objects are not proxied or reactive', () => {
|
|
135
|
-
function ObjectTest() {
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
function ObjectTest() @{
|
|
128
|
+
const obj = new RippleObject({ a: { b: 1 } });
|
|
129
|
+
<>
|
|
138
130
|
<pre>{String(obj.a.b)}</pre>
|
|
139
131
|
<button
|
|
140
132
|
onClick={() => {
|
|
141
133
|
obj.a.b++;
|
|
142
134
|
}}
|
|
143
|
-
>
|
|
144
|
-
|
|
145
|
-
</button>
|
|
146
|
-
</>;
|
|
135
|
+
>{'Increment B'}</button>
|
|
136
|
+
</>
|
|
147
137
|
}
|
|
148
138
|
|
|
149
139
|
render(ObjectTest);
|
|
@@ -161,30 +151,30 @@ describe('RippleObject', () => {
|
|
|
161
151
|
});
|
|
162
152
|
|
|
163
153
|
it('checks if TRACKED_OBJECT symbol is present on RippleObject instances', () => {
|
|
164
|
-
function ObjectTest() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
expect(obj[TRACKED_OBJECT]).toBe(true);
|
|
169
|
-
</>;
|
|
154
|
+
function ObjectTest() @{
|
|
155
|
+
const obj = new RippleObject({ a: 0 });
|
|
156
|
+
expect(TRACKED_OBJECT in obj).toBe(true);
|
|
157
|
+
<pre>{'done'}</pre>
|
|
170
158
|
}
|
|
159
|
+
|
|
160
|
+
render(ObjectTest);
|
|
171
161
|
});
|
|
172
162
|
|
|
173
163
|
it('uses the hash syntax for creating RippleObject', () => {
|
|
174
|
-
function ObjectTest() {
|
|
175
|
-
|
|
176
|
-
|
|
164
|
+
function ObjectTest() @{
|
|
165
|
+
const obj = new RippleObject({ a: 0, b: 1, c: { d: { e: 8 } } });
|
|
166
|
+
<>
|
|
177
167
|
<pre>{obj.a}</pre>
|
|
178
|
-
<pre>
|
|
168
|
+
<pre>
|
|
169
|
+
{TRACKED_OBJECT in obj}
|
|
170
|
+
</pre>
|
|
179
171
|
<pre>{JSON.stringify(obj)}</pre>
|
|
180
172
|
<button
|
|
181
173
|
onClick={() => {
|
|
182
174
|
obj.a++;
|
|
183
175
|
}}
|
|
184
|
-
>
|
|
185
|
-
|
|
186
|
-
</button>
|
|
187
|
-
</>;
|
|
176
|
+
>{'Increment A'}</button>
|
|
177
|
+
</>
|
|
188
178
|
}
|
|
189
179
|
|
|
190
180
|
render(ObjectTest);
|
|
@@ -11,12 +11,10 @@ describe('Portal', () => {
|
|
|
11
11
|
const target = document.createElement('div');
|
|
12
12
|
document.body.appendChild(target);
|
|
13
13
|
|
|
14
|
-
function TestPortal() {
|
|
15
|
-
|
|
16
|
-
<Portal
|
|
17
|
-
|
|
18
|
-
</Portal>
|
|
19
|
-
</>;
|
|
14
|
+
function TestPortal() @{
|
|
15
|
+
<Portal {target}>
|
|
16
|
+
<div class="test-portal">{'Portal works!'}</div>
|
|
17
|
+
</Portal>
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
render(TestPortal);
|
|
@@ -30,12 +28,10 @@ describe('Portal', () => {
|
|
|
30
28
|
});
|
|
31
29
|
|
|
32
30
|
it('renders portal content to document.body', () => {
|
|
33
|
-
function TestPortal() {
|
|
34
|
-
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
</Portal>
|
|
38
|
-
</>;
|
|
31
|
+
function TestPortal() @{
|
|
32
|
+
<Portal target={document.body}>
|
|
33
|
+
<div class="test-portal">{'In document.body!'}</div>
|
|
34
|
+
</Portal>
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
render(TestPortal);
|
|
@@ -49,16 +45,16 @@ describe('Portal', () => {
|
|
|
49
45
|
});
|
|
50
46
|
|
|
51
47
|
it('cleans up portal content when destroyed via conditional rendering', () => {
|
|
52
|
-
function TestPortal() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (open) {
|
|
48
|
+
function TestPortal() @{
|
|
49
|
+
let &[open] = track(true);
|
|
50
|
+
<>
|
|
51
|
+
@if (open) {
|
|
56
52
|
<Portal target={document.body}>
|
|
57
53
|
<div class="test-portal">{'Conditional content'}</div>
|
|
58
54
|
</Portal>
|
|
59
55
|
}
|
|
60
56
|
<button onClick={() => (open = false)}>{'Close'}</button>
|
|
61
|
-
|
|
57
|
+
</>
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
render(TestPortal);
|
|
@@ -75,10 +71,10 @@ describe('Portal', () => {
|
|
|
75
71
|
});
|
|
76
72
|
|
|
77
73
|
it('opens and closes portal via conditional rendering', () => {
|
|
78
|
-
function TestPortal() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (open) {
|
|
74
|
+
function TestPortal() @{
|
|
75
|
+
let &[open] = track(false);
|
|
76
|
+
<>
|
|
77
|
+
@if (open) {
|
|
82
78
|
<Portal target={document.body}>
|
|
83
79
|
<div class="test-portal">
|
|
84
80
|
{'Content'}
|
|
@@ -86,10 +82,10 @@ describe('Portal', () => {
|
|
|
86
82
|
</div>
|
|
87
83
|
</Portal>
|
|
88
84
|
}
|
|
89
|
-
if (!open) {
|
|
85
|
+
@if (!open) {
|
|
90
86
|
<button onClick={() => (open = true)}>{'Open'}</button>
|
|
91
87
|
}
|
|
92
|
-
|
|
88
|
+
</>
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
render(TestPortal);
|
|
@@ -117,15 +113,15 @@ describe('Portal', () => {
|
|
|
117
113
|
document.body.appendChild(target1);
|
|
118
114
|
document.body.appendChild(target2);
|
|
119
115
|
|
|
120
|
-
function TestMultiPortal() {
|
|
121
|
-
|
|
116
|
+
function TestMultiPortal() @{
|
|
117
|
+
<>
|
|
122
118
|
<Portal target={target1}>
|
|
123
119
|
<div class="test-portal">{'Portal 1 content'}</div>
|
|
124
120
|
</Portal>
|
|
125
121
|
<Portal target={target2}>
|
|
126
122
|
<div class="test-portal">{'Portal 2 content'}</div>
|
|
127
123
|
</Portal>
|
|
128
|
-
|
|
124
|
+
</>
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
render(TestMultiPortal);
|
|
@@ -142,17 +138,15 @@ describe('Portal', () => {
|
|
|
142
138
|
});
|
|
143
139
|
|
|
144
140
|
it('handles portal with reactive content', () => {
|
|
145
|
-
function TestReactivePortal() {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
<
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
</Portal>
|
|
155
|
-
</>;
|
|
141
|
+
function TestReactivePortal() @{
|
|
142
|
+
let &[count] = track(0);
|
|
143
|
+
<Portal target={document.body}>
|
|
144
|
+
<div class="test-portal">
|
|
145
|
+
{'Count: '}
|
|
146
|
+
{String(count)}
|
|
147
|
+
<button onClick={() => count++}>{'Increment'}</button>
|
|
148
|
+
</div>
|
|
149
|
+
</Portal>
|
|
156
150
|
}
|
|
157
151
|
|
|
158
152
|
render(TestReactivePortal);
|