You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/core/Base.mjs
+51-3Lines changed: 51 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,26 @@ class Base {
58
58
*/
59
59
staticoverwrittenMethods={}
60
60
/**
61
-
* Configs will get merged throughout the class hierarchy
61
+
* Defines the default configuration properties for the class. These configurations are
62
+
* merged throughout the class hierarchy and can be overridden at the instance level.
63
+
*
64
+
* There are two main types of configs:
65
+
*
66
+
* 1. **Reactive Configs:** Property names ending with a trailing underscore (e.g., `myConfig_`).
67
+
* The framework automatically generates a public getter and setter, removing the underscore
68
+
* from the property name (e.g., `this.myConfig`). This system enables powerful, optional
69
+
* lifecycle hooks that are called automatically if they are implemented on the class:
70
+
* - `beforeGetMyConfig(value)`: Executed before the getter returns. Can be used to dynamically modify the returned value.
71
+
* - `beforeSetMyConfig(newValue, oldValue)`: Executed before a new value is set. Can be used for validation or transformation. Returning `undefined` from this hook will cancel the update.
72
+
* - `afterSetMyConfig(newValue, oldValue)`: Executed after a new value has been successfully set. Ideal for triggering side effects.
73
+
*
74
+
* 2. **Non-Reactive (Prototype-based) Configs:** Property names without a trailing underscore.
75
+
* These are applied directly to the class's **prototype** during the `Neo.setupClass`
76
+
* process. This is highly memory-efficient as the value is shared across all instances.
77
+
* It also allows for powerful, application-wide modifications of default behaviors
78
+
* by using the `Neo.overwrites` mechanism, which modifies these prototype values at
79
+
* load time.
80
+
*
62
81
* @returns {Object} config
63
82
*/
64
83
staticconfig={
@@ -290,9 +309,38 @@ class Base {
290
309
}
291
310
292
311
/**
293
-
* Applying overwrites and adding overwrittenMethods to the class constructors
294
-
* @param {Object} cfg
312
+
* This static method is called by `Neo.setupClass()` during the class creation process.
313
+
* It allows for modifying a class's default prototype-based configs from outside the
314
+
* class hierarchy, which is a powerful way to avoid boilerplate code.
315
+
*
316
+
* It looks for a matching entry in the global `Neo.overwrites` object based on the
317
+
* class's `className`. If found, it merges the properties from the overwrite object
318
+
* into the class's static `config`. This provides a powerful mechanism for theming
319
+
* or applying application-wide customizations to framework or library classes without
320
+
* needing to extend them.
321
+
*
322
+
* @example
323
+
* // Imagine you have hundreds of buttons in your app, and you want all of them
324
+
* // to have `labelPosition: 'top'` instead of the default `'left'`.
325
+
* // Instead of configuring each instance, you can define an overwrite.
326
+
*
327
+
* // inside an Overwrites.mjs file loaded by your app:
328
+
* Neo.overwrites = {
329
+
* Neo: {
330
+
* button: {
331
+
* Base: {
332
+
* labelPosition: 'top'
333
+
* }
334
+
* }
335
+
* }
336
+
* };
337
+
*
338
+
* // Now, every `Neo.button.Base` (and any class that extends it) will have this
339
+
* // new default value on its prototype.
340
+
*
341
+
* @param {Object} cfg The static `config` object of the class being processed.
0 commit comments