Dictionary engine

klevu.extend( target [, object1 ] [, objectN ] )
Returns: Object

Description:  The dictionary engine is the one used by multiple other engines to hold and retrieve data in a key/value format.

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 – fines a storage for engine for the storage of the global elements of the dictionary – supports object storage(default) , session(for browser session Storage), local(for browser local Storage) and cookie storage. Accepts second parameter(Boolean) as fallback in case first storage is not supported by browser to use cookies.

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.

Example of using dictionary by setting an element to a dictionary and then retrieving it from another instance of the same dictionary:

var testDictionary = klevu.dictionary("test");
    testDictionary.getElements(); // {}
    testDictionary.addElement("test","testing");
    testDictionary.mergeToGlobal();
    testDictionary.getGlobal(); // {test: "testing"}
    testDictionary.getElements(); // {test: "testing"}
var testNewDictionary = klevu.dictionary("test")
    testNewDictionary.getElements(); // {}
    testNewDictionary.getGlobal(); //  {test: "testing"}
    testNewDictionary.mergeFromGlobal();
    testNewDictionary.getElements(); // {test: "testing"}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>