attach data to elements. think $.data()
JavaScript
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
History.md
Makefile
Readme.md
component.json
index.js

Readme.md

data

attach data to elements. think $.data().

Installation

$ component install yields/data

API

api = data(el)

Get new data api for the given element.

api.set(key[, val])

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' }

api.get([key])

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();
// > {}

api.has(key)

Whether or not key exists

data(el).set('foo', 'bar').has('foo');
// > true

api.del([key])

Delete all data or a single key from cache.

data(el).del('some key');
data(el).del(); // everything!

api.cache

the element cache

api.el

the element.

add custom methods.

data.api.getUserAge = function () {
  return this.cache.user
    && this.cache.user.age;
};

data(el).set({ user: { age: 99 } }).getUserAge();
// > 99

License

MIT