@snap/valdi 1.0.7 → 1.0.11

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.
Files changed (170) hide show
  1. package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/BUILD.bazel.template +16 -1
  2. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  3. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  4. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  5. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  6. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  7. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  8. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  9. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  10. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  11. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  12. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  13. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  14. package/.metadata/AGENTS.md.template +8 -274
  15. package/.metadata/skill-reference.tsx.template +8 -0
  16. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  17. package/.metadata/skill-tests-README.md.template +17 -0
  18. package/.metadata/skill.md.template +27 -0
  19. package/README.md +12 -3
  20. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  21. package/bundled-skills/registry.json +21 -0
  22. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  23. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  24. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  25. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  26. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  27. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  28. package/bundled-skills/skills/valdi-bazel/skill.md +141 -0
  29. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  30. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  31. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  32. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  33. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  34. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  35. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  37. package/bundled-skills/skills/valdi-custom-view/skill.md +64 -0
  38. package/bundled-skills/skills/valdi-inspect/skill.md +199 -0
  39. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  40. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  41. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  42. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  43. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  44. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  45. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  46. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  47. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  48. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  49. package/bundled-skills/skills/valdi-overview/skill.md +63 -0
  50. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  51. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  52. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  53. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  54. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  55. package/bundled-skills/skills/valdi-polyglot-module/skill.md +124 -0
  56. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  57. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  58. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  59. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  60. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  61. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  62. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  63. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  64. package/dist/commands/bootstrap.js +0 -7
  65. package/dist/commands/inspect.js +16 -0
  66. package/dist/commands/inspect_commands/contexts.js +55 -0
  67. package/dist/commands/inspect_commands/devices.js +53 -0
  68. package/dist/commands/inspect_commands/heap.js +59 -0
  69. package/dist/commands/inspect_commands/select.js +43 -0
  70. package/dist/commands/inspect_commands/snapshot.js +64 -0
  71. package/dist/commands/inspect_commands/status.js +68 -0
  72. package/dist/commands/inspect_commands/tree.js +86 -0
  73. package/dist/commands/newModule.js +10 -14
  74. package/dist/commands/profile.js +16 -0
  75. package/dist/commands/profile_commands/capture.js +106 -0
  76. package/dist/commands/skills.js +16 -0
  77. package/dist/commands/skills_commands/create.js +125 -0
  78. package/dist/commands/skills_commands/install.js +96 -0
  79. package/dist/commands/skills_commands/list.js +83 -0
  80. package/dist/commands/skills_commands/remove.js +41 -0
  81. package/dist/commands/skills_commands/update.js +59 -0
  82. package/dist/core/constants.js +0 -1
  83. package/dist/core/packageFiles.spec.js +29 -0
  84. package/dist/setup/versions.js +1 -1
  85. package/dist/utils/daemonClient.js +342 -0
  86. package/dist/utils/hermesClient.js +252 -0
  87. package/dist/utils/skillsAdapters.js +140 -0
  88. package/dist/utils/skillsRegistry.js +40 -0
  89. package/dist/utils/stringUtils.spec.js +1 -1
  90. package/package.json +20 -5
  91. package/.bazelignore +0 -2
  92. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  93. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  94. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  95. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  96. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  97. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  98. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  99. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  100. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  101. package/.config/copyconfig.json +0 -10
  102. package/.editorconfig +0 -21
  103. package/.eslintignore +0 -1
  104. package/.eslintrc.js +0 -72
  105. package/.github/README.md +0 -164
  106. package/.metadata/.cursorrules.template +0 -60
  107. package/.prettierignore +0 -2
  108. package/.prettierrc.json +0 -7
  109. package/LINUX_COMPATIBILITY.md +0 -248
  110. package/prettier.config.js +0 -4
  111. package/scripts/sync-agents-md.sh +0 -44
  112. package/scripts/update-agents-templates.ts +0 -170
  113. package/spec/support/jasmine.json +0 -6
  114. package/src/commands/bootstrap.ts +0 -410
  115. package/src/commands/build.ts +0 -89
  116. package/src/commands/devSetup.ts +0 -17
  117. package/src/commands/doctor.ts +0 -1832
  118. package/src/commands/export.ts +0 -131
  119. package/src/commands/hotreload.ts +0 -108
  120. package/src/commands/install.ts +0 -93
  121. package/src/commands/lint.ts +0 -15
  122. package/src/commands/lint_commands/lintCheck.ts +0 -53
  123. package/src/commands/lint_commands/lintFormat.ts +0 -49
  124. package/src/commands/log.ts +0 -108
  125. package/src/commands/newModule.ts +0 -286
  126. package/src/commands/package.ts +0 -102
  127. package/src/commands/projectsync.ts +0 -488
  128. package/src/commands/test.ts +0 -68
  129. package/src/core/constants.ts +0 -98
  130. package/src/core/errors.ts +0 -10
  131. package/src/index.ts +0 -27
  132. package/src/setup/DevSetupHelper.ts +0 -290
  133. package/src/setup/linuxSetup.ts +0 -261
  134. package/src/setup/macOSSetup.ts +0 -156
  135. package/src/setup/setupEntryPoint.ts +0 -64
  136. package/src/setup/versions.ts +0 -8
  137. package/src/utils/ArgumentsResolver.ts +0 -23
  138. package/src/utils/BazelClient.ts +0 -285
  139. package/src/utils/Digraph.ts +0 -81
  140. package/src/utils/LoadingIndicator.ts +0 -43
  141. package/src/utils/applicationUtils.ts +0 -276
  142. package/src/utils/buildInfo.ts +0 -99
  143. package/src/utils/byString.ts +0 -3
  144. package/src/utils/cliUtils.ts +0 -112
  145. package/src/utils/copyBootstrapFiles.ts +0 -30
  146. package/src/utils/deviceUtils.ts +0 -76
  147. package/src/utils/errorUtils.ts +0 -63
  148. package/src/utils/fileUtils.ts +0 -257
  149. package/src/utils/githubUtils.ts +0 -102
  150. package/src/utils/jsonUtils.ts +0 -30
  151. package/src/utils/lintUtils.ts +0 -190
  152. package/src/utils/linuxDistro.spec.ts +0 -219
  153. package/src/utils/linuxDistro.ts +0 -326
  154. package/src/utils/logUtils.ts +0 -9
  155. package/src/utils/pathUtils.ts +0 -12
  156. package/src/utils/stringUtils.spec.ts +0 -95
  157. package/src/utils/stringUtils.ts +0 -103
  158. package/src/utils/tempDir.ts +0 -24
  159. package/src/utils/zipUtils.ts +0 -14
  160. package/test/ValdiSmokeTest.ts +0 -279
  161. package/test/helpers/AsyncHelpers.ts +0 -113
  162. package/test/helpers/CommandHelpers.ts +0 -37
  163. package/test/helpers/ProjectHelpers.ts +0 -153
  164. package/test/helpers/StreamHelpers.ts +0 -37
  165. package/test/helpers/TypeScriptClient.ts +0 -217
  166. package/tsconfig.dist.json +0 -8
  167. package/tsconfig.json +0 -42
  168. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/android/CalculatorModuleFactory.kt.template +0 -0
  169. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/ios/SCCCalculatorModuleFactory.m.template +0 -0
  170. /package/.bootstrap/modules/{cpp_bridge_module → polyglot_bridge_module}/src/Calculator.d.ts +0 -0
@@ -0,0 +1,267 @@
1
+ // Expected Valdi migrations — used to validate skill output correctness.
2
+ // Each section corresponds to a source snippet in flutter/compose/react examples.
3
+
4
+ import { Component, StatefulComponent } from 'valdi_core/src/Component';
5
+ import { Style } from 'valdi_core/src/Style';
6
+ import { systemFont } from 'valdi_core/src/SystemFont';
7
+ import { createProviderComponentWithKeyName } from 'valdi_core/src/provider/createProvider';
8
+ import {
9
+ ProvidersValuesViewModel,
10
+ withProviders,
11
+ } from 'valdi_core/src/provider/withProviders';
12
+ import { CancelablePromise } from 'valdi_core/src/CancelablePromise';
13
+ import { HTTPClient } from 'valdi_http/src/HTTPClient';
14
+ import { HTTPResponse } from 'valdi_http/src/HTTPTypes';
15
+ import { PersistentStore } from 'persistence/src/PersistentStore';
16
+ import { View } from 'valdi_tsx/src/NativeTemplateElements';
17
+
18
+ // Stub for the async data-fetching function referenced in examples
19
+ declare function fetchProfile(id: string): Promise<{ name: string }>;
20
+
21
+ // ============================================================
22
+ // Theme service + Provider
23
+ // ============================================================
24
+
25
+ class AppThemeService {
26
+ primary = '#FFFC00';
27
+ }
28
+ const ThemeProvider = createProviderComponentWithKeyName<AppThemeService>('ThemeProvider');
29
+
30
+ // ============================================================
31
+ // Stateless greeting (Flutter Greeting / Compose Greeting / React Greeting)
32
+ // ============================================================
33
+
34
+ interface GreetingViewModel {
35
+ name: string;
36
+ }
37
+
38
+ class Greeting extends Component<GreetingViewModel> {
39
+ onRender(): void {
40
+ <label value={`Hello, ${this.viewModel.name}`} />;
41
+ }
42
+ }
43
+
44
+ // ============================================================
45
+ // Stateful counter (Flutter Counter / Compose Counter / React Counter)
46
+ // ============================================================
47
+
48
+ interface CounterViewModel {
49
+ label: string;
50
+ }
51
+
52
+ interface CounterState {
53
+ count: number;
54
+ }
55
+
56
+ class Counter extends StatefulComponent<CounterViewModel, CounterState> {
57
+ state = { count: 0 };
58
+
59
+ // Class arrow function — never inline lambda in JSX props
60
+ private increment = () => {
61
+ this.setState({ count: this.state.count + 1 });
62
+ };
63
+
64
+ onRender(): void {
65
+ <view onTap={this.increment}>
66
+ <label value={`${this.viewModel.label}: ${this.state.count}`} />;
67
+ </view>;
68
+ }
69
+ }
70
+
71
+ // ============================================================
72
+ // Data loading (Flutter _UserListState / Compose UserProfile / React UserList)
73
+ // ============================================================
74
+
75
+ interface UserProfileViewModel {
76
+ userId: string;
77
+ }
78
+ interface UserProfileState {
79
+ profile: { name: string } | null;
80
+ }
81
+
82
+ class UserProfile extends StatefulComponent<UserProfileViewModel, UserProfileState> {
83
+ state: UserProfileState = { profile: null };
84
+
85
+ onCreate(): void {
86
+ this.loadProfile(this.viewModel.userId);
87
+ }
88
+
89
+ onViewModelUpdate(previous?: UserProfileViewModel): void {
90
+ if (this.viewModel.userId !== previous?.userId) {
91
+ this.loadProfile(this.viewModel.userId);
92
+ }
93
+ }
94
+
95
+ private async loadProfile(id: string) {
96
+ const profile = await fetchProfile(id);
97
+ this.setState({ profile });
98
+ }
99
+
100
+ onRender(): void {
101
+ if (!this.state.profile) {
102
+ <spinner />;
103
+ return;
104
+ }
105
+ <label value={this.state.profile.name} />;
106
+ }
107
+ }
108
+
109
+ // ============================================================
110
+ // List (Flutter ListView.builder / Compose LazyColumn / React FlatList)
111
+ // ============================================================
112
+
113
+ interface User { id: string; name: string; }
114
+
115
+ interface UserListViewModel {
116
+ users: User[];
117
+ }
118
+
119
+ class UserList extends Component<UserListViewModel> {
120
+ onRender(): void {
121
+ // forEach, not map() — JSX is emitted as side-effects
122
+ <scroll>
123
+ {this.viewModel.users.forEach(user => {
124
+ <label key={user.id} value={user.name} />;
125
+ })}
126
+ </scroll>;
127
+ }
128
+ }
129
+
130
+ // ============================================================
131
+ // Layout (Flutter ProfileCard / Compose ProfileCard)
132
+ // ============================================================
133
+
134
+ interface ProfileCardViewModel {
135
+ name: string;
136
+ handle: string;
137
+ bio: string;
138
+ }
139
+
140
+ class ProfileCard extends Component<ProfileCardViewModel> {
141
+ onRender(): void {
142
+ <view flexDirection="column" width="100%" padding={16}>
143
+ <view flexDirection="row" width="100%">
144
+ <label value={this.viewModel.name} font={systemFont(20)} />;
145
+ <layout flexGrow={1} />;
146
+ <label value={this.viewModel.handle} />;
147
+ </view>;
148
+ <layout height={8} />;
149
+ <label value={this.viewModel.bio} />;
150
+ </view>;
151
+ }
152
+ }
153
+
154
+ // ============================================================
155
+ // Styled card (React styled-components Card)
156
+ // Style objects defined after the class, grouped in a const styles object
157
+ // ============================================================
158
+
159
+ interface CardViewModel {
160
+ name: string;
161
+ bio: string;
162
+ }
163
+
164
+ class ProfileCardStyled extends Component<CardViewModel> {
165
+ onRender(): void {
166
+ <view style={styles.card}>
167
+ <label value={this.viewModel.name} font={systemFont(18)} />;
168
+ <label value={this.viewModel.bio} />;
169
+ </view>;
170
+ }
171
+ }
172
+
173
+ const styles = {
174
+ card: new Style<View>({
175
+ backgroundColor: '#ffffff',
176
+ borderRadius: 12,
177
+ boxShadow: '0 2 8 rgba(0,0,0,0.15)',
178
+ padding: 16,
179
+ }),
180
+ };
181
+
182
+ // ============================================================
183
+ // Provider consumer (Flutter ThemedButton / Compose ThemedBadge / React ThemedBadge)
184
+ // ============================================================
185
+
186
+ interface ThemedBadgeViewModel extends ProvidersValuesViewModel<[AppThemeService]> {
187
+ text: string;
188
+ }
189
+
190
+ class ThemedBadge extends Component<ThemedBadgeViewModel> {
191
+ onRender(): void {
192
+ const [theme] = this.viewModel.providersValues;
193
+ <view backgroundColor={theme.primary}>
194
+ <label value={this.viewModel.text} />;
195
+ </view>;
196
+ }
197
+ }
198
+ const ThemedBadgeWithProvider = withProviders(ThemeProvider)(ThemedBadge);
199
+
200
+ // ============================================================
201
+ // Persistent storage (Flutter SharedPreferences / React AsyncStorage)
202
+ // ============================================================
203
+
204
+ const settingsStore = new PersistentStore('settings');
205
+
206
+ interface SettingsState {
207
+ notifications: boolean;
208
+ }
209
+
210
+ class SettingsScreen extends StatefulComponent<{}, SettingsState> {
211
+ state = { notifications: false };
212
+
213
+ async onCreate() {
214
+ const raw = await settingsStore.fetchString('notifications');
215
+ this.setState({ notifications: raw === 'true' });
216
+ }
217
+
218
+ private toggle = async () => {
219
+ const next = !this.state.notifications;
220
+ await settingsStore.storeString('notifications', String(next));
221
+ this.setState({ notifications: next });
222
+ };
223
+
224
+ onRender(): void {
225
+ <view flexDirection="column">
226
+ <label value={`Notifications: ${this.state.notifications}`} />;
227
+ <view onTap={this.toggle}>
228
+ <label value="Toggle" />;
229
+ </view>;
230
+ </view>;
231
+ }
232
+ }
233
+
234
+ // ============================================================
235
+ // HTTP fetch (React UserList with fetch / Flutter _loadUsers)
236
+ // ============================================================
237
+
238
+ interface FetchState {
239
+ users: User[];
240
+ }
241
+
242
+ class UserListFetch extends StatefulComponent<{}, FetchState> {
243
+ state: FetchState = { users: [] };
244
+
245
+ private client = new HTTPClient('https://api.example.com');
246
+ private request?: CancelablePromise<HTTPResponse>;
247
+
248
+ onCreate(): void {
249
+ this.request = this.client.get('/users');
250
+ this.request.then(response => {
251
+ const users = JSON.parse(new TextDecoder().decode(response.body));
252
+ this.setState({ users });
253
+ });
254
+ }
255
+
256
+ onDestroy(): void {
257
+ this.request?.cancel?.();
258
+ }
259
+
260
+ onRender(): void {
261
+ <scroll>
262
+ {this.state.users.forEach(u => {
263
+ <label key={u.id} value={u.name} />;
264
+ })}
265
+ </scroll>;
266
+ }
267
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../../../src/valdi_modules/src/valdi/_configs/base.tsconfig.json"
3
+ }
@@ -0,0 +1,63 @@
1
+ # Valdi Open Source - Cursor Rules
2
+
3
+ ## ⚠️ Open Source Project
4
+
5
+ This is an open source project. Never commit secrets, API keys, or proprietary information.
6
+
7
+ ## 🚨 CRITICAL: This is NOT React!
8
+
9
+ Valdi uses TSX/JSX syntax but is **fundamentally different from React**.
10
+
11
+ **Common AI mistakes:**
12
+ - ❌ Suggesting `useState`, `useEffect`, `useContext` (don't exist!)
13
+ - ❌ Functional components (don't exist!)
14
+ - ❌ `this.props` (should be `this.viewModel`)
15
+ - ❌ `markNeedsRender()`, `onMount()`, `onUpdate()` (wrong names/don't exist!)
16
+
17
+ **Correct Valdi:**
18
+ - ✅ `class MyComponent extends StatefulComponent`
19
+ - ✅ `state = {}` + `this.setState()`
20
+ - ✅ `this.viewModel` for props
21
+ - ✅ `onCreate()`, `onViewModelUpdate()`, `onDestroy()` lifecycle
22
+
23
+ ## 📦 AI Skills
24
+
25
+ Install Valdi skills for your AI tool to get context-specific guidance:
26
+
27
+ ```bash
28
+ npm install -g @snap/valdi
29
+ valdi skills install
30
+ ```
31
+
32
+ Skills available (`valdi skills list`):
33
+
34
+ | Skill | Coverage |
35
+ |-------|----------|
36
+ | `valdi-tsx` | TSX component patterns, lifecycle, styling |
37
+ | `valdi-setup` | Module BUILD.bazel, tsconfig, hot reload |
38
+ | `valdi-async` | CancelablePromise, HTTPClient, lifecycle safety |
39
+ | `valdi-perf` | ViewModel stability, createReusableCallback, Style interning |
40
+ | `valdi-component-tests` | elementKeyFind, tapNodeWithKey, discriminated unions |
41
+ | `valdi-ios` | Swift/ObjC platform bridging |
42
+ | `valdi-android` | Kotlin platform bridging |
43
+ | `valdi-bazel` | Build rules, platform builds |
44
+ | `valdi-compiler` | Compiler pipeline internals |
45
+ | `valdi-cpp-runtime` | C++ runtime and renderer |
46
+ | `valdi-polyglot-module` | Cross-platform polyglot APIs, web polyglot entry pattern |
47
+ | `valdi-custom-view` | Native view integration, viewFactory |
48
+
49
+ ## Quick Commands
50
+
51
+ ```bash
52
+ bazel build //... # Build everything
53
+ bazel test //... # Run all tests
54
+ valdi install ios # Build & install iOS app
55
+ valdi hotreload # Start hot reload
56
+ ```
57
+
58
+ ## More Information
59
+
60
+ - **Comprehensive guide**: `/AGENTS.md`
61
+ - **AI tooling**: `/docs/docs/ai-tooling.md`
62
+ - **Support**: `/SUPPORT.md`
63
+ - **Discord**: https://discord.gg/uJyNEeYX2U
@@ -0,0 +1,197 @@
1
+ # Valdi Performance Patterns
2
+
3
+ Valdi re-renders a child component whenever its viewModel reference changes. Most
4
+ unnecessary re-renders come from creating new object/array/function references in
5
+ `onRender()`. Fix the reference — fix the re-render.
6
+
7
+ ## ViewModel Identity Stability
8
+
9
+ **The #1 performance problem in Valdi apps.** Every object or array literal created
10
+ inside `onRender()` is a new reference. Child components will always re-render, even
11
+ when the actual values haven't changed.
12
+
13
+ ```typescript
14
+ // ❌ New object every render — child always re-renders
15
+ onRender(): void {
16
+ <UserRow vm={{ name: this.viewModel.user.name, age: this.viewModel.user.age }} />;
17
+ }
18
+
19
+ // ❌ New array every render
20
+ onRender(): void {
21
+ <TabBar tabs={['Home', 'Profile', 'Settings']} />;
22
+ }
23
+
24
+ // ✅ Stable class property for constants
25
+ private tabs = ['Home', 'Profile', 'Settings'];
26
+ onRender(): void {
27
+ <TabBar tabs={this.tabs} />;
28
+ }
29
+
30
+ // ✅ Pre-compute derived viewModels in onViewModelUpdate
31
+ private userRowVM: UserRowViewModel = { name: '', age: 0 };
32
+
33
+ onViewModelUpdate(): void {
34
+ this.userRowVM = { name: this.viewModel.user.name, age: this.viewModel.user.age };
35
+ }
36
+
37
+ onRender(): void {
38
+ <UserRow vm={this.userRowVM} />;
39
+ }
40
+ ```
41
+
42
+ Only update the pre-computed VM when the relevant input actually changes:
43
+
44
+ ```typescript
45
+ onViewModelUpdate(previous?: UserProfileViewModel): void {
46
+ if (this.viewModel.userId !== previous?.userId) {
47
+ this.userRowVM = buildUserRowVM(this.viewModel.user);
48
+ }
49
+ }
50
+ ```
51
+
52
+ ## Navigation Callbacks
53
+
54
+ Navigation callbacks passed into child viewModels have the same identity problem:
55
+ `() => this.navigationController.push(...)` creates a new function each render.
56
+ Use a class arrow function — it is defined once and has a stable reference:
57
+
58
+ ```typescript
59
+ // ❌ New function every render
60
+ onRender(): void {
61
+ <UserCard onTap={() => this.navigationController.push(DetailPage, { id: this.viewModel.userId })} />;
62
+ }
63
+
64
+ // ✅ Class arrow function — stable reference, viewModel.userId read at tap time
65
+ private goToDetail = (): void => {
66
+ this.navigationController.push(DetailPage, { id: this.viewModel.userId });
67
+ };
68
+
69
+ onRender(): void {
70
+ <UserCard onTap={this.goToDetail} />;
71
+ }
72
+ ```
73
+
74
+ ## `<layout>` vs `<view>`
75
+
76
+ `<view>` allocates a native platform view. `<layout>` is virtual — it participates in
77
+ flexbox layout but creates no native view, which is faster and uses less memory.
78
+
79
+ ```typescript
80
+ // ❌ Native view wasted on an invisible spacer
81
+ <view height={16} />
82
+
83
+ // ✅ No native view allocated
84
+ <layout height={16} />
85
+
86
+ // ❌ Wrapper with no visual properties or tap handler
87
+ <view flexDirection="column">
88
+ <label value="A" />;
89
+ <label value="B" />;
90
+ </view>;
91
+
92
+ // ✅ Virtual layout node
93
+ <layout flexDirection="column">
94
+ <label value="A" />;
95
+ <label value="B" />;
96
+ </layout>;
97
+ ```
98
+
99
+ **Use `<view>` when you need:** `onTap`, `backgroundColor`, `borderRadius`, `style`,
100
+ `overflow`, `opacity`, or any visual/interactive property.
101
+ **Use `<layout>` for everything else:** spacers, invisible wrappers, structural containers.
102
+
103
+ ## Keys in Lists
104
+
105
+ Keys determine element identity across re-renders. Without a key (or with an index
106
+ key), reordering or inserting items causes the wrong component instances to receive
107
+ the wrong viewModels.
108
+
109
+ ```typescript
110
+ // ❌ No key — identity lost on reorder
111
+ {this.viewModel.items.forEach(item => {
112
+ <ItemRow value={item.name} />;
113
+ })}
114
+
115
+ // ❌ Index key — breaks on insert/remove
116
+ {this.viewModel.items.forEach((item, index) => {
117
+ <ItemRow key={String(index)} value={item.name} />;
118
+ })}
119
+
120
+ // ✅ Stable data ID
121
+ {this.viewModel.items.forEach(item => {
122
+ <ItemRow key={item.id} value={item.name} />;
123
+ })}
124
+ ```
125
+
126
+ ## Render Props as Class Arrow Functions
127
+
128
+ When a parent needs to pass a render function to a child (e.g. a list row renderer),
129
+ define it as a class arrow function property so it has a stable reference:
130
+
131
+ ```typescript
132
+ // ❌ New function every render — child's renderItem prop always changes
133
+ onRender(): void {
134
+ <List renderItem={(item) => { <Row data={item} />; }} />;
135
+ }
136
+
137
+ // ✅ Stable class arrow function
138
+ private renderItem = (item: Item): void => {
139
+ <Row data={item} />;
140
+ };
141
+
142
+ onRender(): void {
143
+ <List renderItem={this.renderItem} />;
144
+ }
145
+ ```
146
+
147
+ For loop closures that must capture a loop variable, use `createReusableCallback`
148
+ inline in `onRender()`. Valdi's diffing engine recognises `Callback` objects and
149
+ updates the internal function reference without treating it as a prop change, so the
150
+ child does not re-render:
151
+
152
+ ```typescript
153
+ import { createReusableCallback } from 'valdi_core/src/utils/Callback';
154
+
155
+ // ❌ New plain function every render — child always re-renders
156
+ onRender(): void {
157
+ {this.viewModel.sections.forEach((section, i) => {
158
+ <Section onTap={() => this.handleTap(i)} />;
159
+ })}
160
+ }
161
+
162
+ // ✅ Inline Callback — identity-merged by Valdi's diffing engine
163
+ onRender(): void {
164
+ {this.viewModel.sections.forEach((section, i) => {
165
+ <Section onTap={createReusableCallback(() => this.handleTap(i))} />;
166
+ })}
167
+ }
168
+ ```
169
+
170
+ ## Style Objects at Module Level
171
+
172
+ `new Style<T>({...})` interns style objects — the same property values always produce
173
+ the same cached object. This interning only works at module initialization time.
174
+ Inside `onRender()` the cache is bypassed and a new allocation happens every render.
175
+
176
+ ```typescript
177
+ // ❌ Defeats interning — new allocation every render
178
+ onRender(): void {
179
+ const s = new Style<View>({ backgroundColor: '#fff', borderRadius: 8 });
180
+ <view style={s} />;
181
+ }
182
+
183
+ // ✅ Interned at module level
184
+ import { View } from 'valdi_tsx/src/NativeTemplateElements';
185
+
186
+ const styles = {
187
+ card: new Style<View>({ backgroundColor: '#fff', borderRadius: 8 }),
188
+ };
189
+
190
+ class MyCard extends Component<MyViewModel> {
191
+ onRender(): void {
192
+ <view style={styles.card} />;
193
+ }
194
+ }
195
+ ```
196
+
197
+ Group styles in a `const styles = {}` object after the class definition.
@@ -0,0 +1,19 @@
1
+ load("//bzl/valdi:valdi_module.bzl", "valdi_module")
2
+
3
+ valdi_module(
4
+ name = "tests",
5
+ srcs = glob([
6
+ "src/**/*.ts",
7
+ "src/**/*.tsx",
8
+ ]) + [
9
+ "tsconfig.json",
10
+ ],
11
+ android_output_target = "release",
12
+ ios_module_name = "SCCValdiPerfRef",
13
+ ios_output_target = "release",
14
+ visibility = ["//visibility:public"],
15
+ deps = [
16
+ "//src/valdi_modules/src/valdi/valdi_core",
17
+ "//src/valdi_modules/src/valdi/valdi_tsx",
18
+ ],
19
+ )
@@ -0,0 +1,26 @@
1
+ # valdi-perf skill tests
2
+
3
+ Compile check for the performance patterns taught in `skill.md`.
4
+
5
+ ## What's tested
6
+
7
+ `src/reference.tsx` exercises:
8
+ - Pre-computed viewModels in `onViewModelUpdate` (stable child references)
9
+ - `createReusableCallback` for memoized callbacks by argument
10
+ - `<layout>` vs `<view>` for invisible containers and spacers
11
+ - Stable class arrow functions for render props
12
+ - Module-level `Style` objects (not created inside `onRender`)
13
+ - `key={item.id}` with stable data IDs in lists (not array indices)
14
+
15
+ ## Compile check
16
+
17
+ ```bash
18
+ cd client/src/open_source
19
+ bazel build //ai-skills/skills/valdi-perf/tests:tests
20
+ ```
21
+
22
+ Expected: `Build completed successfully`
23
+
24
+ ## Updating
25
+
26
+ When Valdi APIs change (import paths, type signatures), update `src/reference.tsx` to match and keep it compiling. Also update `../skill.md` with any corrected patterns.