New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

es-databinding

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-databinding

Two way data binding in JavaScript (ES2015)

latest
Source
npmnpm
Version
0.4.1
Version published
Maintainers
1
Created
Source

Two way data binding in JavaScript Build Status

Synopsis

es-databinding (DataBinder) - two-way data binding library.

Installation

npm i --save es-databinding
or
git clone https://github.com/Zlobin/es-databinding.git
cd es-databinding && npm i && webpack

Examples

var userState = {
  firstName: 'John',
  lastName: 'Doe',
  fullName: '',
  sex: {
    active: 'M',
    data: {
      m: 'Man',
      w: 'Woman'
    }
  }
};

var cartState = {
  total: 0,
  items: [
    'Item 1',
    'Item 2',
    'Item 3'
  ]
};

var binding = {
  'user.sex.active': 'span.active',
  'user.firstName': '#first-name',
  'user.fullName': {
    // DOM element.
    el: '#fullName',
    callback: function() {
      // Will be called after changing element value.
    },
    parse: function() {
      // When apply from DOM to state.
    },
    transform: function(data) {
      // When applying from state to DOM.
      // Show how to transform data.
      // Example:
      // return `${data.value} USD`;
    }
  },
  'cart.items': '.cart-items',
  'cart.total': '#cart-total'
};

var binder = DataBinder(
  {
    user: userState,
    cart: cartState
  },
  binding
);

Manual changing state.

binder.state.user.firstName = 'John';

Export

binder.export();

Pros:

  • No setTimeout ot setInterval.
  • No dependencies.
  • Small size ~6.5kb in packed, ~2kb gzipped.
  • Easy to maintain and to extend.
  • ES2015

TODO

  • Add more tests.
  • Add more examples.
  • Add middleware pattern into setting value (to validating, for instance).
  • Add support for path like 'user.*.state'.
  • Implement parse method.
  • Add benchmarks.

Keywords

2 way data binding

FAQs

Package last updated on 17 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts