Options: System Wide Defaults
What are we learning here?
ββββββββββββββββ
β Change β
β Options β
βββββββββ¬βββββββ
ββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββ
β Loading β β Component β β
β Component β β β β
β ββββββββββββ β β ββββββββββββββββββββ ββββββΌβββββ β
β β options βββΌββΌβββTransformβββββββββββββΊβ Received Options ββββΊβ Final β β
β ββββββββββββ β β (optional) ββββββββββ²ββββββββββ β Options β β
β β β Merge ββββββ€βββββ β
β ββββββββββββ β β βββββββββββββββββββββ ββββββββββ΄ββββββββββ ββββββΌβββββ β
ββββββββββββββββ β β settings βββΌββΌβΊβ Received Settings ββββΊβ Merged Settings β β ! Watch β β
β Parent β β ββββββββββββ β β ββββββββββββ²βββββββββ ββββββββββ²ββββββββββ βββββββββββ β
β Component β ββββββββββββββββ β Merge Merge β
β ββββββββββββ β β ββββββββββββ΄βββββββββ β β
β β Received βββΌβββββββββββββββββββΌβΊβ Parent Settings β β β
β β Settings β β β βββββββββββββββββββββ β β
β ββββββββββββ β β β β
ββββββββββββββββ β βββββββββββββββββββββ ββββββββββ΄ββββββββββ β
β β Static Defaults ββββΊβ Merged Defaults β β
β ββββββββββββ²βββββββββ ββββββββββββββββββββ β
β Merge β
ββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββΌβββββββββββ
β Base Component β
β ββββββββββββ΄βββββββββ β
β β Static Defaults β β
β ββββββββββββ²βββββββββ β
βββββββββββMergeβββββββββ
ββββββββββββββΌβββββββββββ
β Base Component β
β ββββββββββββ΄βββββββββ β
β β Static Defaults β β
β βββββββββββββββββββββ β
βββββββββββββββββββββββββ
- Set defaults for the whole system or parts of it
You have two options to pass overriding options. We just got to know the first alternative. The options are passed using the load method. Either in the short version:
Or per start definition object:
The second one can only be done per start definition object. The property you have to use is
settings. This would look like:
The "settings" have a very special meaning because they are used for the component to be loaded and all other child components loaded by this component. Settings are valid for the entire component hierarchy from this point on.
Since we call the complete component hierarchy βsystemβ, settings can therefore define so-called βsystem wide defaultsβ or sometime just "partial system wide defaults".
There are several useful applications for system wide defaults. One of them, for example, is the authentication mechanism, which is set in the root component and can be used by every component. More on that later.
Each application can set any settings that are adopted in all defaults. And that's why you should be careful not to pollute the root level.
As a best practice you should either use your own namespace or put individual properties in the
designated key $globals:
// Use the $globals key:
this.load({
component: YourComponent,
settings: {
$globals: {
yourGlobalThing: something
}
}
})
// Access the global somewhere later:
this.options.$globals.yourGlobalThing;
To change the own "setting" which should propagated to all child component you can use the setter
this.env.settings. It works like the setter this.options which merge all properties to the
existing ones: