elementDataStore

dom-utils~ elementDataStore

Source:

Adapted from https://stackoverflow.com/a/46522991/3071529

A storage solution aimed at replacing jQuerys data function. Implementation Note: Elements are stored in a (WeakMap)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap]. This makes sure the data is garbage collected when the node is removed.

Members

(static) _storage :WeakMap

Source:
Type:
  • WeakMap

Methods

(static) get(element, key) → {object}

Source:

Return object from element storage.

Parameters:
Name Type Description
element Node

target element

key string

name of the stored data

Returns:

stored data object

Type
object

(static) has(element, key) → {boolean}

Source:

Checkes whether element has given storage item.

Parameters:
Name Type Description
element Node

target element

key string

name of the stored data

Returns:

whether data is present

Type
boolean

(static) put(element, key, obj)

Source:

Adds object to element storage. Ensures that element storage exist.

Parameters:
Name Type Description
element Node

target element

key string

name of the stored data

obj object

stored data

(static) remove(element, key) → {object}

Source:

Removes item from element storage. Removes element storage if empty.

Parameters:
Name Type Description
element Node

target element

key string

name of the stored data

Returns:

removed data object

Type
object