Configuration
ActiveJS tries to give as many configuration options as possible to allow some degree of customization and personalization. While not requiring any configuration by choosing the most sensible defaults.
Configuration can be done on many levels, it can be done per instance and it can also be done globally.
// Unit configuration
const aUnit = new GenericUnit({cacheSize: 10, immutable: true, persistent: true})
// Action configuration
const anAction = new Action({initialValue: 'START'})
// AsyncSystem configuration
const anAsyncSystem = new AsyncSystem({
freezeQueryWhilePending: true,
// it overrides AsyncSystem's member Units' config
// it applies to all three GenericUnits and one BoolUnit
UNITS: {cacheSize: 3},
// it overrides common UNITS config above, applies to dataUnit only
DATA_UNIT: {cacheSize: 4}
})
ActiveJS exposes a global class called Configuration, through which you can set and reset global config that overrides default configuration. Which can still be overridden by inline config.
To set the global config you can use the
set
method, it accepts a configuration object of type GlobalConfig.Configuration.set({
// it overrides default Action config
ACTION: {replay: true},
// it overrides default Unit config, for all Unit types
UNITS: {cacheSize: 1},
// it overrides global UNITS config above, for GenericUnits
GENERIC_UNIT: {cacheSize: 2},
ASYNC_SYSTEM: {
// it overrides global UNITS, GENERIC_UNIT, and BOOL_UNIT config
// it applies to AsyncSystem's three GenericUnits and one BoolUnit
UNITS: {cacheSize: 3},
// it overrides global ASYNC_SYSTEM.UNITS config above, for dataUnit
DATA_UNIT: {cacheSize: 4}
}
});
The more specific a configuration the higher precedence it has.
Given the global config type interface GlobalConfig.
This is how the precedence order works, going from lowest to highest precedence.
Units | AsyncSystem | Action | Cluster |
Default config | Default config | Default config | Default config |
GlobalConfig > UNITS | GlobalConfig > ASYNC_SYSTEM | GlobalConfig > ACTION | GlobalConfig > CLUSTER |
Type-specific Unit config e.g. GlobalConfig > DICT_UNIT | Inline config | Inline config | Inline config |
GlobalConfig > ASYNC_SYSTEM > UNITS | | | |
Unit specific config e.g. GlobalConfig > ASYNC_SYSTEM > UNITS > DATA_UNIT or GlobalConfig > ASYNC_SYSTEM > UNITS > QUERY_UNIT | | | |
Inline config | | | |
- In a Single Page App, you should set global configuration only once, and override it in the inline config if needed. Otherwise, it can become very difficult to keep track of which instances are using what configuration, depending on their time of creation.
- If you do need to change global configuration multiple times, just keep in mind that calling
Configuration.set
second time doesn't merge the new configuration with the old one it simply rewrites it. However, the defaults are not affected by this behavior, they have to be overridden specifically every time.
Last modified 2yr ago