core-decorators
Advanced tools
Comparing version 0.0.11 to 0.0.13
{ | ||
"name": "core-decorators", | ||
"version": "0.0.11", | ||
"version": "0.0.13", | ||
"description": "Library of ES7 decorators inspired by languages that come with built-ins like @override, @deprecated, etc", | ||
"main": "src/core-decorators.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha --require babel/register 'src/**/*.spec.js'" | ||
}, | ||
@@ -29,3 +29,8 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/jayphelps/core-decorators.js" | ||
} | ||
"homepage": "https://github.com/jayphelps/core-decorators.js", | ||
"devDependencies": { | ||
"babel": "^5.2.16", | ||
"mocha": "^2.2.4", | ||
"must": "^0.12.0" | ||
} | ||
} |
# core-decorators.js | ||
Library of ES7 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). | ||
Library of ES7 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. | ||
The idea is these decorators would be used to ensure code sanity, but would be removed in production builds via a Babel plugin. | ||
### @readonly | ||
@@ -112,2 +110,23 @@ | ||
### @autobind | ||
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;` | ||
```js | ||
import { autobind } from 'core-decorators'; | ||
class Person { | ||
@autobind | ||
getPerson() { | ||
return this; | ||
} | ||
} | ||
let person = new Person(); | ||
let getPerson = person.getPerson; | ||
getPerson() === person; | ||
// true | ||
``` | ||
### @memoize | ||
@@ -120,2 +139,2 @@ | ||
![adorable dog](https://cloud.githubusercontent.com/assets/762949/7152487/b0fec1ce-e2f1-11e4-9207-93fb1422381c.gif) | ||
![adorable dog](https://cloud.githubusercontent.com/assets/762949/7152487/b0fec1ce-e2f1-11e4-9207-93fb1422381c.gif) |
@@ -6,1 +6,2 @@ export { default as override } from './override'; | ||
export { default as readonly } from './readonly'; | ||
export { default as autobind } from './autobind'; |
import { decorate } from './private/utils'; | ||
function handleDescriptor(target, key, descriptor, [msg = DEFAULT_MSG, options = {}]) { | ||
function handleDescriptor(target, key, descriptor) { | ||
descriptor.writable = false; | ||
@@ -5,0 +5,0 @@ return descriptor; |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
19101
15
393
0
1
139
3