Dictionary Engine
The dictionary engine is the one used by multiple other engines to hold and retrieve data in a key/value format.
- Translation Engine
- Currency Engine
- Cache Engine
Available interfaces:
- getGlobal – gets the global stored elements
- mergeToGlobal – retrieves the elements from local and merges them into the global storage elements
- overrideGlobal – retrieves the elements from local and overrides them into the global storage elements
- mergeFromGlobal – retrieves the elements from storage and merges them into the local storage elements
- setElements – calls addElement for a list of elements to be added
- getElements – gets all elements
- resetElements – resets all elements(deletes local elements)
- getElement – gets one value for a given key of a element
- addElement – adds to local dictionary a element in the key value format
- setStorage – defines a storage for engine for the storage of the global elements of the dictionary
The dictionary is a key-value implementation that can retrieve a value for a specific key of string or number type. The key has to be unique within the scope of the generated dictionary. If same key is added it will override the local storage element that has that key.
The scope is defined by the name given on generation. The scope is only taken in consideration when interacting with the global storage of the dictionary , local storage per element can differ from one instance to another of a dictionary that is part of same scope.
Any local change can be pushed to the global storage via the interfaces provided. Any other instance with the same scope will need to merge those changes into there local storage as needed.
Using dictionary by setting an element to a dictionary and then retrieving it from another instance of the same dictionary:
Sets the dictionary engine storage types for its global scope.
- storage – keyword for the storage used
- fallback – Boolean – optional – use cookie storage as fallback if using required storage is not supported.
Current supported storage engines are:
- object - Default
- local – Uses browser local storage
- session – Uses browser session storage
- cookies – Uses browser cookies , persistent across session
- cookiesSession – Uses browser cookies , only for current session session
Setting a storage will also retrieve all data from the storage on the global scope. As a example if the global scope is empty but the dictionary data has been saved in the local storage previously:
Used to retrieve the values directly from the global scope.
The values retrieved will still belong to the global scope and not will be part of the local scope. For example consider that global is {test: “test”} :
Used to retrieve the values from the global scope and merge it over the local scope.
If a key is already present in the local scope with a different value it will be overridden by the value in the global scope.
The currency engine is an implementation of the dictionary engine refer to the dictionary docs for an in-depth view.
The map of a currency element, with defaults:
- atEnd: false – controls if the symbol is after the value
- code: “<string>” – same as the global name
- decimal: “.” – symbol to be used in the decimal place
- format: “%s%s” – the format of the currency, can only contain 2 elements
- grouping: 3 – thousand decimal grouping
- precision: 2 – rounding on x decimal
- string: “<symbol>” – the symbol to be used for the currency
- thousand: “,” – symbol to be used in the thousand place
Specific functions for the engine:
- addCurrency – used to add a single currency object – addCurrency : function ( Code , Map )
- setCurrencies – used to set a list of currencies
- processCurrency – retrieves the string of the formatted value in the selected currency code – processCurrency : function ( code , value )
All of the Dictionary engine interfaces are available on the Currency engine
The translator engine is an implementation of the dictionary engine refer to the dictionary docs for an in-depth view
The translator engine is used to group a specific language and the currency engine used in that language.
Specific functions for the engine:
- translate – used to reverse check a string from the dictionary, the original string is returned if no string matches dictionary. Accepts parameters to be used as format strings –
- example: translate(“I have found %s Products”,5) would return “I have found 5 Products”
- getCurrencyObject – retrieves the currency object for the translation object.
All of the Dictionary engine interfaces are available on the Translator engine.
Stores a key-value map ,the engine keys do not have to be of string type but can be any object , similar to MAP
Any value (both objects and primitive values) may be used as either a key or a value. The engine is used to store individual query request/response.
The scope of the cache is always global and will be shared by all implementations of the cache engine.
- getCache – retrieves a value for a given key object
- hasCache – checks if a given key object has a value
- setCache – sets a key/value map to the cache engine
- getAllCache – get all cache objects
.