StorageItem

StorageItem

Class meant to facilitate communication with the local storage.

The methods support chaining.

Constructor

new StorageItem(key)

Source:

Create an instance of a storage item, getting its contents from the local storage. In case of an unexistent/falsy/corrupt value or the storage inaccessible, set an empty object.

To reload the contents of the storage item after an idle period, run StorageItem#reload. Note that the user may interact with the storage in other tabs.

Parameters:
Name Type Description
key string

Local storage Item key (will be prepended by StorageItem.prefix).

Members

prefix :string

Source:

Prefix added to the name of the storage item.

Type:
  • string

Methods

cleanUp(removeCondition) → {StorageItem}

Source:

Clean up entries (e.g. old ones), if callback returns true for an entry.

Parameters:
Name Type Description
removeCondition function
Returns:
Type
StorageItem

get(key) → {*}

Source:

Get an entry of the storage item by key.

Parameters:
Name Type Description
key string
Returns:
Type
*

getAll() → {*}

Source:

Get all entries in the storage item.

Returns:
Type
*

reload() → {StorageItem}

Source:

Get the contents of the storage item and set it to the instance. In case of an unexistent/falsy/corrupt value or the storage inaccessible, set an empty object.

Run this every time you use the storage after an idle period: the user may interact with the storage in other tabs in the same time frame.

Returns:
Type
StorageItem

remove(key) → {StorageItem}

Source:

Remove an entry of the storage item.

Parameters:
Name Type Description
key string
Returns:
Type
StorageItem

removeItem() → {StorageItem}

Source:

Delete the entire item from the storage.

Returns:
Type
StorageItem

save() → {StorageItem}

Source:

Save the data to the storage item.

Returns:
Type
StorageItem

set(key, value) → {StorageItem}

Source:

Set an entry of the storage item.

Parameters:
Name Type Description
key string
value *
Returns:
Type
StorageItem

setWithTime(pageKey, pageData) → {StorageItem}

Source:

Update a storage entry by page key (be it an article ID or page name): set and add a UNIX time.

Parameters:
Name Type Description
pageKey string
pageData *
Returns:
Type
StorageItem