class-autobind-decorator
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -95,10 +95,15 @@ 'use strict'; | ||
if (!dontOptimize) { | ||
var _configurable = propDescriptor.configurable, | ||
writable = propDescriptor.writable; | ||
var writable = propDescriptor.writable, | ||
enumerable = propDescriptor.enumerable; // use same values as prototype for consistency | ||
// `defineProperty` must be used here rather than a standard assignment because | ||
// assignments will first check for getters/setters up the prototype chain and | ||
// thus reject the assignment (since the property on the prototype has a getter | ||
// but no setter (see: http://www.2ality.com/2012/08/property-definition-assignment.html)) | ||
Object.defineProperty(this, ownPropIdentifier, { | ||
value: boundMethod, | ||
configurable: _configurable, | ||
writable: writable | ||
configurable: true, | ||
writable: writable, | ||
enumerable: enumerable | ||
}); | ||
@@ -105,0 +110,0 @@ } |
# CHANGELOG | ||
## v2.2.0 (12/17/2016) | ||
- Add TypeScript declaration file (closes #1) | ||
- Make newly-defined property have same enumerability as property being | ||
overridden | ||
- Add additional tests and comments | ||
## v2.1.0 (11/18/2016) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "class-autobind-decorator", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A small framework-agnostic utility for auto-binding \"class\" methods to instances (with customization options) using either \"legacy\" decorator syntax or plain old ES5 (without needing ES2015+ polyfills).", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"scripts": { | ||
"build": "./node_modules/.bin/babel src -d build", | ||
"build": "./node_modules/.bin/babel src -d build && cp ./src/index.d.ts ./build", | ||
"test": "npm run build && ./node_modules/.bin/mocha --compilers js:babel-core/register -- test" | ||
@@ -9,0 +10,0 @@ }, |
@@ -25,2 +25,3 @@ # class-autobind-decorator | ||
- Documented and tested | ||
- Includes TypeScript declarations for use with TypeScript | ||
@@ -138,3 +139,5 @@ ## Installation | ||
and, from that point onward, to store the bound method on the instance itself. You can override | ||
this behavior by setting `dontOptimize` to true. | ||
this behavior by setting `dontOptimize` to true. If you do that, the method will be re-bound to the | ||
instance on every access; a bound version of the method will not be stored on the instance itself | ||
(so, a use case for this might be if you need the instance not to be modified at all). | ||
@@ -174,5 +177,5 @@ ## Building | ||
or can't be used as both "bare" (unconfigured) decorators and configured | ||
decorators, and things like that -- no hate, though!). I also just wanted an | ||
opportunity to work more directly with decorators, so I used it as a | ||
learning experience. :) | ||
decorators, or don't have TypeScript declarations, and things like that -- no | ||
hate, though!). I also just wanted an opportunity to work more directly with | ||
decorators, so I used it as a learning experience. :) | ||
@@ -182,1 +185,2 @@ ## License | ||
[MIT](https://opensource.org/licenses/MIT) | ||
@@ -81,8 +81,13 @@ /** | ||
if (!dontOptimize) { | ||
const { configurable, writable } = propDescriptor; | ||
const { writable, enumerable } = propDescriptor; // use same values as prototype for consistency | ||
// `defineProperty` must be used here rather than a standard assignment because | ||
// assignments will first check for getters/setters up the prototype chain and | ||
// thus reject the assignment (since the property on the prototype has a getter | ||
// but no setter (see: http://www.2ality.com/2012/08/property-definition-assignment.html)) | ||
Object.defineProperty(this, ownPropIdentifier, { | ||
value: boundMethod, | ||
configurable, | ||
writable | ||
configurable: true, | ||
writable, | ||
enumerable | ||
}); | ||
@@ -89,0 +94,0 @@ } |
@@ -39,2 +39,6 @@ import 'babel-polyfill'; | ||
/** | ||
* Retrieves three classes for testing -- one unbound, one auto-bound, and one | ||
* auto-bound-with-options (some methods ignored). | ||
*/ | ||
function getClasses(autoBindOptions) { | ||
@@ -121,2 +125,3 @@ class MyFirstClass { | ||
expect(myFirstInstance.hasOwnProperty('testMethodOne')).to.equal(false); | ||
expect(b(myFirstInstance)).to.equal(true); | ||
}); | ||
@@ -134,4 +139,4 @@ }); | ||
expect(myFirstInstance.hasOwnProperty('testMethodOne')).to.equal(true); | ||
}) | ||
}) | ||
}); | ||
}); | ||
}); | ||
@@ -183,2 +188,5 @@ | ||
expect(testMethodOne(mySecondInstance)).to.equal(false); | ||
expect(myFirstInstance.hasOwnProperty('testMethodOne')).to.equal(true); | ||
expect(MySecondClass.prototype.hasOwnProperty('testMethodOne')).to.equal(true); | ||
expect(mySecondInstance.hasOwnProperty('testMethodOne')).to.equal(false); | ||
@@ -188,4 +196,5 @@ testMethodOne = mySecondInstance.testMethodOne; | ||
expect(testMethodOne(mySecondInstance)).to.equal(true); | ||
expect(mySecondInstance.hasOwnProperty('testMethodOne')).to.equal(true); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26263
10
356
183