Giter Club home page Giter Club logo

yields-data's Introduction

This repository is a mirror of the component module yields/data. It has been modified to work with NPM+Browserify. You can install it using the command npm install npmcomponent/yields-data. Please do not open issues or send pull requests against this repo. If you have issues with this repo, report it to npmcomponent.

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

yields-data's People

Contributors

airportyh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.