Base
Abstract
Base class for all configurable classes.
Subclasses do not have to implement a constructor with its restriction of having to call super() before there is a this reference. Subclasses instead implement a construct method which is called by the Base constructor. This may call its super implementation at any time.
The Base constructor applies all configs to properties of the new instance. The instance will have been configured after the super.construct(config) is called.
See the Class System documentation in the guides for more information.
Properties
Properties are getters/setters or publicly accessible variables on this class-
A class property getter for the configuration properties of the class, which can be overridden by configurations passed at construction time.
Unlike a normal
staticproperty, this property is only ever used for the class that defines it (as in,hasOwnProperty). It is retrieved for all classes in a class hierarchy, to gather their configs individually and then combine them with those of derived classes.For example, a
Labelmight declare atextconfig like so:class Label extends Base { static configurable = { text : null }; }The
textconfig is automatically inherited by classes derived from Label. By implementingget configurable(), derived classes can change the default value of inherited configs, or define new configs, or both.When a config property is declared in this way, the class author can also implement either of two special methods that will be called when the config property is assigned a new value:
changeText()updateText()
In the example above, the
Labelclass could implement achangeText()method, anupdateText()method, or both. The generated property setter ensures these methods will be called when thetextproperty is assigned.The generated setter (for
textin this example) performs the following steps:- If the class defines a
changeText()method, call it passing the new value and the current value:changeText(newText, oldText).
Then:- If
changeText()exits without returning a value (i.e.,undefined), exit and do nothing further. The assumption is that the changer method has done all that is required. - Otherwise, the return value of
changeText()replaces the incoming value passed to the setter.
- If
- If the new value (or the value returned by
changeText()) is!==to the current value:- Update the stored config value in
this._text. - If the class defines an
updateText()method, call it passing the new value and the previous value.updateText(newText, oldText)
- Update the stored config value in
Resolving a value from an owner
By specifying a value starting with
'up.'for a config, the config system will resolve that value by examining the ownership hierarchy. It will walk up the hierarchy looking for a property matching the name (or dot separated path) after 'up.'. If one is found, the value will be read and used as the initial value.class Parent extends Base { static get configurable() { return [ 'importantValue' ] } } class Child extends Base { static get configurable() { return [ 'value' ] } } const parent = new Parent({ importantValue : 123 }); const child = new Child({ owner : parent, // Will be resolved from the owner value : 'up.importantValue' }); console.log(child.value); // logs 123Please note that this is for now a one way one time binding, the value will only be read initially and not kept up to date on later changes.
Value Merging
When a config property value is an object, the value declared by the base class is merged with values declared by derived classes and the value passed to the constructor.
class Example extends Base { static configurable = { config : { foo : 1, bar : 2 } }; } class Example2 extends Example { static configurable = { config : { bar : 42, zip : 'abc' } }; } let ex = new Example2({ config : { zip : 'xyz' } });The result of the merge would set
configto:ex.foo = { foo : 1, // from Example bar : 42, // from Example2 zip : 'xyz' // from constructor }Config Options
Some config properties require additional options such as declarative information about the config that may be useful to automate some operation. Consider a
Button. It could declare that itstextconfig affects the rendered HTML by applying arenderproperty to the config definition. Its base class could then examine the config definition to find this property.To support this, config options ca be declared like so:
class Button extends Widget { static configurable = { text : { value : null, $config : { render : true } } }; }The
$configproperty can alternatively be just the names of the options that should be enabled (set totrue).For example, the following is equivalent to the above:
class Button extends Widget { static configurable = { text : { value : null, $config : 'render' } };Default Value
It is common to set a config to a
nullvalue to take advantage of internal optimizations fornullvalues. In most cases the fact that this producesundefinedas the actual initial value of the config is acceptable. When this is not acceptable, a config can be declared like so:class Widget { static configurable = { disabled : { $config : null, value : null, default : false } };The
defaultproperty above determines the value of the config while still gaining the benefits of minimal processing due to thenullvalue of thevalueproperty. -
A class property getter to add additional, special class properties.
For example, a class adds a
declarableclass property like so:class Something extends Base { static get declarable() { return ['extra']; } static setupExtra(cls, meta) { // use cls.extra } }A derived class can then specify this property like so:
class Derived extends Something { static get extra() { // return extra information } }When the
Derivedclass is initialized, thesetupExtra()method is called andDerivedis passed as the argument. It is also thethispointer, but the parameter is minifiable. The second argument passed is the$metaobject for the class.Classes are initialized at the first occurrence of the following:
- An instance is created
- The class
$metaproperty is accessed
-
A legacy class property getter for the default configuration of the class, which can be overridden by configurations passed at construction time. We recommend using
configurableinstead.Unlike a normal
staticproperty, this property is only ever used for the class that defines it (as in,hasOwnProperty). It is retrieved for all classes in a class hierarchy, to gather their configs individually and then combine them with those of derived classes.For example, a
Storemight declare itsurlconfig like so:class Store extends Base { static get defaultConfig() { return { url : null }; } }The
urlconfig is automatically inherited by classes derived from Store. By implementingget defaultConfig(), derived classes can change the default value of inherited configs, or define new configs, or both. When defining new configs, however,configurableis preferred.Config properties introduced to a class by this declaration do not participate in value merging and do not get a generated setter. Config properties introduced by a base class using
configurablecan be set to a different value usingdefaultConfigand in doing so, the values will be merged as appropriate forconfigurable. -
A class property getter for the default values of internal properties for this class.
-
An object owned by this class that does not share properties with its super class. This object may contain other properties which are added as needed and are not documented here.
- class : Function
The class constructor that owns the meta object
- super : Object
The
$metaobject for the super class. This isnullforBase - config : Object
The object holding the default configuration values for this class
- configs : Object
An object keyed by config name that holds the defined configs for the class The value of each property is a Config instance
- forkConfigs : Boolean
This will be
trueif the default configuration values for this class (in theconfigproperty of the meta object) must be forked to avoid object sharing, or if the object can be passed toObject.create()for efficiency - hierarchy : Function[]
The array of classes in the ancestry of this class. This will start with
Baseat index 0 and ends with this class - properties : Function[]
The array of classes that define a "static get properties()" getter
- class : Function
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueby destroy after destruction.It is also one of the few properties that remains on the object after returning from
destroy(). This property is often checked in code paths that may encounter a destroyed object (like some event handlers) or in the destruction path during cleanup. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed).
Functions
Functions are methods available for calling on the class-
Determines if the specified config property exists in an instance of Base
-
Returns the merge of the
baseConfigandconfigconfig objects based on the configs defined by this class. -
Factory version of the Base constructor. Merges all arguments to create a config object that is passed along to the constructor.
-
This optional class method is called when a class is mixed in using the mixin() method.
-
Merges the provided default configuration values with the existing defaults for this class (and its subclasses).
This method allows you to define additional or override existing default property values that apply to all instances of the class.
// All my input fields should be clearable Field.applyDefaults({ clearable : true }); -
Gets the full defaultConfig block for this object's entire inheritance chain all the way up to but not including Base
-
This method is called as part of
setupClass(). It will process theconfigurable()return object and thedefaultConfigreturn object. -
Destroys the provided objects by calling their destroy method. Skips empty values or objects that are already destroyed.
Base.destroy(myButton, toolbar1, helloWorldMessageBox); -
Registers this class type with its Factory
-
Checks if an obj is of type using object's $name property and doing string comparison of the property with the type parameter.
-
Applies one or more
mixinsto this class and returns the produced class constructor.For example, instead of writing this:
class A extends Delayable(Events(Localizable(Base))) { // ... }Using this method, one would write this:
class A extends Base.mixin(Localizable, Events, Delayable) { // ... }If one of the mixins specified has already been mixed into the class, it will be ignored and not mixed in a second time.
-
This method is called only once for any class. This can occur when the first instance is created or when the
$metaobject is first requested.
-
Base constructor, passes arguments to construct.
-
This method is required to help
unusedgetters to survive production build process. Some tools, like angular, will removeunusedcode in production build, making our side-effected getters behind, breaking code heavily. -
Creates a binding between the specified config properties of this object and the specified
targetobject. Changes to these config properties of this object will be reflected to thetargetobject as they occur, and (optionally), vise-versa.Returns a function to call to remove the binding.
-
Delays the execution of the passed function by the passed time quantum, or if the time is omitted or not a number, delays until the next animation frame. Note that this will use setTimeout || requestAnimationFrame if this class mixes in
Delayable, otherwise it uses the global methods. The function will be called usingthisobject as its execution scope. -
Returns
trueif this instance has a non-null value for the specified config. This will not activate a lazy config. -
Returns the value of an uningested config without ingesting the config or transforming it from its raw value using its
changeXxxxxmethod. -
Tracks a detacher function for the specified listener name.
-
Ensures that the specified config is initialized if it is needed. If there is a config value specified, and it was initialized by this call, this method returns
true. If there was a config value specified, and it was already initialized, this method returnsfalse. If there was no value specified for the given config, this method returnsnull.This is not the same as just reading the property, because some property getters exist that do not actually just read the config value back, but instead produce some result. Reading such properties to incidentally trigger a possible config initializer can lead to incorrect results. For example, the Combo items config.
-
This call will activate any pending lazy configs that were assigned a string value equal to the
groupparameter. -
Removes all detacher functions for the specified
Eventsobject. This is called by theremoveAllListenersmethod on that object which is typically called by itsdestroyinvocation. -
This is intended to set a block of configs during configuration. It is not intended to be used outside of the configuration phase.
If any of the properties are not yet ingested from the configuration object, they will be set and ingested in the normal order.
Properties which are already ingested are set immediately.
-
Used by the Widget and GridFeatureManager class internally. Returns the class hierarchy of this object starting from the
topClassclass (which defaults toBase).For example
classHierarchy(Widget)on a Combo would yield[Widget, Field, TextField, PickerField, Combo] -
Returns the value of the specified config property. This is a method to allow property getters to be explicitly called in a way that does not get optimized out.
The following triggers the getter call, but optimizers will remove it:
inst.foo; // also raises "expression has no side-effects" warningInstead, do the following to trigger a getter:
inst.getConfig('foo'); -
Gets the full defaultConfig block for the entire inheritance chain for this class all the way up to but not including Base
-
Gets the full properties block for this class's entire inheritance chain all the way up to but not including Base
-
This method is called when any config changes.
-
Removes all event listeners that were registered with the passed names.
-
afterConfigure( )internal
Base implementation so that all subclasses and mixins may safely call
super.afterConfigure. This is called by the Base class after the configure method has been called. At this point, all configs have been applied.This method allows all classes in the hierarchy to inject functionality either before or after the super.afterConstruct();
-
afterConstruct( )internal
Base implementation so that all subclasses and mixins may safely call super.afterConstruct.
This is called by the Base class after the construct method has been called.
At this point, all configs have been applied.
This method allows all classes in the hierarchy to inject functionality either before or after the super.afterConstruct();
-
Called by the Base constructor to apply configs to this instance. This must not be called.
-
Base implementation applies configuration.
Subclasses need only implement this if they have to initialize instance specific properties required by the class. Often a
constructmethod is unnecessary. All initialization of incoming configuration properties can be done in aset propNameimplementation. -
destroy( )
Destroys this object.
This is primarily accomplished by calling doDestroy, however, prior to callingdoDestroy, isDestroying is set totrue. After doDestroy returns, isDestroyed is set totrue.Do not override this method in subclasses. To provide class-specific cleanup, implement doDestroy instead.
-
Destroys the named properties if they have been initialized, and if they have a
destroymethod. Deletes the property from this object. For example:this.destroyProperties('store', 'resourceStore', 'eventStore', 'dependencyStore', 'assignmentStore'); -
doDestroy( )ADVANCED
Classes implement this method to provide custom cleanup logic before calling
super.doDestroy(). The general pattern is as follows:class Foo extends Base { doDestroy() { // perform custom cleanup super.doDestroy(); } }This method is called by destroy which also prevents multiple calls from reaching
doDestroy. Prior to callingdoDestroy, isDestroying is set totrue. Upon return, the object is fully destructed and isDestroyed is set totrue.Do not call this method directly. Instead call destroy.
-
finishConfigure( )internal
Base implementation so that all subclasses and mixins may safely call super.finishConfigure.
This is called by the Base class before exiting the configure method.
At this point, all configs have been applied, but the
isConfiguringproperty is still set.This method allows all classes in the hierarchy to inject functionality into the config phase.
-
Sets configuration options this object with all the properties passed in the parameter object. Timing is taken care of. If the setter of one config is called first, and references the value of another config which has not yet been set, that config will be set just in time, and the new value will be used.
-
startConfigure( )internal
Base implementation so that all subclasses and mixins may safely call super.startConfigure.
This is called by the Base class before setting configuration properties, but after the active initial getters have been set, so all configurations are available.
This method allows all classes in the hierarchy to force some configs to be evaluated before others.
-
animateProperty( propertyName, newValue, duration1000, easing'linear' )
Changes the value of a numeric property of this object smoothly over the specified duration.
-
Provides a way of calling callbacks which may have been specified as the name of a function and optionally adds scope resolution.
For example, if the callback is specified as a string, then if it is prefixed with
'this.'then the function is resolved in this object. This is useful when configuring listeners at the class level.If the callback name is prefixed with
'up.'then the ownership hierarchy is queried using theownerproperty until an object with the named function is present, then the named function is called upon that object.If a named function is not found, an error is thrown. If the function should be only called when present, and may not be present, add a
?as a suffix. -
Experimental helper function, extracts the currently used configs and wraps them as an app, downloading the resulting JS file.
This function is intended to simplify creating test cases for issue reporting on Bryntum's support forum.
-
Provides a way of locating callbacks which may have been specified as the name of a function and optionally adds scope resolution.
For example, if the callback is specified as a string, then if it is prefixed with
'this.'then the function is resolved in this object. This is useful when configuring listeners at the class level.If the callback name is prefixed with
'up.'then the ownership hierarchy is queried using theownerproperty until an object with the named function is present, then the named function is called upon that object.