Menu
©2015
Documentation generator: JsDoc Toolkit 2.4.0
Template: Codeview 1.2
Generated on: 2015-1-16 18:32

Class puredom.LocalStorage

Class Summary
Constructor Attributes Constructor Name and Description
 
puredom.LocalStorage(id, options, callback)
Provides a cross-browser persisted storage layer using various storage adapters.
Field Summary
Field Attributes Field Name and Description
 
The maximum number of milliseconds to wait before committing data to the persistence layer.
 
get
Alias of {puredom.LocalStorage#getValue}
 
Alias of {puredom.LocalStorage#removeKey}
 
set
Alias of {puredom.LocalStorage#setValue}

Method Summary

Method Attributes Method Name and Description
<static>  
puredom.LocalStorage. addAdapter (name, adapter)
Register a storage adapter.
 
commit (callback)
Save the collection immediately using the active persistence adapter.
 
Get the name of the active adapter.
 
getData ()
Get the full data object.
 
Get a namespaced facade of the LocalStorage interface.
 
getValue (key)
Get the stored value corresponding to a dot-notated key.
<static>  
puredom.LocalStorage. NamespacedLocalStorage ()
A namespaced facade of the LocalStorage interface.
 
purge ()
Remove all keys/values in the collection.
 
removeKey (key)
Remove a key and (its stored value) from the collection.
 
restore (callback)
Restore the collection from its persisted state.
 
setAdapter (type)
Specify the name of a storage adapter the instance should use.
 
setValue (key, value)
Set the stored value corresponding to a dot-notated key.
 
Load whichever adapter works best in the current environment.

Class Detail

puredom.LocalStorage(id, options, callback)
Provides a cross-browser persisted storage layer using various storage adapters.
Parameters:
{String} id
Required identifier for the specific storage instance.
{Object} options Optional
Hashmap of available config options (see description)
{Object} options.adapter Optional, Default: auto
Attempt to use a specific adapter. If unset, the best adapter is automatically used (useBest=true).
{Object} options.useBest Optional, Default: true
Attempt to use the best adapter available, unless an adapter is manually specified and loads successfully.
{Object} options.restore Optional, Default: true
Attempt to restore the data immediately.
{Function} callback Optional
Gets passed a reference to the instance after the initial restore() has completed.

Field Detail

commitDelay
The maximum number of milliseconds to wait before committing data to the persistence layer.
get
Alias of {puredom.LocalStorage#getValue}
remove
Alias of {puredom.LocalStorage#removeKey}
set
Alias of {puredom.LocalStorage#setValue}

Method Detail

  • <static> puredom.LocalStorage.addAdapter(name, adapter)
    Register a storage adapter.
    Parameters:
    {String} name
    A name for the adapter. Used by puredom.LocalStorage#setAdapter and puredom.LocalStorage#getAdapter.
    {Object} adapter
    The adapter itself.
  • {this} commit(callback)
    Save the collection immediately using the active persistence adapter.
    This bypasses the default "delayed write" save technique that is implicitly used when interacting with other methods.
    Parameters:
    {Function} callback
    Gets called when the commit has completed, passed a reference to the instance.
    Returns:
    {this}
  • {String} getAdapter()
    Get the name of the active adapter.
    Returns:
    {String} The curernt adapter's name
  • {Object} getData()
    Get the full data object.
    Returns:
    {Object} data
  • Get a namespaced facade of the LocalStorage interface.
    Tip: This is a nice way to reduce the number of commits triggered by a large application, because all namespaces derived from a single LocalStorage instance share the same commit queue.
    Parameters:
    {String} ns
    A namespace (prefix) to use. Example: "model.session"
    Returns:
    {puredom.LocalStorage.NamespacedLocalStorage} An interface identical to puredom.LocalStorage.
  • getValue(key)
    Get the stored value corresponding to a dot-notated key.
    Parameters:
    {String} key
    A key, specified in dot-notation.
    Returns:
    If key exists, returns the corresponding value, otherwise returns undefined.
  • <static> puredom.LocalStorage.NamespacedLocalStorage()
    A namespaced facade of the LocalStorage interface.
  • {this} purge()
    Remove all keys/values in the collection.
    Returns:
    {this}
  • {this} removeKey(key)
    Remove a key and (its stored value) from the collection.
    Parameters:
    {String} key
    A key, specified in dot-notation.
    Returns:
    {this}
  • {this} restore(callback)
    Restore the collection from its persisted state.
    Parameters:
    {Function} callback
    Gets called when the restore has completed, passed a reference to the instance.
    Returns:
    {this}
  • {Boolean} setAdapter(type)
    Specify the name of a storage adapter the instance should use.
    Note: Pay attention to the return value! Even if you know a given adapter exists, it may fail to load if it is not supported in the current environment (eg: if window.localStorage doesn't exists, cookies are blocked, etc).
    Parameters:
    {String} type
    The name of an adapter to use. For a list, see puredom.LocalStorage.adapters
    Returns:
    {Boolean} true if the adapter loaded successfully, false if the specified adapter did not exist or could not be loaded.
  • {this} setValue(key, value)
    Set the stored value corresponding to a dot-notated key.
    If the key does not exist, it is created.
    Parameters:
    {String} key
    A key, specified in dot-notation.
    {Any} value Optional
    The value to set. If an {Object} or {Array}, its internal values become accessible as dot-notated keys. If null or undefined, the key is removed.
    Returns:
    {this}
  • useBestAdapter()
    Load whichever adapter works best in the current environment.
    This is determined by querying each adapter to check which are supported, then selecting the best based on a pre-determined "score", as reported by the adapter.
    Note: This method throws a delayed error (does not stop execution) if no adapters are supported in the current environment.