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.

Inline / per-instance configuration

1
// Unit configuration
2
const aUnit = new GenericUnit({cacheSize: 10, immutable: true, persistent: true})
3
​
4
// Action configuration
5
const anAction = new Action({initialValue: 'START'})
6
​
7
// AsyncSystem configuration
8
const anAsyncSystem = new AsyncSystem({
9
freezeQueryWhilePending: true,
10
11
// it overrides AsyncSystem's member Units' config
12
// it applies to all three GenericUnits and one BoolUnit
13
UNITS: {cacheSize: 3},
14
15
// it overrides common UNITS config above, applies to dataUnit only
16
DATA_UNIT: {cacheSize: 4}
17
})
Copied!

Global configuration

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.
1
Configuration.set({
2
// it overrides default Action config
3
ACTION: {replay: true},
4
5
// it overrides default Unit config, for all Unit types
6
UNITS: {cacheSize: 1},
7
8
// it overrides global UNITS config above, for GenericUnits
9
GENERIC_UNIT: {cacheSize: 2},
10
11
ASYNC_SYSTEM: {
12
// it overrides global UNITS, GENERIC_UNIT, and BOOL_UNIT config
13
// it applies to AsyncSystem's three GenericUnits and one BoolUnit
14
UNITS: {cacheSize: 3},
15
16
// it overrides global ASYNC_SYSTEM.UNITS config above, for dataUnit
17
DATA_UNIT: {cacheSize: 4}
18
}
19
});
Copied!

Hierarchy of configuration

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
​
​
​

Notes

  • 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.