neo.mjs 10.0.0-alpha.5 → 10.0.0-beta.2

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 (188) hide show
  1. package/ServiceWorker.mjs +2 -2
  2. package/apps/colors/view/GridContainer.mjs +1 -1
  3. package/apps/covid/view/AttributionComponent.mjs +1 -1
  4. package/apps/covid/view/HeaderContainer.mjs +6 -6
  5. package/apps/covid/view/MainContainerController.mjs +5 -5
  6. package/apps/covid/view/TableContainerController.mjs +1 -1
  7. package/apps/covid/view/country/Gallery.mjs +13 -13
  8. package/apps/covid/view/country/Helix.mjs +13 -13
  9. package/apps/covid/view/country/HistoricalDataTable.mjs +1 -1
  10. package/apps/email/view/Viewport.mjs +2 -2
  11. package/apps/form/view/SideNavList.mjs +1 -1
  12. package/apps/portal/index.html +1 -1
  13. package/apps/portal/resources/data/examples_devmode.json +26 -27
  14. package/apps/portal/resources/data/examples_dist_dev.json +26 -27
  15. package/apps/portal/resources/data/examples_dist_esm.json +25 -26
  16. package/apps/portal/resources/data/examples_dist_prod.json +26 -27
  17. package/apps/portal/view/HeaderToolbar.mjs +3 -3
  18. package/apps/portal/view/about/Container.mjs +2 -2
  19. package/apps/portal/view/about/MemberContainer.mjs +3 -3
  20. package/apps/portal/view/blog/List.mjs +7 -7
  21. package/apps/portal/view/examples/List.mjs +4 -4
  22. package/apps/portal/view/home/ContentBox.mjs +2 -2
  23. package/apps/portal/view/home/FeatureSection.mjs +3 -3
  24. package/apps/portal/view/home/FooterContainer.mjs +7 -7
  25. package/apps/portal/view/home/parts/AfterMath.mjs +3 -3
  26. package/apps/portal/view/home/parts/MainNeo.mjs +3 -3
  27. package/apps/portal/view/home/parts/References.mjs +6 -6
  28. package/apps/portal/view/learn/ContentComponent.mjs +102 -111
  29. package/apps/portal/view/learn/PageSectionsContainer.mjs +1 -1
  30. package/apps/portal/view/learn/PageSectionsList.mjs +2 -2
  31. package/apps/portal/view/services/Component.mjs +16 -16
  32. package/apps/realworld/view/FooterComponent.mjs +1 -1
  33. package/apps/realworld/view/HeaderComponent.mjs +8 -8
  34. package/apps/realworld/view/HomeComponent.mjs +6 -6
  35. package/apps/realworld/view/article/CommentComponent.mjs +4 -4
  36. package/apps/realworld/view/article/Component.mjs +14 -14
  37. package/apps/realworld/view/article/CreateCommentComponent.mjs +3 -3
  38. package/apps/realworld/view/article/CreateComponent.mjs +3 -3
  39. package/apps/realworld/view/article/PreviewComponent.mjs +1 -1
  40. package/apps/realworld/view/article/TagListComponent.mjs +2 -2
  41. package/apps/realworld/view/user/ProfileComponent.mjs +8 -8
  42. package/apps/realworld/view/user/SettingsComponent.mjs +4 -4
  43. package/apps/realworld/view/user/SignUpComponent.mjs +4 -4
  44. package/apps/realworld2/view/FooterComponent.mjs +1 -1
  45. package/apps/realworld2/view/HomeContainer.mjs +3 -3
  46. package/apps/realworld2/view/article/DetailsContainer.mjs +1 -1
  47. package/apps/realworld2/view/article/PreviewComponent.mjs +7 -7
  48. package/apps/realworld2/view/article/TagListComponent.mjs +2 -2
  49. package/apps/realworld2/view/user/ProfileContainer.mjs +1 -1
  50. package/apps/route/view/center/CardAdministration.mjs +2 -2
  51. package/apps/route/view/center/CardAdministrationDenied.mjs +1 -1
  52. package/apps/route/view/center/CardContact.mjs +2 -2
  53. package/apps/route/view/center/CardHome.mjs +1 -1
  54. package/apps/route/view/center/CardSection1.mjs +1 -1
  55. package/apps/route/view/center/CardSection2.mjs +1 -1
  56. package/apps/sharedcovid/view/AttributionComponent.mjs +1 -1
  57. package/apps/sharedcovid/view/HeaderContainer.mjs +6 -6
  58. package/apps/sharedcovid/view/MainContainerController.mjs +5 -5
  59. package/apps/sharedcovid/view/TableContainerController.mjs +1 -1
  60. package/apps/sharedcovid/view/country/Gallery.mjs +13 -13
  61. package/apps/sharedcovid/view/country/Helix.mjs +13 -13
  62. package/apps/sharedcovid/view/country/HistoricalDataTable.mjs +1 -1
  63. package/apps/shareddialog/childapps/shareddialog2/view/MainContainer.mjs +1 -1
  64. package/apps/shareddialog/view/MainContainer.mjs +1 -1
  65. package/buildScripts/createApp.mjs +2 -2
  66. package/examples/table/cellEditing/MainContainer.mjs +1 -1
  67. package/examples/table/container/MainContainer.mjs +3 -3
  68. package/examples/table/nestedRecordFields/Viewport.mjs +6 -6
  69. package/examples/tableFiltering/MainContainer.mjs +1 -1
  70. package/examples/tablePerformance/MainContainer.mjs +1 -1
  71. package/examples/tablePerformance/MainContainer2.mjs +1 -1
  72. package/examples/tablePerformance/MainContainer3.mjs +2 -2
  73. package/examples/tableStore/MainContainer.mjs +2 -2
  74. package/learn/Glossary.md +261 -0
  75. package/learn/UsingTheseTopics.md +2 -2
  76. package/learn/benefits/ConfigSystem.md +538 -28
  77. package/learn/benefits/Effort.md +47 -2
  78. package/learn/benefits/Features.md +50 -32
  79. package/learn/benefits/FormsEngine.md +68 -38
  80. package/learn/benefits/MultiWindow.md +33 -7
  81. package/learn/benefits/OffTheMainThread.md +2 -2
  82. package/learn/benefits/Quick.md +45 -12
  83. package/learn/benefits/RPCLayer.md +75 -0
  84. package/learn/benefits/Speed.md +16 -11
  85. package/learn/gettingstarted/ComponentModels.md +4 -4
  86. package/learn/gettingstarted/Config.md +6 -6
  87. package/learn/gettingstarted/DescribingTheUI.md +4 -4
  88. package/learn/gettingstarted/Events.md +6 -6
  89. package/learn/gettingstarted/Extending.md +4 -4
  90. package/learn/gettingstarted/References.md +6 -6
  91. package/learn/gettingstarted/Workspaces.md +6 -6
  92. package/learn/guides/ApplicationBootstrap.md +26 -26
  93. package/learn/guides/ComponentsAndContainers.md +12 -12
  94. package/learn/guides/ConfigSystemDeepDive.md +280 -0
  95. package/learn/guides/CustomComponents.md +2 -2
  96. package/learn/guides/DeclarativeComponentTreesVsImperativeVdom.md +17 -17
  97. package/learn/guides/InstanceLifecycle.md +295 -1
  98. package/learn/guides/MainThreadAddons.md +475 -0
  99. package/learn/guides/PortalApp.md +2 -2
  100. package/learn/guides/StateProviders.md +12 -12
  101. package/learn/guides/WorkingWithVDom.md +14 -14
  102. package/learn/guides/events/CustomEvents.md +16 -16
  103. package/learn/guides/events/DomEvents.md +12 -12
  104. package/learn/javascript/ClassFeatures.md +3 -2
  105. package/learn/javascript/Classes.md +8 -8
  106. package/learn/javascript/NewNode.md +4 -4
  107. package/learn/javascript/Overrides.md +8 -8
  108. package/learn/javascript/Super.md +10 -8
  109. package/learn/tree.json +52 -51
  110. package/learn/tutorials/Earthquakes.md +54 -57
  111. package/learn/tutorials/TodoList.md +4 -4
  112. package/package.json +2 -2
  113. package/resources/scss/src/apps/portal/learn/ContentComponent.scss +12 -0
  114. package/resources/scss/src/table/{View.scss → Body.scss} +1 -1
  115. package/resources/scss/src/table/plugin/CellEditing.scss +1 -1
  116. package/resources/scss/theme-dark/table/{View.scss → Body.scss} +1 -1
  117. package/resources/scss/theme-light/table/{View.scss → Body.scss} +1 -1
  118. package/resources/scss/theme-neo-light/Global.scss +1 -2
  119. package/resources/scss/theme-neo-light/table/{View.scss → Body.scss} +1 -1
  120. package/src/DefaultConfig.mjs +2 -2
  121. package/src/Main.mjs +8 -7
  122. package/src/Neo.mjs +16 -2
  123. package/src/button/Base.mjs +2 -2
  124. package/src/calendar/view/SettingsContainer.mjs +2 -2
  125. package/src/calendar/view/YearComponent.mjs +9 -9
  126. package/src/calendar/view/calendars/ColorsList.mjs +1 -1
  127. package/src/calendar/view/calendars/List.mjs +1 -1
  128. package/src/calendar/view/month/Component.mjs +15 -15
  129. package/src/calendar/view/week/Component.mjs +12 -12
  130. package/src/calendar/view/week/EventDragZone.mjs +4 -4
  131. package/src/calendar/view/week/TimeAxisComponent.mjs +3 -3
  132. package/src/component/Base.mjs +17 -2
  133. package/src/component/Carousel.mjs +2 -2
  134. package/src/component/Chip.mjs +3 -3
  135. package/src/component/Circle.mjs +2 -2
  136. package/src/component/DateSelector.mjs +8 -8
  137. package/src/component/Helix.mjs +1 -1
  138. package/src/component/Label.mjs +3 -18
  139. package/src/component/Legend.mjs +3 -3
  140. package/src/component/MagicMoveText.mjs +6 -14
  141. package/src/component/Process.mjs +3 -3
  142. package/src/component/Progress.mjs +1 -1
  143. package/src/component/StatusBadge.mjs +2 -2
  144. package/src/component/Timer.mjs +2 -2
  145. package/src/component/Toast.mjs +5 -3
  146. package/src/container/AccordionItem.mjs +2 -2
  147. package/src/container/Base.mjs +1 -1
  148. package/src/core/Base.mjs +77 -14
  149. package/src/core/Util.mjs +14 -2
  150. package/src/date/DayViewComponent.mjs +2 -2
  151. package/src/date/SelectorContainer.mjs +1 -1
  152. package/src/draggable/grid/header/toolbar/SortZone.mjs +21 -21
  153. package/src/draggable/table/header/toolbar/SortZone.mjs +1 -1
  154. package/src/form/field/CheckBox.mjs +4 -4
  155. package/src/form/field/FileUpload.mjs +25 -39
  156. package/src/form/field/Range.mjs +1 -1
  157. package/src/form/field/Text.mjs +3 -3
  158. package/src/form/field/TextArea.mjs +2 -3
  159. package/src/grid/Body.mjs +8 -5
  160. package/src/grid/_export.mjs +1 -1
  161. package/src/list/Color.mjs +2 -2
  162. package/src/main/DeltaUpdates.mjs +157 -98
  163. package/src/main/addon/AmCharts.mjs +61 -84
  164. package/src/main/addon/Base.mjs +161 -42
  165. package/src/main/addon/GoogleMaps.mjs +9 -16
  166. package/src/main/addon/HighlightJS.mjs +2 -13
  167. package/src/main/addon/IntersectionObserver.mjs +21 -21
  168. package/src/main/addon/MonacoEditor.mjs +32 -64
  169. package/src/manager/ClassHierarchy.mjs +114 -0
  170. package/src/menu/List.mjs +1 -1
  171. package/src/plugin/Popover.mjs +2 -2
  172. package/src/sitemap/Component.mjs +1 -1
  173. package/src/table/{View.mjs → Body.mjs} +25 -22
  174. package/src/table/Container.mjs +43 -43
  175. package/src/table/_export.mjs +2 -2
  176. package/src/table/plugin/CellEditing.mjs +19 -19
  177. package/src/tooltip/Base.mjs +1 -6
  178. package/src/tree/Accordion.mjs +3 -3
  179. package/src/vdom/Helper.mjs +19 -22
  180. package/src/worker/App.mjs +1 -2
  181. package/src/worker/Base.mjs +7 -5
  182. package/src/worker/Canvas.mjs +2 -3
  183. package/src/worker/Data.mjs +5 -7
  184. package/src/worker/Task.mjs +2 -3
  185. package/src/worker/VDom.mjs +3 -4
  186. package/src/worker/mixin/RemoteMethodAccess.mjs +5 -2
  187. package/learn/guides/MainThreadAddonExample.md +0 -15
  188. package/learn/guides/MainThreadAddonIntro.md +0 -44
@@ -1 +1,295 @@
1
- ## todo
1
+ Understanding the lifecycle of a class instance in Neo.mjs is crucial for building robust and predictable
2
+ applications. The framework provides a series of well-defined hooks that allow you to tap into different stages of an
3
+ instance's life, from its creation to its destruction.
4
+
5
+ This guide will walk you through the entire lifecycle, starting with the initial synchronous steps and moving on to
6
+ the asynchronous parts and destruction.
7
+
8
+ ## How the Lifecycle is Triggered
9
+
10
+ While this guide details the lifecycle methods of an instance, it's important to understand how that lifecycle begins.
11
+ In typical Neo.mjs application code, you will rarely call `Neo.create()` directly.
12
+
13
+ The most common way to create component instances is declaratively, by defining configuration objects within a container's
14
+ `items` array. The framework then internally uses `Neo.create()` to turn these configuration objects into fully-fledged
15
+ instances, automatically initiating their lifecycle.
16
+
17
+ It is crucial to **never** create a Neo.mjs class instance using the `new` keyword (e.g., `new MyComponent()`),
18
+ as this would bypass the entire lifecycle initialization process described below, resulting in a broken and
19
+ improperly configured instance. Always let the framework handle instantiation, either through declarative `items`
20
+ configs or, in less common cases, by using `Neo.create()` directly.
21
+
22
+ ## 1. The Synchronous Creation Flow
23
+
24
+ When the framework creates a new instance, it executes a sequence of synchronous methods. This initial phase is
25
+ responsible for setting up the instance's basic configuration and state.
26
+
27
+ The synchronous lifecycle methods are called in the following order:
28
+
29
+ 1. **`new YourClass()`**: The framework first calls the actual JavaScript class constructor with **no arguments**.
30
+ This is a crucial step. Its primary purpose is to create the instance and initialize all of its defined class
31
+ fields. This ensures that by the time any Neo.mjs lifecycle method (like `construct`) or config hook
32
+ (like `beforeGetX`) is called, all class fields are fully available on `this`, preventing potential race
33
+ conditions or errors from accessing uninitialized properties.
34
+
35
+ 2. **`construct(config)`**: This is the first Neo.mjs lifecycle hook called on the new instance. Its primary role is
36
+ to process the configuration object that was passed to `Neo.create()`. It's here that the initial values for
37
+ your configs are processed and applied via the config system.
38
+
39
+ 3. **`onConstructed()`**: This hook is called immediately after `construct()` has finished. It's the ideal place to
40
+ perform any setup that depends on the initial configuration, such as setting initial values for other
41
+ properties or starting a process.
42
+
43
+ 4. **`onAfterConstructed()`**: This hook is called after `onConstructed()`. It provides another opportunity for
44
+ setup logic, which can be useful for separating concerns or for logic that needs to run after the primary
45
+ `onConstructed` logic has completed.
46
+
47
+ 5. **`init()`**: This is the final synchronous hook in the creation process. It's a general-purpose initialization
48
+ method that you can use for any final setup tasks before the instance is returned by `Neo.create()`.
49
+
50
+ It's important to remember that all of these methods are synchronous. Any asynchronous operations should be handled
51
+ in the later, asynchronous phases of the lifecycle.
52
+
53
+ ## 2. `constructor()` vs `construct()`: A Critical Distinction
54
+
55
+ While you *can* define a standard JavaScript `constructor()` method on a Neo.mjs class, it is strongly discouraged
56
+ and considered a bad practice. The framework provides the `construct()` lifecycle hook for a very specific and
57
+ powerful reason: **pre-processing configs**.
58
+
59
+ ### The `constructor()` Limitation
60
+
61
+ In standard JavaScript class inheritance, you **cannot** access the `this` context in a constructor before calling
62
+ `super()`. This is a language-level restriction.
63
+
64
+ ```javascript
65
+ // Anti-pattern: Do not do this in Neo.mjs
66
+ constructor(config) {
67
+ // ERROR! 'this' is not available before super()
68
+ console.log(this.someClassField);
69
+
70
+ super(config); // Assuming a parent constructor call
71
+ }
72
+ ```
73
+
74
+ ### The `construct()` Advantage
75
+
76
+ The `construct()` method, however, is just a regular method called by the framework *after* the instance has been
77
+ fully created (via `new YourClass()`). This means that inside `construct()`, you have full access to `this` from the
78
+ very first line.
79
+
80
+ This enables a powerful pattern: you can inspect or modify the incoming `config` object *before* passing it up the
81
+ inheritance chain with `super.construct(config)`. This is invaluable for component-specific logic.
82
+
83
+ ```javascript
84
+ // The correct Neo.mjs pattern
85
+ construct(config) {
86
+ // 'this' is fully available here!
87
+ // We can inspect the config and perform logic before the parent class does.
88
+ if (config.someFlag) {
89
+ config.title = 'Title set by child class';
90
+ this.someProperty = true;
91
+ }
92
+
93
+ // Now, pass the (potentially modified) config to the parent.
94
+ super.construct(config);
95
+ }
96
+ ```
97
+
98
+ In summary, always use `construct()` for your initialization logic. It provides the flexibility needed to work
99
+ within the Neo.mjs lifecycle and config system, a flexibility that the standard `constructor()` cannot offer.
100
+
101
+ ## 3. The Asynchronous Initialization Flow
102
+
103
+ After the synchronous creation methods are complete, the instance lifecycle moves into an asynchronous phase. This is
104
+ where you should place any logic that cannot be executed synchronously, such as loading external files, fetching
105
+ data from a server, or waiting for other resources to become available.
106
+
107
+ This phase is orchestrated by a microtask scheduled from within the `construct()` method.
108
+
109
+ ### `initAsync()`: The Asynchronous Entry Point
110
+
111
+ The core of this phase is the `async initAsync()` method.
112
+
113
+ * **Scheduling**: Immediately after the synchronous `construct()` logic is finished, the framework schedules a
114
+ microtask (`Promise.resolve().then(...)`) that will execute after the current JavaScript execution block is empty.
115
+ * **Execution**: This microtask calls and `await`s the `initAsync()` method. This is the designated place for all
116
+ asynchronous initialization logic. You can override this method in your own classes to perform tasks like
117
+ dynamic imports or initial data fetching.
118
+ * **Parent Call**: When overriding `initAsync()`, it is crucial to call `await super.initAsync()` at the beginning
119
+ of your implementation to ensure that parent classes can perform their own asynchronous setup, such as
120
+ registering remote methods.
121
+
122
+ ```javascript
123
+ // In your class
124
+ async initAsync() {
125
+ // Always call the parent method first!
126
+ await super.initAsync();
127
+
128
+ // Your async logic here
129
+ const myModule = await import('./MyOptionalModule.mjs');
130
+ this.data = await myService.fetchInitialData();
131
+ }
132
+ ```
133
+
134
+ ### `isReady`: The Signal of Completion
135
+
136
+ Once the `initAsync()` promise resolves, the framework sets the instance's `isReady` config to `true`.
137
+
138
+ * **`isReady_`**: The config is defined as `isReady_` (with a trailing underscore), which means it gets an
139
+ `afterSetIsReady(value, oldValue)` hook.
140
+ * **Reacting to Readiness**: You can implement the `afterSetIsReady()` method to be notified precisely when the
141
+ instance is fully initialized and ready for interaction. This is the most reliable way to coordinate logic that
142
+ depends on the component's full readiness.
143
+
144
+ ```javascript
145
+ // In your class
146
+ afterSetIsReady(isReady, wasReady) {
147
+ if (isReady && !wasReady) {
148
+ console.log('The instance is now fully ready!');
149
+ // Perform actions that require the component to be fully initialized
150
+ }
151
+ }
152
+ ```
153
+
154
+ This `initAsync` -> `isReady` pattern provides a robust and predictable way to manage the asynchronous parts of the
155
+ instance lifecycle, ensuring that dependent logic only runs when the instance is in a known, ready state.
156
+
157
+ ## 4. Destruction: Cleaning Up with `destroy()`
158
+
159
+ The final phase of the instance lifecycle is destruction. Properly cleaning up instances when they are no longer needed
160
+ is critical for preventing memory leaks and ensuring your application remains performant over time. The `destroy()`
161
+ method is the designated entry point for all cleanup logic.
162
+
163
+ ### The Base `destroy()` Implementation
164
+
165
+ The `Neo.core.Base` class provides a foundational `destroy()` method that performs several key actions:
166
+
167
+ * **Clears Timeouts**: It clears any pending timeouts that were created using `this.timeout()`.
168
+ * **Unregisters Instance**: It unregisters the instance from the global `Neo.manager.Instance`, so it can no longer
169
+ be looked up by its ID.
170
+ * **Property Deletion**: It iterates over all properties of the instance and deletes them. This is an aggressive
171
+ strategy to help the JavaScript garbage collector reclaim memory by breaking references.
172
+ * **Single-Execution Guard**: The base class automatically intercepts the `destroy()` method to ensure that its core
173
+ logic can only be executed **once**, even if `destroy()` is called multiple times.
174
+
175
+ ### Overriding `destroy()`: Best Practices
176
+
177
+ When your class holds references to other Neo.mjs instances or external resources, you must override the `destroy()`
178
+ method to manage them correctly. The primary goal is to break all circular references and remove any listeners or
179
+ registrations so that the instance can be safely garbage collected.
180
+
181
+ Here is an example from `Neo.grid.Container` that illustrates key best practices:
182
+
183
+ ```javascript
184
+ // Example from src/grid/Container.mjs
185
+ destroy(...args) {
186
+ let me = this;
187
+
188
+ // 1. Clean up SHARED instances (e.g., Stores)
189
+ // We don't destroy the store, as it might be used by other components.
190
+ // Setting it to null will trigger the afterSetStore hook, which is the
191
+ // correct place to remove any listeners this grid added to the store.
192
+ me.store = null;
193
+
194
+ // 2. Destroy OWNED instances
195
+ // The grid container creates and owns its scrollManager, so it's
196
+ // responsible for destroying it.
197
+ me.scrollManager.destroy();
198
+
199
+ // 3. Unregister from external services/managers
200
+ // The component had previously registered with the ResizeObserver addon.
201
+ // It must unregister to prevent the addon from holding a dead reference.
202
+ me.mounted && Neo.main.addon.ResizeObserver.unregister({
203
+ id : me.id,
204
+ windowId: me.windowId
205
+ });
206
+
207
+ // 4. ALWAYS call super.destroy() LAST
208
+ // This executes the base cleanup logic after your custom logic is complete.
209
+ super.destroy(...args);
210
+ }
211
+ ```
212
+
213
+ To summarize the best practices:
214
+
215
+ 1. **Call `super.destroy()` Last**: Always end your `destroy()` method with `super.destroy(...args)`. If you call it
216
+ first, `this` will be partially dismantled, and subsequent calls on it will likely fail.
217
+ 2. **Destroy Owned Instances**: If your class creates its own instances of other Neo.mjs classes (e.g., helpers,
218
+ managers), you are responsible for calling `destroy()` on them.
219
+ 3. **Clean Up Shared Instances**: If your class uses a shared instance (like a `Store` or a global service), do **not**
220
+ call `destroy()` on it. Instead, remove any listeners you added to it. A good pattern is to set the config
221
+ property to `null` (e.g., `this.store = null`) and perform the listener cleanup inside the `afterSet` hook.
222
+ 4. **Unregister from Services**: If your class registered itself with any external manager or service (like the
223
+ `ResizeObserver`), be sure to unregister from it.
224
+
225
+ ## 5. Lifecycle of Nested Instances: Set-Driven vs. Get-Driven
226
+
227
+ A powerful feature of the config system is that a config property can be another Neo.mjs class instance. A common
228
+ example is a grid's `selectionModel`. This raises an important architectural question: when should this nested
229
+ instance be created? The framework supports two patterns, each with different implications for the lifecycle.
230
+
231
+ ### The Set-Driven Approach (Eager Instantiation)
232
+
233
+ In this pattern, you ensure the instance is created as soon as the config is set. This is typically done inside a
234
+ `beforeSet` hook.
235
+
236
+ The `Neo.grid.Body` class provides a perfect example with its `selectionModel_` config.
237
+
238
+ ```javascript
239
+ // In Neo.grid.Body
240
+ beforeSetSelectionModel(value, oldValue) {
241
+ oldValue?.destroy();
242
+
243
+ // beforeSetInstance ensures the value is a valid instance,
244
+ // creating one from a config object if necessary.
245
+ return ClassSystemUtil.beforeSetInstance(value, RowModel);
246
+ }
247
+ ```
248
+
249
+ When the framework processes the grid body's configs during its `construct` phase, `beforeSetSelectionModel` is
250
+ called. It immediately creates the selection model instance.
251
+
252
+ **The key takeaway is the guarantee this provides for `onConstructed()`**. Because the selection model was
253
+ instantiated during `construct`, by the time `onConstructed()` is called, you can safely assume the instance exists.
254
+
255
+ ```javascript
256
+ // In Neo.grid.Body
257
+ onConstructed() {
258
+ super.onConstructed();
259
+
260
+ // This is safe because beforeSetSelectionModel already created the instance.
261
+ this.selectionModel?.register(this);
262
+ }
263
+ ```
264
+
265
+ Use the set-driven approach when a nested instance is **essential** for the component's core functionality and needs
266
+ to be available immediately after construction.
267
+
268
+ ### The Get-Driven Approach (Lazy Instantiation)
269
+
270
+ Alternatively, you can defer the creation of a nested instance until it's actually needed for the first time. This
271
+ is achieved by creating the instance within a `beforeGet` hook. This "lazy" approach can improve initial creation
272
+ performance if the nested instance is complex or not always used.
273
+
274
+ `Neo.grid.Body` also demonstrates this pattern with its `columnPositions_` config.
275
+
276
+ ```javascript
277
+ // In Neo.grid.Body
278
+ beforeGetColumnPositions(value) {
279
+ // If the backing field (_columnPositions) is null...
280
+ if (!value) {
281
+ // ...create the instance now.
282
+ this._columnPositions = value = Neo.create({
283
+ module : Collection,
284
+ keyProperty: 'dataField'
285
+ });
286
+ }
287
+ return value;
288
+ }
289
+ ```
290
+
291
+ With this pattern, the `columnPositions` collection is **not** created during the `construct` phase. It is only
292
+ instantiated the very first time some other code calls `this.columnPositions`.
293
+
294
+ Use the get-driven approach for non-essential or heavy nested instances to optimize performance and memory usage,
295
+ especially if they are only used in specific scenarios.