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.8.1 to 0.9.0

lib/enumerable.js

4

lib/core-decorators.js

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

var _enumerable = require('./enumerable');
exports.enumerable = _interopRequire(_enumerable);
var _nonenumerable = require('./nonenumerable');

@@ -36,0 +40,0 @@

8

lib/debounce.js

@@ -33,4 +33,3 @@ 'use strict';

value: function value() {
var _this = this,
_arguments = arguments;
var _this = this;

@@ -43,2 +42,3 @@ var _metaFor = (0, _privateUtils.metaFor)(this);

var callNow = immediate && !timeout;
var args = arguments;

@@ -50,3 +50,3 @@ clearTimeout(timeout);

if (!immediate) {
callback.apply(_this, _arguments);
callback.apply(_this, args);
}

@@ -56,3 +56,3 @@ }, wait);

if (callNow) {
callback.apply(this, arguments);
callback.apply(this, args);
}

@@ -59,0 +59,0 @@ }

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

function handleDescriptor(target, key, descriptor) {
console.warn('DEPRECATION: @memoize is deprecated and will be removed shortly.');
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');

@@ -53,0 +53,0 @@ var _metaForDescriptor = metaForDescriptor(descriptor);

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

});
exports['default'] = enumerable;
exports['default'] = nonenumerable;

@@ -16,3 +16,3 @@ var _privateUtils = require('./private/utils');

function enumerable() {
function nonenumerable() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

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

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

this.debounceTimeoutIds = {};
this.throttleTimeoutIds = {};
this.throttlePreviouStimestamps = {};
};

@@ -54,0 +56,0 @@

{
"name": "core-decorators",
"version": "0.8.1",
"version": "0.9.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",

# core-decorators.js [![Build Status](https://travis-ci.org/jayphelps/core-decorators.js.svg?branch=master)](https://travis-ci.org/jayphelps/core-decorators.js)
Library of [ES2016 (ES7) decorators](https://github.com/wycats/javascript-decorators) inspired by languages that come with built-ins like @​override, @​deprecate, etc, similar to [pre-defined Annotations in Java](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html). Note that unlike Java annotations, decorators are functions which are applied at runtime.
Library of [JavaScript decorators](https://github.com/wycats/javascript-decorators) (sometimes erroneously stated as ES2016 or ES7) inspired by languages that come with built-ins like @​override, @​deprecate, etc, similar to [pre-defined Annotations in Java](https://docs.oracle.com/javase/tutorial/java/annotations/predefined.html). Note that unlike Java annotations, decorators are functions which are applied at runtime.
It also includes a single class decorator, `@mixin` for applying object descriptors to a given class.
It also includes a single class decorator, `@mixin` for applying object descriptors to a given class.
_*compiled code is intentionally not checked into this repo_
### Get It

@@ -13,9 +15,7 @@

This form could be consumed by any ES2016 (ES7) transpiler that supports decorators like [babel.js](https://babeljs.io/) with `babel --optional es7.decorators,es7.objectRestSpread` or `babel --stage 1` or using the recent iterations of TypeScript.
This can be consumed by any transpiler that supports decorators like [babel.js](https://babeljs.io/) or using the recent iterations of TypeScript. To use with babel, you must include the correct babel plugins for decorator [parsing](http://babeljs.io/docs/plugins/syntax-decorators/) and [transformation](http://babeljs.io/docs/plugins/transform-decorators/) or use [stage-1](http://babeljs.io/docs/plugins/preset-stage-1/).
_*note that the compiled code is intentionally not checked into this repo_
## Decorators
##### For Methods
##### For Properties and Methods
* [@autobind](#autobind)

@@ -26,3 +26,5 @@ * [@readonly](#readonly)

* [@debounce](#debounce)
* [@throttle](#throttle) :new:
* [@suppressWarnings](#suppresswarnings)
* [@enumerable](#enumerable) :new:
* [@nonenumerable](#nonenumerable)

@@ -38,3 +40,2 @@ * [@nonconfigurable](#nonconfigurable)

* @instrument/profile
* @throttle
* @assertArguments(arg1 => arg1, arg2 => arg2)

@@ -47,3 +48,3 @@ * @private

Forces invocations of this function to always have `this` refer to the class instance, even if the function is passed around or would otherwise lose its `this` context. e.g. `var fn = context.method;`
Forces invocations of this function to always have `this` refer to the class instance, even if the function is passed around or would otherwise lose its `this` context. e.g. `var fn = context.method;` Popular with React components.

@@ -158,3 +159,3 @@ ```js

class Editor {
content = '';

@@ -169,2 +170,27 @@

### @throttle
Creates a new throttled function which will be invoked in every `wait` milliseconds. Default timeout is 300 ms.
Second argument is optional options:
- `leading`: default to `true`, allows to trigger function on the leading.
- `trailing`: default to `true`, allows to trigger function on the trailing edge of the wait interval.
Implementation is insired by similar method from [UnderscoreJS](http://underscorejs.org/#throttle).
```js
import { throttle } from 'core-decorators';
class Editor {
content = '';
@throttle(500, {leading: false})
updateContent(content) {
this.content = content;
}
}
```
### @suppressWarnings

@@ -195,5 +221,27 @@

### @enumerable
Marks a method as being enumerable. Note that instance properties are _already_ enumerable, so this is only useful for methods.
```js
import { enumerable } from 'core-decorators';
class Meal {
pay() {}
@enumerable
eat() {}
}
var dinner = new Meal();
for (var key in dinner) {
key;
// "eat" only, not "pay"
}
```
### @nonenumerable
Marks a property or method as not being enumerable.
Marks a property as not being enumerable. Note that class methods are _already_ nonenumerable, so this is only useful for instance properties.

@@ -205,3 +253,3 @@ ```js

entree = 'steak';
@nonenumerable

@@ -208,0 +256,0 @@ cost = 20.99;

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

export { default as readonly } from './readonly';
export { default as enumerable } from './enumerable';
export { default as nonenumerable } from './nonenumerable';

@@ -9,0 +10,0 @@ export { default as nonconfigurable } from './nonconfigurable';

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

const callNow = immediate && !timeout;
const args = arguments;

@@ -25,3 +26,3 @@ clearTimeout(timeout);

if (!immediate) {
callback.apply(this, arguments);
callback.apply(this, args);
}

@@ -31,3 +32,3 @@ }, wait);

if (callNow) {
callback.apply(this, arguments);
callback.apply(this, args);
}

@@ -34,0 +35,0 @@ }

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

function handleDescriptor(target, key, descriptor) {
console.warn('DEPRECATION: @memoize is deprecated and will be removed shortly.');
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');

@@ -40,0 +40,0 @@ const { fn, wrapKey } = metaForDescriptor(descriptor);

@@ -8,4 +8,4 @@ import { decorate } from './private/utils';

export default function enumerable(...args) {
export default function nonenumerable(...args) {
return decorate(handleDescriptor, args);
}
const { defineProperty, getOwnPropertyDescriptor,
getOwnPropertyNames, getOwnPropertySymbols } = Object;
export function isDescriptor(desc) {

@@ -8,5 +8,5 @@ if (!desc || !desc.hasOwnProperty) {

}
const keys = ['value', 'get', 'set'];
for (let i = 0, l = keys.length; i < l; i++) {

@@ -17,3 +17,3 @@ if (desc.hasOwnProperty(keys[i])) {

}
return false;

@@ -34,2 +34,4 @@ }

debounceTimeoutIds = {};
throttleTimeoutIds = {};
throttlePreviouStimestamps = {};
}

@@ -58,7 +60,7 @@

: getOwnPropertyNames;
export function getOwnPropertyDescriptors(obj) {
const descs = {};
getOwnKeys(obj).forEach(

@@ -83,2 +85,2 @@ key => (descs[key] = getOwnPropertyDescriptor(obj, key))

};
}
}
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