attach data to elements. think $.data().
$ component install yields/data
Get new data api for the given element.
Merge the provided obj
or set
key
to val
.
data(el).set({ foo: 'bar' })
data(el).set({ bar: 'foo' });
data(el).get();
// > { foo: 'bar', bar: 'foo' }
Get all data or a single value by key
,
if the key
does not exists it will be looked-up
in the element data-*
attributes, when found
it will be cached and then returned.
data(el).get('foo');
// > null
data(el).get();
// > {}
Whether or not key
exists
data(el).set('foo', 'bar').has('foo');
// > true
Delete all data or a single key
from cache.
data(el).del('some key');
data(el).del(); // everything!
the element cache
the element.
data.api.getUserAge = function () {
return this.cache.user
&& this.cache.user.age;
};
data(el).set({ user: { age: 99 } }).getUserAge();
// > 99
MIT