Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.17.0 to 0.18.0

14

lib/autobind.js

@@ -16,12 +16,2 @@ 'use strict';

function bind(fn, context) {
if (fn.bind) {
return fn.bind(context);
} else {
return function __autobind__() {
return fn.apply(context, arguments);
};
}
}
var mapStore = void 0;

@@ -45,3 +35,3 @@

if (superStore.has(fn) === false) {
superStore.set(fn, bind(fn, obj));
superStore.set(fn, (0, _utils.bind)(fn, obj));
}

@@ -105,3 +95,3 @@

var boundFn = bind(fn, this);
var boundFn = (0, _utils.bind)(fn, this);

@@ -108,0 +98,0 @@ defineProperty(this, key, {

2

lib/debounce.js

@@ -58,2 +58,4 @@ 'use strict';

function debounce() {
(0, _utils.internalDeprecation)('@debounce is deprecated and will be removed shortly. Use @debounce from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

@@ -60,0 +62,0 @@ args[_key] = arguments[_key];

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

value: function deprecationWrapper() {
console.warn('DEPRECATION ' + methodSignature + ': ' + msg);
(0, _utils.warn)('DEPRECATION ' + methodSignature + ': ' + msg);
return descriptor.value.apply(this, arguments);

@@ -39,0 +39,0 @@ }

@@ -50,4 +50,2 @@ 'use strict';

function handleDescriptor(target, key, descriptor) {
console.warn('DEPRECATION: @memoize is deprecated and will be removed shortly. Use @decorate with lodash\'s memoize helper.\n\n https://github.com/jayphelps/core-decorators.js#decorate');
var _metaForDescriptor = metaForDescriptor(descriptor),

@@ -87,2 +85,4 @@ fn = _metaForDescriptor.fn,

function memoize() {
(0, _utils.internalDeprecation)('@memoize is deprecated and will be removed shortly. Use @memoize from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {

@@ -89,0 +89,0 @@ args[_key2] = arguments[_key2];

@@ -68,2 +68,4 @@ 'use strict';

(0, _utils.internalDeprecation)('@mixin is deprecated and will be removed shortly. Use @mixin from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
if (typeof mixins[0] === 'function') {

@@ -70,0 +72,0 @@ return handleClass(mixins[0], []);

@@ -6,6 +6,8 @@ 'use strict';

});
exports.getOwnKeys = undefined;
exports.warn = exports.getOwnKeys = undefined;
var _desc, _value, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _desc, _value, _class, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
exports.isDescriptor = isDescriptor;

@@ -16,2 +18,4 @@ exports.decorate = decorate;

exports.createDefaultSetter = createDefaultSetter;
exports.bind = bind;
exports.internalDeprecation = internalDeprecation;

@@ -111,2 +115,4 @@ var _lazyInitialize = require('../lazy-initialize');

_initDefineProp(this, 'throttleTrailingArgs', _descriptor4, this);
_initDefineProp(this, 'profileLastRan', _descriptor5, this);
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, 'debounceTimeoutIds', [_lazyInitialize2.default], {

@@ -132,2 +138,7 @@ enumerable: true,

}
}), _descriptor5 = _applyDecoratedDescriptor(_class.prototype, 'profileLastRan', [_lazyInitialize2.default], {
enumerable: true,
initializer: function initializer() {
return null;
}
})), _class);

@@ -175,2 +186,28 @@

};
}
function bind(fn, context) {
if (fn.bind) {
return fn.bind(context);
} else {
return function __autobind__() {
return fn.apply(context, arguments);
};
}
}
var warn = exports.warn = function () {
if ((typeof console === 'undefined' ? 'undefined' : _typeof(console)) !== 'object' || !console || typeof console.warn !== 'function') {
return function () {};
} else {
return bind(console.warn, console);
}
}();
var seenDeprecations = {};
function internalDeprecation(msg) {
if (seenDeprecations[msg] !== true) {
seenDeprecations[msg] = true;
warn('DEPRECATION: ' + msg);
}
}

@@ -16,7 +16,9 @@ 'use strict';

var oc = console;
// Exported for mocking in tests
var defaultConsole = exports.defaultConsole = {
profile: console.profile ? console.profile.bind(console) : function () {},
profileEnd: console.profileEnd ? console.profileEnd.bind(console) : function () {},
warn: console.warn.bind(console)
profile: console.profile ? (0, _utils.bind)(console.profile, console) : function () {},
profileEnd: console.profileEnd ? (0, _utils.bind)(console.profileEnd, console) : function () {},
warn: _utils.warn
};

@@ -29,3 +31,3 @@

_ref2$2 = _ref2[1],
once = _ref2$2 === undefined ? false : _ref2$2,
onceThrottleOrFunction = _ref2$2 === undefined ? false : _ref2$2,
_ref2$3 = _ref2[2],

@@ -36,3 +38,3 @@ console = _ref2$3 === undefined ? defaultConsole : _ref2$3;

if (!profile.__warned) {
console.warn('Console.profile is not supported. All @profile decorators are disabled.');
console.warn('console.profile is not supported. All @profile decorators are disabled.');
profile.__warned = true;

@@ -53,10 +55,9 @@ }

var ran = false;
return _extends({}, descriptor, {
value: function value() {
var label = '' + prefix;
if (!once || once && !ran) {
console.profile(label);
ran = true;
var now = Date.now();
var meta = (0, _utils.metaFor)(this);
if (onceThrottleOrFunction === true && !meta.profileLastRan || onceThrottleOrFunction === false || typeof onceThrottleOrFunction === 'number' && now - meta.profileLastRan > onceThrottleOrFunction || typeof onceThrottleOrFunction === 'function' && onceThrottleOrFunction.apply(this, arguments)) {
console.profile(prefix);
meta.profileLastRan = now;
}

@@ -67,3 +68,3 @@

} finally {
console.profileEnd(label);
console.profileEnd(prefix);
}

@@ -70,0 +71,0 @@ }

@@ -82,2 +82,4 @@ 'use strict';

function throttle() {
(0, _utils.internalDeprecation)('@throttle is deprecated and will be removed shortly. Use @throttle from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

@@ -84,0 +86,0 @@ args[_key] = arguments[_key];

{
"name": "core-decorators",
"version": "0.17.0",
"version": "0.18.0",
"description": "Library of JavaScript stage-0 decorators (aka ES2016/ES7 decorators but that's not accurate!) 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",

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

## Need lodash utilities as decorators?
core-decorators aims to provide decorators that are fundamental to JavaScript itself--mostly things you could do with normal `Object.defineProperty` but not as easily when using ES2015 classes. Things like debouncing, throttling, and other more opinionated decorators are being phased out in favor of [lodash-decorators](https://www.npmjs.com/package/lodash-decorators) which wraps applicable lodash utilities as decorators. We don't want to duplicate the effort of lodash, which has years and years of robust testing and bugfixes.
## Decorators

@@ -32,3 +36,3 @@

* [@decorate](#decorate)
* [@extendDescriptor](#extenddescriptor) :new:
* [@extendDescriptor](#extenddescriptor)

@@ -45,14 +49,14 @@ ##### For Properties

* [@override](#override)
* [@debounce](#debounce)
* [@throttle](#throttle)
* [@debounce](#debounce) :no_entry_sign: DEPRECATED
* [@throttle](#throttle) :no_entry_sign: DEPRECATED
* [@time](#time)
* [@profile](#profile) :new:
* [@profile](#profile)
##### For Classes
* [@autobind](#autobind)
* [@mixin](#mixin-alias-mixins)
* [@mixin](#mixin-alias-mixins) :no_entry_sign: DEPRECATED
## Helpers
* [applyDecorators()](#applydecorators-helper) :new:
* [applyDecorators()](#applydecorators-helper)

@@ -192,3 +196,3 @@ ## Docs

### @debounce
### @debounce :no_entry_sign: DEPRECATED

@@ -213,3 +217,3 @@ Creates a new debounced function which will be invoked after `wait` milliseconds since the time it was invoked. Default timeout is 300 ms.

### @throttle
### @throttle :no_entry_sign: DEPRECATED

@@ -388,3 +392,3 @@ Creates a new throttled function which will be invoked in every `wait` milliseconds. Default timeout is 300 ms.

### @mixin (alias: @mixins)
### @mixin (alias: @mixins) :no_entry_sign: DEPRECATED

@@ -482,2 +486,41 @@ Mixes in all property descriptors from the provided Plain Old JavaScript Objects (aka POJOs) as arguments. Mixins are applied in the order they are passed, but do **not** override descriptors already on the class, including those inherited traditionally.

Alternatively you can pass a number instead of `true` to represent the milliseconds between profiles. Profiling is always ran on the leading edge.
```js
class Bird {
@profile(null, 1000)
sing() {
}
}
var bird = new Bird();
bird.sing(); // Adds a profile with label Bird.sing
// Wait 100ms
bird.sing(); // Does nothing
// Wait 1000ms
bird.sing(); // Adds a profile with label Bird.sing
```
When you need extremely fine-tuned control, you can pass a function that returns a boolean to determine if profiling should occur. The function will have `this` context of the instance and the arguments to the method will be passed to the function as well. Arrow functions **will not** receive the instance context.
```js
class Bird {
@profile(null, function (volume) { return volume === 'loud'; })
sing(volume) {
}
@profile(null, function () { return this.breed === 'eagle' })
fly() {
}
}
var bird = new Bird();
bird.sing('loud'); // Adds a profile with label Bird.sing
bird.sing('quite'); // Does nothing
bird.fly(); // Does nothing
bird.breed = 'eagle';
bird.fly(); // Adds a profile with label Bird.fly
```
Profiling is currently only supported in Chrome 53+, Firefox, and Edge. Unfortunately this feature can't be polyfilled or faked, so if used in an unsupported browser or Node.js then this decorator will automatically disable itself.

@@ -484,0 +527,0 @@

import { decorate, createDefaultSetter,
getOwnPropertyDescriptors, getOwnKeys } from './private/utils';
getOwnPropertyDescriptors, getOwnKeys, bind } from './private/utils';
const { defineProperty, getPrototypeOf } = Object;
function bind(fn, context) {
if (fn.bind) {
return fn.bind(context);
} else {
return function __autobind__() {
return fn.apply(context, arguments);
};
}
}
let mapStore;

@@ -16,0 +6,0 @@

@@ -1,2 +0,2 @@

import { decorate, metaFor } from './private/utils';
import { decorate, metaFor, internalDeprecation } from './private/utils';

@@ -37,3 +37,4 @@ const DEFAULT_TIMEOUT = 300;

export default function debounce(...args) {
internalDeprecation('@debounce is deprecated and will be removed shortly. Use @debounce from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
return decorate(handleDescriptor, args);
}

@@ -1,2 +0,2 @@

import { decorate } from './private/utils';
import { decorate, warn } from './private/utils';

@@ -19,3 +19,3 @@ const DEFAULT_MSG = 'This function will be removed in future versions.';

value: function deprecationWrapper() {
console.warn(`DEPRECATION ${methodSignature}: ${msg}`);
warn(`DEPRECATION ${methodSignature}: ${msg}`);
return descriptor.value.apply(this, arguments);

@@ -22,0 +22,0 @@ }

@@ -1,2 +0,2 @@

import { decorate } from './private/utils';
import { decorate, internalDeprecation } from './private/utils';

@@ -37,4 +37,2 @@ function toObject(cache, value) {

function handleDescriptor(target, key, descriptor) {
console.warn('DEPRECATION: @memoize is deprecated and will be removed shortly. Use @decorate with lodash\'s memoize helper.\n\n https://github.com/jayphelps/core-decorators.js#decorate');
const { fn, wrapKey } = metaForDescriptor(descriptor);

@@ -71,3 +69,4 @@ const argumentCache = new WeakMap();

export default function memoize(...args) {
internalDeprecation('@memoize is deprecated and will be removed shortly. Use @memoize from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
return decorate(handleDescriptor, args);
}

@@ -1,2 +0,2 @@

import { getOwnPropertyDescriptors, getOwnKeys } from './private/utils';
import { getOwnPropertyDescriptors, getOwnKeys, internalDeprecation } from './private/utils';

@@ -52,2 +52,4 @@ const { defineProperty, getPrototypeOf } = Object;

export default function mixin(...mixins) {
internalDeprecation('@mixin is deprecated and will be removed shortly. Use @mixin from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
if (typeof mixins[0] === 'function') {

@@ -54,0 +56,0 @@ return handleClass(mixins[0], []);

@@ -44,2 +44,5 @@ import lazyInitialize from '../lazy-initialize';

throttleTrailingArgs = null;
@lazyInitialize
profileLastRan = null;
}

@@ -93,1 +96,27 @@

}
export function bind(fn, context) {
if (fn.bind) {
return fn.bind(context);
} else {
return function __autobind__() {
return fn.apply(context, arguments);
};
}
}
export const warn = (() => {
if (typeof console !== 'object' || !console || typeof console.warn !== 'function') {
return () => {};
} else {
return bind(console.warn, console);
}
})();
const seenDeprecations = {};
export function internalDeprecation(msg) {
if (seenDeprecations[msg] !== true) {
seenDeprecations[msg] = true;
warn('DEPRECATION: ' + msg);
}
}

@@ -1,14 +0,16 @@

import { decorate } from './private/utils';
import { decorate, metaFor, warn, bind } from './private/utils';
const oc = console;
// Exported for mocking in tests
export const defaultConsole = {
profile: console.profile ? console.profile.bind(console) : () => {},
profileEnd: console.profileEnd ? console.profileEnd.bind(console) : () => {},
warn: console.warn.bind(console)
profile: console.profile ? bind(console.profile, console) : () => {},
profileEnd: console.profileEnd ? bind(console.profileEnd, console) : () => {},
warn
};
function handleDescriptor(target, key, descriptor, [prefix = null, once = false, console = defaultConsole]) {
function handleDescriptor(target, key, descriptor, [prefix = null, onceThrottleOrFunction = false, console = defaultConsole]) {
if (!profile.__enabled) {
if (!profile.__warned) {
console.warn('Console.profile is not supported. All @profile decorators are disabled.');
console.warn('console.profile is not supported. All @profile decorators are disabled.');
profile.__warned = true;

@@ -29,11 +31,15 @@ }

let ran = false;
return {
...descriptor,
value() {
const label = `${prefix}`;
if (!once || once && !ran) {
console.profile(label);
ran = true;
const now = Date.now();
const meta = metaFor(this);
if (
(onceThrottleOrFunction === true && !meta.profileLastRan) ||
(onceThrottleOrFunction === false) ||
(typeof onceThrottleOrFunction === 'number' && (now - meta.profileLastRan) > onceThrottleOrFunction) ||
(typeof onceThrottleOrFunction === 'function' && onceThrottleOrFunction.apply(this, arguments))
) {
console.profile(prefix);
meta.profileLastRan = now;
}

@@ -44,3 +50,3 @@

} finally {
console.profileEnd(label);
console.profileEnd(prefix);
}

@@ -47,0 +53,0 @@ }

@@ -1,2 +0,2 @@

import { decorate, metaFor } from './private/utils';
import { decorate, metaFor, internalDeprecation } from './private/utils';

@@ -61,3 +61,4 @@ const DEFAULT_TIMEOUT = 300;

export default function throttle(...args) {
internalDeprecation('@throttle is deprecated and will be removed shortly. Use @throttle from lodash-decorators.\n\n https://www.npmjs.com/package/lodash-decorators');
return decorate(handleDescriptor, args);
}
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