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: