Socket
Socket
Sign inDemoInstall

core-decorators

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-decorators - npm Package Compare versions

Comparing version 0.9.2 to 0.10.0

lib/lazy-initialize.js

10

lib/core-decorators.js

@@ -61,2 +61,10 @@ 'use strict';

exports.mixin = _interopRequire(_mixin);
exports.mixins = _interopRequire(_mixin);
exports.mixins = _interopRequire(_mixin);
var _lazyInitialize = require('./lazy-initialize');
exports.lazyInitialize = _interopRequire(_lazyInitialize);
var _time = require('./time');
exports.time = _interopRequire(_time);

@@ -6,2 +6,5 @@ 'use strict';

});
var _createDecoratedClass = (function () { function defineProperties(target, descriptors, initializers) { for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === 'function') { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator); } } if (descriptor.initializer !== undefined) { initializers[key] = descriptor; continue; } } Object.defineProperty(target, key, descriptor); } } return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) { if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers); if (staticProps) defineProperties(Constructor, staticProps, staticInitializers); return Constructor; }; })();
var _slice = Array.prototype.slice;

@@ -14,6 +17,14 @@ exports.isDescriptor = isDescriptor;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _defineDecoratedPropertyDescriptor(target, key, descriptors) { var _descriptor = descriptors[key]; if (!_descriptor) return; var descriptor = {}; for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; descriptor.value = descriptor.initializer.call(target); Object.defineProperty(target, key, descriptor); }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
var _lazyInitialize = require('../lazy-initialize');
var _lazyInitialize2 = _interopRequireDefault(_lazyInitialize);
var defineProperty = Object.defineProperty;

@@ -50,10 +61,41 @@ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;

var Meta = function Meta() {
_classCallCheck(this, Meta);
var Meta = (function () {
var _instanceInitializers = {};
this.debounceTimeoutIds = {};
this.throttleTimeoutIds = {};
this.throttlePreviousTimestamps = {};
};
function Meta() {
_classCallCheck(this, Meta);
_defineDecoratedPropertyDescriptor(this, 'debounceTimeoutIds', _instanceInitializers);
_defineDecoratedPropertyDescriptor(this, 'throttleTimeoutIds', _instanceInitializers);
_defineDecoratedPropertyDescriptor(this, 'throttlePreviousTimestamps', _instanceInitializers);
}
_createDecoratedClass(Meta, [{
key: 'debounceTimeoutIds',
decorators: [_lazyInitialize2['default']],
initializer: function () {
return {};
},
enumerable: true
}, {
key: 'throttleTimeoutIds',
decorators: [_lazyInitialize2['default']],
initializer: function () {
return {};
},
enumerable: true
}, {
key: 'throttlePreviousTimestamps',
decorators: [_lazyInitialize2['default']],
initializer: function () {
return {};
},
enumerable: true
}], null, _instanceInitializers);
return Meta;
})();
var META_KEY = typeof Symbol === 'function' ? Symbol('__core_decorators__') : '__core_decorators__';

@@ -60,0 +102,0 @@

2

lib/suppress-warnings.js

@@ -23,3 +23,3 @@ 'use strict';

function handleDescriptor(target, key, descriptor, warningTypes) {
function handleDescriptor(target, key, descriptor) {
return _extends({}, descriptor, {

@@ -26,0 +26,0 @@ value: function suppressWarningsWrapper() {

{
"name": "core-decorators",
"version": "0.9.2",
"version": "0.10.0",
"description": "Library of ES2016 (ES7) JavaScript decorators inspired by languages that come with built-ins like @​override, @​deprecate, @​autobind, @​mixin and more! Works great with React/Angular/more!",

@@ -5,0 +5,0 @@ "main": "lib/core-decorators.js",

@@ -20,13 +20,19 @@ # core-decorators.js [![Build Status](https://travis-ci.org/jayphelps/core-decorators.js.svg?branch=master)](https://travis-ci.org/jayphelps/core-decorators.js)

##### For Properties and Methods
* [@readonly](#readonly)
* [@nonconfigurable](#nonconfigurable)
* [@decorate](#decorate) :new:
##### For Properties only
* [@nonenumerable](#nonenumerable)
* [@lazyInitialize](#lazyInitialize) :new:
##### For Methods only
* [@autobind](#autobind)
* [@readonly](#readonly)
* [@deprecate](#deprecate-alias-deprecated)
* [@suppressWarnings](#suppresswarnings)
* [@enumerable](#enumerable) :new:
* [@override](#override)
* [@deprecate](#deprecate-alias-deprecated)
* [@debounce](#debounce)
* [@throttle](#throttle) :new:
* [@suppressWarnings](#suppresswarnings)
* [@enumerable](#enumerable) :new:
* [@nonenumerable](#nonenumerable)
* [@nonconfigurable](#nonconfigurable)
* [@decorate](#decorate) :new:
* [@instrument](#instrument) :new:

@@ -38,3 +44,2 @@ ##### For Classes

##### Proposed (not implemented, PRs welcome!):
* @instrument/profile
* @assertArguments(arg1 => arg1, arg2 => arg2)

@@ -226,3 +231,3 @@ * @private

pay() {}
@enumerable

@@ -267,3 +272,3 @@ eat() {}

Marks a property or method as not being writable.
Marks a property or method so that it cannot be reconfigured, changed, or deleted.

@@ -316,2 +321,30 @@ ```js

### @lazyInitialize
Prevents a property initializer from running until the decorated property is actually looked up. Useful to prevent excess allocations that might otherwise not be used, but be careful not to over-optimize things.
```js
import { lazyInitialize } from 'core-decorators';
function createHugeBuffer() {
console.log('huge buffer created');
return new Array(1000000);
}
class Editor {
@lazyInitialize
hugeBuffer = createHugeBuffer();
}
var editor = new Editor();
// createHugeBuffer() has not been called yet
editor.hugeBuffer;
// logs 'huge buffer created', now it has been called
editor.hugeBuffer;
// already initialized and equals our buffer, so
// createHugeBuffer() is not called again
```
### @mixin (alias: @mixins)

@@ -350,3 +383,33 @@

### @instrument
Uses `console.time` and `console.timeEnd` to provide function timings with a unique label whose default prefix is `ClassName.method`. Supply a first argument to override the prefix:
```js
class Bird {
@instrument('sing')
sing() {
}
}
var bird = new Bird();
bird.sing(); // console.time label will be 'sing-0'
bird.sing(); // console.time label will be 'sing-1'
```
Will polyfill `console.time` if the current environment does not support it. You can also supply a custom `console` object as the second argument with the following methods:
* `myConsole.time(label)`
* `myConsole.timeEnd(label)`
* `myConsole.log(value)`
```js
let myConsole = {
time: function(label) { /* custom time() method */ },
timeEnd: function(label) { /* custom timeEnd method */ },
log: function(str) { /* custom log method */ }
}
```
# Future Compatibility
Since most people can't keep up to date with specs, it's important to note that ES2016 (including the decorators spec this relies on) is in-flux and subject to breaking changes. In fact, the [biggest change is coming shortly](https://github.com/wycats/javascript-decorators/pull/36) but I am active in the appropriate communities and will be keeping this project up to date as things progress. For the most part, these changes will usually be transparent to consumers of this project--that said, core-decorators has not yet reached 1.0 and may in fact introduce breaking changes. If you'd prefer not to receive these changes, be sure to lock your dependency to [PATCH](http://semver.org/). You can track the progress of core-decorators@1.0.0 in the [The Road to 1.0](https://github.com/jayphelps/core-decorators.js/issues/15) ticket.

@@ -14,1 +14,3 @@ export { default as override } from './override';

export { default as mixin, default as mixins } from './mixin';
export { default as lazyInitialize } from './lazy-initialize';
export { default as time } from './time';

@@ -0,1 +1,3 @@

import lazyInitialize from '../lazy-initialize';
const { defineProperty, getOwnPropertyDescriptor,

@@ -31,4 +33,7 @@ getOwnPropertyNames, getOwnPropertySymbols } = Object;

class Meta {
@lazyInitialize
debounceTimeoutIds = {};
@lazyInitialize
throttleTimeoutIds = {};
@lazyInitialize
throttlePreviousTimestamps = {};

@@ -35,0 +40,0 @@ }

@@ -15,3 +15,3 @@ import { decorate } from './private/utils';

function handleDescriptor(target, key, descriptor, warningTypes) {
function handleDescriptor(target, key, descriptor) {
return {

@@ -18,0 +18,0 @@ ...descriptor,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc