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.4.1 to 0.4.2

60

lib/autobind.js

@@ -20,2 +20,26 @@ 'use strict';

var mapStore = undefined;
function getBoundSuper(obj, fn) {
if (typeof WeakMap === 'undefined') {
throw new Error('Using @autobind on ' + fn.name + '() requires WeakMap support due to its use of super.' + fn.name + '()\n See https://github.com/jayphelps/core-decorators.js/issues/20');
}
if (!mapStore) {
mapStore = new WeakMap();
}
if (mapStore.has(obj) === false) {
mapStore.set(obj, new WeakMap());
}
var superStore = mapStore.get(obj);
if (superStore.has(fn) === false) {
superStore.set(fn, bind(fn, obj));
}
return superStore.get(fn);
}
function handleDescriptor(target, key, _ref) {

@@ -28,24 +52,28 @@ var fn = _ref.value;

var constructor = target.constructor;
return {
configurable: true,
get: function get() {
// This happens if someone accesses the
// property directly on the prototype
if (this === constructor.prototype) {
return fn;
}
// This is a confusing case where you have an autobound method calling
// super.sameMethod() which is also autobound and so on.
if (this.constructor !== constructor && this.constructor.prototype.hasOwnProperty(key)) {
return getBoundSuper(this, fn);
}
return this[key] = bind(fn, this);
},
set: function set(newValue) {
if (this === target) {
// New value directly set on the prototype.
delete this[key];
this[key] = newValue;
} else {
// New value set on a child object.
// Cannot use assignment because it will call the setter on the
// prototype.
Object.defineProperty(this, key, {
configurable: true,
enumerable: true,
value: newValue,
writable: true
});
}
Object.defineProperty(this, key, {
configurable: true,
enumerable: true,
value: newValue,
writable: true
});
}

@@ -52,0 +80,0 @@ };

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

function handleDescriptor(target, key, descriptor) {
console.warn('DEPRECATION: @memoize is deprecated and will be removed shortly.');
var _metaForDescriptor = metaForDescriptor(descriptor);

@@ -52,0 +54,0 @@

{
"name": "core-decorators",
"version": "0.4.1",
"version": "0.4.2",
"description": "Library of ES7 decorators inspired by languages that come with built-ins like @override, @deprecated, etc",

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

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

* [@suppressWarnings](#suppresswarnings)
* [@memoize](#memoize)
* [@nonenumerable](#nonenumerable)

@@ -237,6 +236,2 @@ * [@nonconfigurable](#nonconfigurable)

### @memoize
Initial implementation included, likely slow. WIP.
### @mixin (alias: @mixins)

@@ -256,2 +251,4 @@

const FlyMixin = {
// All types of property descriptors are supported
get speed() {}
fly() {}

@@ -272,2 +269,2 @@ land() {}

```
```

@@ -13,2 +13,29 @@ import { decorate } from './private/utils';

let mapStore;
function getBoundSuper(obj, fn) {
if (typeof WeakMap === 'undefined') {
throw new Error(
`Using @autobind on ${fn.name}() requires WeakMap support due to its use of super.${fn.name}()
See https://github.com/jayphelps/core-decorators.js/issues/20`
);
}
if (!mapStore) {
mapStore = new WeakMap();
}
if (mapStore.has(obj) === false) {
mapStore.set(obj, new WeakMap());
}
const superStore = mapStore.get(obj);
if (superStore.has(fn) === false) {
superStore.set(fn, bind(fn, obj));
}
return superStore.get(fn);
}
function handleDescriptor(target, key, { value: fn }) {

@@ -19,24 +46,28 @@ if (typeof fn !== 'function') {

const { constructor } = target;
return {
configurable: true,
get() {
// This happens if someone accesses the
// property directly on the prototype
if (this === constructor.prototype) {
return fn;
}
// This is a confusing case where you have an autobound method calling
// super.sameMethod() which is also autobound and so on.
if (this.constructor !== constructor && this.constructor.prototype.hasOwnProperty(key)) {
return getBoundSuper(this, fn);
}
return (this[key] = bind(fn, this));
},
set(newValue) {
if (this === target) {
// New value directly set on the prototype.
delete this[key];
this[key] = newValue;
} else {
// New value set on a child object.
// Cannot use assignment because it will call the setter on the
// prototype.
Object.defineProperty(this, key, {
configurable: true,
enumerable: true,
value: newValue,
writable: true
});
}
Object.defineProperty(this, key, {
configurable: true,
enumerable: true,
value: newValue,
writable: true
});
}

@@ -43,0 +74,0 @@ };

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

function handleDescriptor(target, key, descriptor) {
console.warn('DEPRECATION: @memoize is deprecated and will be removed shortly.');
const { fn, wrapKey } = metaForDescriptor(descriptor);

@@ -39,0 +41,0 @@ const argumentCache = new WeakMap();

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