@usels/babel-plugin-legend-memo 0.0.1-beta.3
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/README.md +631 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +354 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +331 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +38 -0
- package/src/index.ts +51 -0
- package/src/types.ts +35 -0
- package/src/utils/addAutoImport.ts +40 -0
- package/src/utils/createAutoElement.ts +21 -0
- package/src/utils/getRootObject.ts +25 -0
- package/src/utils/hasAttributeGetCall.ts +59 -0
- package/src/utils/hasGetCall.ts +93 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/isInsideAttribute.ts +12 -0
- package/src/utils/isInsideObserverHOC.ts +24 -0
- package/src/utils/isInsideReactiveContext.ts +23 -0
- package/src/utils/wrapChildrenAsFunction.ts +113 -0
- package/src/visitors/index.ts +3 -0
- package/src/visitors/jsxElement.ts +52 -0
- package/src/visitors/jsxExpressionContainer.ts +42 -0
- package/src/visitors/program.ts +43 -0
- package/tests/attribute.test.ts +136 -0
- package/tests/basic.test.ts +184 -0
- package/tests/complex.test.ts +192 -0
- package/tests/edge-cases.test.ts +231 -0
- package/tests/options.test.ts +149 -0
- package/tests/reactive-children.test.ts +265 -0
- package/tsconfig.json +11 -0
- package/tsup.config.ts +10 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import pluginTester from 'babel-plugin-tester';
|
|
2
|
+
import plugin from '../src';
|
|
3
|
+
|
|
4
|
+
const babelOptions = {
|
|
5
|
+
plugins: ['@babel/plugin-syntax-jsx'],
|
|
6
|
+
configFile: false,
|
|
7
|
+
babelrc: false,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
pluginTester({
|
|
11
|
+
plugin,
|
|
12
|
+
pluginOptions: {},
|
|
13
|
+
babelOptions,
|
|
14
|
+
title: 'basic transforms',
|
|
15
|
+
tests: {
|
|
16
|
+
'wraps $-suffixed observable .get() in JSX child': {
|
|
17
|
+
code: `
|
|
18
|
+
function App() {
|
|
19
|
+
return <div>{count$.get()}</div>;
|
|
20
|
+
}
|
|
21
|
+
`,
|
|
22
|
+
output: `
|
|
23
|
+
import { Memo } from "@legendapp/state/react";
|
|
24
|
+
function App() {
|
|
25
|
+
return (
|
|
26
|
+
<div>
|
|
27
|
+
<Memo>{() => count$.get()}</Memo>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
`,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
'wraps chained .get() (user$.profile.name.get())': {
|
|
35
|
+
code: `
|
|
36
|
+
function App() {
|
|
37
|
+
return <span>{user$.profile.name.get()}</span>;
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
output: `
|
|
41
|
+
import { Memo } from "@legendapp/state/react";
|
|
42
|
+
function App() {
|
|
43
|
+
return (
|
|
44
|
+
<span>
|
|
45
|
+
<Memo>{() => user$.profile.name.get()}</Memo>
|
|
46
|
+
</span>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
`,
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
'wraps complex expression with multiple .get() in one Auto': {
|
|
53
|
+
code: `
|
|
54
|
+
function App() {
|
|
55
|
+
return <p>{a$.get() + " " + b$.get()}</p>;
|
|
56
|
+
}
|
|
57
|
+
`,
|
|
58
|
+
output: `
|
|
59
|
+
import { Memo } from "@legendapp/state/react";
|
|
60
|
+
function App() {
|
|
61
|
+
return (
|
|
62
|
+
<p>
|
|
63
|
+
<Memo>{() => a$.get() + " " + b$.get()}</Memo>
|
|
64
|
+
</p>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
`,
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
'wraps ternary containing .get()': {
|
|
71
|
+
code: `
|
|
72
|
+
function App() {
|
|
73
|
+
return <div>{isActive$.get() ? "ON" : "OFF"}</div>;
|
|
74
|
+
}
|
|
75
|
+
`,
|
|
76
|
+
output: `
|
|
77
|
+
import { Memo } from "@legendapp/state/react";
|
|
78
|
+
function App() {
|
|
79
|
+
return (
|
|
80
|
+
<div>
|
|
81
|
+
<Memo>{() => (isActive$.get() ? "ON" : "OFF")}</Memo>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
`,
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
'wraps logical AND conditional rendering': {
|
|
89
|
+
code: `
|
|
90
|
+
function App() {
|
|
91
|
+
return <div>{show$.get() && <Modal />}</div>;
|
|
92
|
+
}
|
|
93
|
+
`,
|
|
94
|
+
output: `
|
|
95
|
+
import { Memo } from "@legendapp/state/react";
|
|
96
|
+
function App() {
|
|
97
|
+
return (
|
|
98
|
+
<div>
|
|
99
|
+
<Memo>{() => show$.get() && <Modal />}</Memo>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
`,
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
'wraps JSX-containing expression (ternary with JSX)': {
|
|
107
|
+
code: `
|
|
108
|
+
function App() {
|
|
109
|
+
return <div>{isVisible$.get() ? <A /> : <B />}</div>;
|
|
110
|
+
}
|
|
111
|
+
`,
|
|
112
|
+
output: `
|
|
113
|
+
import { Memo } from "@legendapp/state/react";
|
|
114
|
+
function App() {
|
|
115
|
+
return (
|
|
116
|
+
<div>
|
|
117
|
+
<Memo>{() => (isVisible$.get() ? <A /> : <B />)}</Memo>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
`,
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
'wraps span child that contains .get()': {
|
|
125
|
+
code: `
|
|
126
|
+
function App() {
|
|
127
|
+
return <div><span>{name$.get()}</span><p>static</p></div>;
|
|
128
|
+
}
|
|
129
|
+
`,
|
|
130
|
+
output: `
|
|
131
|
+
import { Memo } from "@legendapp/state/react";
|
|
132
|
+
function App() {
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<span>
|
|
136
|
+
<Memo>{() => name$.get()}</Memo>
|
|
137
|
+
</span>
|
|
138
|
+
<p>static</p>
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
`,
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
'does not add import if already present': {
|
|
146
|
+
code: `
|
|
147
|
+
import { Memo } from "@legendapp/state/react";
|
|
148
|
+
function App() {
|
|
149
|
+
return <div>{count$.get()}</div>;
|
|
150
|
+
}
|
|
151
|
+
`,
|
|
152
|
+
output: `
|
|
153
|
+
import { Memo } from "@legendapp/state/react";
|
|
154
|
+
function App() {
|
|
155
|
+
return (
|
|
156
|
+
<div>
|
|
157
|
+
<Memo>{() => count$.get()}</Memo>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
`,
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
'does not add import when no transforms occur': {
|
|
165
|
+
code: `
|
|
166
|
+
function App() {
|
|
167
|
+
return <div>hello world</div>;
|
|
168
|
+
}
|
|
169
|
+
`,
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
'does not transform JSX without .get()': {
|
|
173
|
+
code: `
|
|
174
|
+
function App() {
|
|
175
|
+
return <div>{someValue}</div>;
|
|
176
|
+
}
|
|
177
|
+
`,
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
'does not transform non-JSX .get()': {
|
|
181
|
+
code: `const x = count$.get();`,
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import pluginTester from 'babel-plugin-tester';
|
|
2
|
+
import plugin from '../src';
|
|
3
|
+
|
|
4
|
+
const babelOptions = {
|
|
5
|
+
plugins: ['@babel/plugin-syntax-jsx'],
|
|
6
|
+
configFile: false,
|
|
7
|
+
babelrc: false,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
pluginTester({
|
|
11
|
+
plugin,
|
|
12
|
+
pluginOptions: {},
|
|
13
|
+
babelOptions,
|
|
14
|
+
title: 'complex use cases',
|
|
15
|
+
tests: {
|
|
16
|
+
'wraps three independent reactive siblings with separate Memos': {
|
|
17
|
+
code: `
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<div>
|
|
21
|
+
{a$.get()}
|
|
22
|
+
{b$.get()}
|
|
23
|
+
{c$.get()}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
`,
|
|
28
|
+
output: `
|
|
29
|
+
import { Memo } from "@legendapp/state/react";
|
|
30
|
+
function App() {
|
|
31
|
+
return (
|
|
32
|
+
<div>
|
|
33
|
+
<Memo>{() => a$.get()}</Memo>
|
|
34
|
+
<Memo>{() => b$.get()}</Memo>
|
|
35
|
+
<Memo>{() => c$.get()}</Memo>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
'wraps nullish coalescing expression containing .get()': {
|
|
43
|
+
code: `
|
|
44
|
+
function App() {
|
|
45
|
+
return <p>{name$.get() ?? 'Anonymous'}</p>;
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
output: `
|
|
49
|
+
import { Memo } from "@legendapp/state/react";
|
|
50
|
+
function App() {
|
|
51
|
+
return (
|
|
52
|
+
<p>
|
|
53
|
+
<Memo>{() => name$.get() ?? "Anonymous"}</Memo>
|
|
54
|
+
</p>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
`,
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
'wraps function call with .get() as argument': {
|
|
61
|
+
code: `
|
|
62
|
+
function App() {
|
|
63
|
+
return <p>{formatDate(date$.get())}</p>;
|
|
64
|
+
}
|
|
65
|
+
`,
|
|
66
|
+
output: `
|
|
67
|
+
import { Memo } from "@legendapp/state/react";
|
|
68
|
+
function App() {
|
|
69
|
+
return (
|
|
70
|
+
<p>
|
|
71
|
+
<Memo>{() => formatDate(date$.get())}</Memo>
|
|
72
|
+
</p>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
`,
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
'wraps .get() inside 3-level nested JSX': {
|
|
79
|
+
code: `
|
|
80
|
+
function App() {
|
|
81
|
+
return (
|
|
82
|
+
<div>
|
|
83
|
+
<section>
|
|
84
|
+
<p>{content$.get()}</p>
|
|
85
|
+
</section>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
90
|
+
output: `
|
|
91
|
+
import { Memo } from "@legendapp/state/react";
|
|
92
|
+
function App() {
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<section>
|
|
96
|
+
<p>
|
|
97
|
+
<Memo>{() => content$.get()}</Memo>
|
|
98
|
+
</p>
|
|
99
|
+
</section>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
`,
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
'wraps reactive expression and reactive-attribute sibling independently': {
|
|
107
|
+
code: `
|
|
108
|
+
function App() {
|
|
109
|
+
return (
|
|
110
|
+
<div>
|
|
111
|
+
{count$.get()}
|
|
112
|
+
<span className={color$.get()}>{label$.get()}</span>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
`,
|
|
117
|
+
output: `
|
|
118
|
+
import { Memo } from "@legendapp/state/react";
|
|
119
|
+
function App() {
|
|
120
|
+
return (
|
|
121
|
+
<div>
|
|
122
|
+
<Memo>{() => count$.get()}</Memo>
|
|
123
|
+
<Memo>{() => <span className={color$.get()}>{label$.get()}</span>}</Memo>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
`,
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
'wraps .get() in arrow function component body': {
|
|
131
|
+
code: `
|
|
132
|
+
const App = () => (
|
|
133
|
+
<div>{value$.get()}</div>
|
|
134
|
+
);
|
|
135
|
+
`,
|
|
136
|
+
output: `
|
|
137
|
+
import { Memo } from "@legendapp/state/react";
|
|
138
|
+
const App = () => (
|
|
139
|
+
<div>
|
|
140
|
+
<Memo>{() => value$.get()}</Memo>
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
`,
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
'wraps logical OR fallback expression with .get()': {
|
|
147
|
+
code: `
|
|
148
|
+
function App() {
|
|
149
|
+
return <p>{user$.name.get() || 'Guest'}</p>;
|
|
150
|
+
}
|
|
151
|
+
`,
|
|
152
|
+
output: `
|
|
153
|
+
import { Memo } from "@legendapp/state/react";
|
|
154
|
+
function App() {
|
|
155
|
+
return (
|
|
156
|
+
<p>
|
|
157
|
+
<Memo>{() => user$.name.get() || "Guest"}</Memo>
|
|
158
|
+
</p>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
`,
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
'wraps .map() items that have reactive attribute and content': {
|
|
165
|
+
code: `
|
|
166
|
+
function App() {
|
|
167
|
+
return (
|
|
168
|
+
<ul>
|
|
169
|
+
{items.map((item$) => (
|
|
170
|
+
<li className={item$.class.get()}>{item$.name.get()}</li>
|
|
171
|
+
))}
|
|
172
|
+
</ul>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
`,
|
|
176
|
+
output: `
|
|
177
|
+
import { Memo } from "@legendapp/state/react";
|
|
178
|
+
function App() {
|
|
179
|
+
return (
|
|
180
|
+
<ul>
|
|
181
|
+
{items.map((item$) => (
|
|
182
|
+
<Memo>
|
|
183
|
+
{() => <li className={item$.class.get()}>{item$.name.get()}</li>}
|
|
184
|
+
</Memo>
|
|
185
|
+
))}
|
|
186
|
+
</ul>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
`,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import pluginTester from 'babel-plugin-tester';
|
|
2
|
+
import plugin from '../src';
|
|
3
|
+
|
|
4
|
+
const babelOptions = {
|
|
5
|
+
plugins: ['@babel/plugin-syntax-jsx'],
|
|
6
|
+
configFile: false,
|
|
7
|
+
babelrc: false,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
pluginTester({
|
|
11
|
+
plugin,
|
|
12
|
+
pluginOptions: {},
|
|
13
|
+
babelOptions,
|
|
14
|
+
title: 'skip / edge cases',
|
|
15
|
+
tests: {
|
|
16
|
+
'does NOT wrap inside existing <Memo>': {
|
|
17
|
+
code: `
|
|
18
|
+
function App() {
|
|
19
|
+
return <Memo>{() => count$.get()}</Memo>;
|
|
20
|
+
}
|
|
21
|
+
`,
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
'does NOT wrap inside <For>': {
|
|
25
|
+
code: `
|
|
26
|
+
function App() {
|
|
27
|
+
return <For each={list$}>{(item) => <div>{item.name.get()}</div>}</For>;
|
|
28
|
+
}
|
|
29
|
+
`,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'does NOT wrap inside <Show>': {
|
|
33
|
+
code: `
|
|
34
|
+
function App() {
|
|
35
|
+
return <Show if={isVisible$}>{() => <span>{label$.get()}</span>}</Show>;
|
|
36
|
+
}
|
|
37
|
+
`,
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
'does NOT wrap inside <Memo>': {
|
|
41
|
+
code: `
|
|
42
|
+
function App() {
|
|
43
|
+
return <Memo>{() => <p>{count$.get()}</p>}</Memo>;
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
'does NOT wrap inside <Computed>': {
|
|
49
|
+
code: `
|
|
50
|
+
function App() {
|
|
51
|
+
return <Computed>{() => <p>{count$.get()}</p>}</Computed>;
|
|
52
|
+
}
|
|
53
|
+
`,
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
'does NOT wrap inside <Switch>': {
|
|
57
|
+
code: `
|
|
58
|
+
function App() {
|
|
59
|
+
return <Switch value={val$}>{count$.get()}</Switch>;
|
|
60
|
+
}
|
|
61
|
+
`,
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
'does NOT wrap inside observer() HOC': {
|
|
65
|
+
code: `const Comp = observer(() => <div>{obs$.get()}</div>);`,
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
'does NOT wrap Map.get("key") with string arg': {
|
|
69
|
+
code: `
|
|
70
|
+
function App() {
|
|
71
|
+
return <div>{map.get("key")}</div>;
|
|
72
|
+
}
|
|
73
|
+
`,
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
'does NOT wrap Map.get(variable) with variable arg': {
|
|
77
|
+
code: `
|
|
78
|
+
function App() {
|
|
79
|
+
return <div>{map.get(id)}</div>;
|
|
80
|
+
}
|
|
81
|
+
`,
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
'does NOT wrap store.get() without $ suffix (allGet:false default)': {
|
|
85
|
+
code: `
|
|
86
|
+
function App() {
|
|
87
|
+
return <div>{store.get()}</div>;
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
'does NOT wrap .get() inside onClick arrow function': {
|
|
93
|
+
code: `
|
|
94
|
+
function App() {
|
|
95
|
+
return <button onClick={() => count$.get()}>click</button>;
|
|
96
|
+
}
|
|
97
|
+
`,
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
'does NOT wrap .get() inside onChange regular function': {
|
|
101
|
+
code: `
|
|
102
|
+
function App() {
|
|
103
|
+
return <input onChange={function() { obs$.get(); }} />;
|
|
104
|
+
}
|
|
105
|
+
`,
|
|
106
|
+
output: `
|
|
107
|
+
function App() {
|
|
108
|
+
return (
|
|
109
|
+
<input
|
|
110
|
+
onChange={function () {
|
|
111
|
+
obs$.get();
|
|
112
|
+
}}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
`,
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
'does NOT wrap .get() inside useMemo callback': {
|
|
120
|
+
code: `
|
|
121
|
+
function App() {
|
|
122
|
+
return <div>{useMemo(() => obs$.get(), [])}</div>;
|
|
123
|
+
}
|
|
124
|
+
`,
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
'does NOT wrap .get() inside useCallback callback': {
|
|
128
|
+
code: `
|
|
129
|
+
function App() {
|
|
130
|
+
return <div>{useCallback(() => obs$.get(), [])}</div>;
|
|
131
|
+
}
|
|
132
|
+
`,
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
'wraps obs$?.get() optional call': {
|
|
136
|
+
code: `
|
|
137
|
+
function App() {
|
|
138
|
+
return <div>{obs$?.get()}</div>;
|
|
139
|
+
}
|
|
140
|
+
`,
|
|
141
|
+
output: `
|
|
142
|
+
import { Memo } from "@legendapp/state/react";
|
|
143
|
+
function App() {
|
|
144
|
+
return (
|
|
145
|
+
<div>
|
|
146
|
+
<Memo>{() => obs$?.get()}</Memo>
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
`,
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
'wraps obs$.items[0].get() with computed access': {
|
|
154
|
+
code: `
|
|
155
|
+
function App() {
|
|
156
|
+
return <div>{obs$.items[0].get()}</div>;
|
|
157
|
+
}
|
|
158
|
+
`,
|
|
159
|
+
output: `
|
|
160
|
+
import { Memo } from "@legendapp/state/react";
|
|
161
|
+
function App() {
|
|
162
|
+
return (
|
|
163
|
+
<div>
|
|
164
|
+
<Memo>{() => obs$.items[0].get()}</Memo>
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
`,
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
'wraps only the child with .get(), leaves siblings untouched': {
|
|
172
|
+
code: `
|
|
173
|
+
function App() {
|
|
174
|
+
return <div>{count$.get()}<p>static</p></div>;
|
|
175
|
+
}
|
|
176
|
+
`,
|
|
177
|
+
output: `
|
|
178
|
+
import { Memo } from "@legendapp/state/react";
|
|
179
|
+
function App() {
|
|
180
|
+
return (
|
|
181
|
+
<div>
|
|
182
|
+
<Memo>{() => count$.get()}</Memo>
|
|
183
|
+
<p>static</p>
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
`,
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
'wraps .get() inside Fragment': {
|
|
191
|
+
code: `
|
|
192
|
+
function App() {
|
|
193
|
+
return <>{count$.get()}<p>hello</p></>;
|
|
194
|
+
}
|
|
195
|
+
`,
|
|
196
|
+
output: `
|
|
197
|
+
import { Memo } from "@legendapp/state/react";
|
|
198
|
+
function App() {
|
|
199
|
+
return (
|
|
200
|
+
<>
|
|
201
|
+
<Memo>{() => count$.get()}</Memo>
|
|
202
|
+
<p>hello</p>
|
|
203
|
+
</>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
`,
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
'wraps .get() inside .map() callback JSX child': {
|
|
210
|
+
code: `
|
|
211
|
+
function App() {
|
|
212
|
+
return <ul>{items.map(item$ => <li>{item$.name.get()}</li>)}</ul>;
|
|
213
|
+
}
|
|
214
|
+
`,
|
|
215
|
+
output: `
|
|
216
|
+
import { Memo } from "@legendapp/state/react";
|
|
217
|
+
function App() {
|
|
218
|
+
return (
|
|
219
|
+
<ul>
|
|
220
|
+
{items.map((item$) => (
|
|
221
|
+
<li>
|
|
222
|
+
<Memo>{() => item$.name.get()}</Memo>
|
|
223
|
+
</li>
|
|
224
|
+
))}
|
|
225
|
+
</ul>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
`,
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
});
|