Socket
Socket
Sign inDemoInstall

twreporter-react

Package Overview
Dependencies
77
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    twreporter-react

React-Redux site for The Reporter Foundation in Taiwan


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

D - Property descriptor factory

Originally derived from es5-ext package.

Defining properties with descriptors is very verbose:

var Account = function () {};
Object.defineProperties(Account.prototype, {
  deposit: { value: function () {
      /* ... */
    }, configurable: true, enumerable: false, writable: true },
  whithdraw: { value: function () {
      /* ... */
    }, configurable: true, enumerable: false, writable: true },
  balance: { get: function () {
      /* ... */
    }, configurable: true, enumerable: false }
});

D cuts that to:

var d = require('d');

var Account = function () {};
Object.defineProperties(Account.prototype, {
  deposit: d(function () {
    /* ... */
  }),
  whithdraw: d(function () {
    /* ... */
  }),
  balance: d.gs(function () {
    /* ... */
  })
});

By default, created descriptor follow characteristics of native ES5 properties, and defines values as:

{ configurable: true, enumerable: false, writable: true }

You can overwrite it by preceding value argument with instruction:

d('c', value); // { configurable: true, enumerable: false, writable: false }
d('ce', value); // { configurable: true, enumerable: true, writable: false }
d('e', value); // { configurable: false, enumerable: true, writable: false }

// Same way for get/set:
d.gs('e', value); // { configurable: false, enumerable: true }

Other utilities

autoBind(obj, props) (d/auto-bind)

Define methods which will be automatically bound to its instances

var d = require('d');
var autoBind = require('d/auto-bind');

var Foo = function () { this._count = 0; };
autoBind(Foo.prototype, {
  increment: d(function () { ++this._count; });
});

var foo = new Foo();

// Increment foo counter on each domEl click
domEl.addEventListener('click', foo.increment, false);
lazy(obj, props) (d/lazy)

Define lazy properties, which will be resolved on first access

var d = require('d');
var lazy = require('d/lazy');

var Foo = function () {};
lazy(Foo.prototype, {
  items: d(function () { return []; })
});

var foo = new Foo();
foo.items.push(1, 2); // foo.items array created

Installation

NPM

In your project path:

$ npm install d

Browser

You can easily bundle D for browser with modules-webmake

Tests Build Status

$ npm test

FAQs

Last updated on 08 Aug 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc