Class: ConfigurationManager

mmir. ConfigurationManager

A class for managing the configuration.
It's purpose is to load the configuration and settings automatically. This "class" is structured as a singleton - so that only one instance is in use.

Requires

  • module:mmir.require

Methods

addListener(propertyName, listener, emitOnAdding)

Register listener for configuration changes.
Name Type Description
propertyName String | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be invoked on all configuration changes. If propertyName is an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g. some.property will be resolved so that the value will set to: some: {property: <value>}
listener function the listener function that will be invoked when a configuration value is changed:
listener(newValue: any, oldValue: any, propertyName: string[])
where propertyName is the list of property-name path components (the last component is the property name itself) NOTE: if parameter propertyName was not specified, the third argument for the listener will be invoked with an empty Array.
emitOnAdding Boolean optional OPTIONAL if true the listener will be immediately be invoked after adding it with the current value
listener(newValue: , oldValue: undefined, propertyName: )
NOTE: can only be used when param propertyName is specified.
See:

get(propertyName, defaultValue, setAsDefaultIfUnset){any}

Returns the value of a property.
Name Type Description
propertyName String | Array.<String> if String: The name of the property. NOTE: If the property does not exists at the root-level, dot-separated names will be resolved into object-structures, e.g. some.property will be resolved so that the value at: some: {property: <value>} will be returned if String array: each entry corresponds to component in a dot-separated path (see above)
defaultValue any optional OPTIONAL a default value that will be returned, in case there is no property propertyName.
setAsDefaultIfUnset Boolean optional OPTIONAL if true, and there is no value set yet for propertyName, then the specified defaultValue will be set for propertyName.
DEFAULT: false
NOTE: if this argument is used, param defaultValue must also be given!
See:
Returns:
Type Description
any The value of the property
Uses get. If the propertyName does not exists, returns undefined, otherwise values will be converted into Boolean values. Special case for Strings: the String "false" will be converted to Boolean value false.
Name Type Description
defaultValue any optional OPTIONAL if a default value is specified and there exists no property propertyName, the specified default value will be returned. NOTE: the default value will also be converted to a Boolean value, if necessary.
See:
Uses get. If the property does not exists, returns undefined, otherwise values will be converted into Number values. If the value has not the type "string", it will be converted by JSON.stringify.
Name Type Description
defaultValue any optional OPTIONAL if a default value is specified and there exists no property propertyName, the specified default value will be returned. NOTE: the default value will also be converted to a Number value, if necessary.
See:
Uses get. If the property does not exists, returns undefined, otherwise values will be converted into String values. If the value has not the type "string", it will be converted by JSON.stringify.
Name Type Description
defaultValue any optional OPTIONAL if a default value is specified and there exists no property propertyName, the specified default value will be returned. NOTE: the default value will also be converted to a String value, if necessary.
See:
Initialize the configuration manager (i.e. loading configuration data etc.)
Name Type Description
forceReloadConfig Boolean optional OPTIONAL if FALSY, configuration data will only be loaded, if it has not been loaded yet. If TRUTHY, configuration data will be reloaded regardless, wether it is already available or not.
Returns:
Type Description
Promise a deferred promise that gets fulfilled when initialization is completed.

off(propertyName, listener){boolean}

Remove listener for configuration changes: if listener was registered multiple times, the first one is removed.
Name Type Description
propertyName String | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be removed from list of listeners for all configuration changes, otherwise it will be removed from listeners for the specified property-path.
listener function the listener function that will be invoked when a configuration value is changed:
listener(newValue: any, oldValue: any, propertyName: string)
See:
Returns:
Type Description
boolean true if a listener was removed, otherwise false.

on(propertyName, listener, emitOnAdding)

Register listener for configuration changes.
Name Type Description
propertyName String | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be invoked on all configuration changes. If propertyName is an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g. some.property will be resolved so that the value will set to: some: {property: <value>}
listener function the listener function that will be invoked when a configuration value is changed:
listener(newValue: any, oldValue: any, propertyName: string[])
where propertyName is the list of property-name path components (the last component is the property name itself) NOTE: if parameter propertyName was not specified, the third argument for the listener will be invoked with an empty Array.
emitOnAdding Boolean optional OPTIONAL if true the listener will be immediately be invoked after adding it with the current value
listener(newValue: , oldValue: undefined, propertyName: )
NOTE: can only be used when param propertyName is specified.
See:

removeListener(propertyName, listener){boolean}

Remove listener for configuration changes: if listener was registered multiple times, the first one is removed.
Name Type Description
propertyName String | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be removed from list of listeners for all configuration changes, otherwise it will be removed from listeners for the specified property-path.
listener function the listener function that will be invoked when a configuration value is changed:
listener(newValue: any, oldValue: any, propertyName: string)
See:
Returns:
Type Description
boolean true if a listener was removed, otherwise false.

set(propertyName, value){any}

Sets a property to a given value.
Name Type Description
propertyName String | Array.<String> The name of the property. If propertyName is an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g. some.property will be resolved so that the value will set to: some: {property: <value>}
value any The value of the property
See:
Throws:
if the propertyName is dot-separated AND one of its path-elements (except for the last) already exists AND its type is not 'object'
Type
Error
Returns:
Type Description
any The newly set value for the property
See: