lodash-decorators
Advanced tools
Comparing version 0.1.5 to 0.2.0
@@ -8,8 +8,2 @@ 'use strict'; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _settings = require('./settings'); | ||
var _settings2 = _interopRequireDefault(_settings); | ||
var _lodash = require('lodash'); | ||
@@ -16,0 +10,0 @@ |
@@ -9,3 +9,2 @@ 'use strict'; | ||
exports.isGetter = isGetter; | ||
exports.copyMetaData = copyMetaData; | ||
@@ -23,5 +22,5 @@ exports.createDecorator = createDecorator; | ||
var _settings = require('./settings'); | ||
var _CompositeKeyWeakMap = require('./CompositeKeyWeakMap'); | ||
var _settings2 = _interopRequireDefault(_settings); | ||
var _CompositeKeyWeakMap2 = _interopRequireDefault(_CompositeKeyWeakMap); | ||
@@ -78,6 +77,2 @@ var _applyTypes = require('./applyTypes'); | ||
function isGetter(getter) { | ||
return Boolean(getter['' + _settings2['default'].annotationPrefix + 'isGetter']); | ||
} | ||
/** | ||
@@ -93,2 +88,3 @@ * Used to copy over meta data from function to function. | ||
}); | ||
return to; | ||
} | ||
@@ -120,5 +116,4 @@ | ||
if (get) { | ||
var toWrap = isGetter(get) ? get : get.call(this); | ||
descriptor.get = TYPE_MAP[type].apply(TYPE_MAP, [method, target, toWrap].concat(args)); | ||
copyMetaData(toWrap, descriptor.get); | ||
descriptor.get = TYPE_MAP[type].apply(TYPE_MAP, [method, target, get].concat(args)); | ||
copyMetaData(get, descriptor.get); | ||
} else if (value) { | ||
@@ -135,4 +130,6 @@ descriptor.value = TYPE_MAP[type].apply(TYPE_MAP, [method, target, value].concat(args)); | ||
function createInstanceDecorator(method) { | ||
var type = arguments[1] === undefined ? 'pre' : arguments[1]; | ||
var type = arguments[1] === undefined ? _applyTypes.PRE : arguments[1]; | ||
var objectMap = new _CompositeKeyWeakMap2['default'](); | ||
return type === _applyTypes.SINGLE ? wrapper() : wrapper; | ||
@@ -150,40 +147,25 @@ | ||
var action = TYPE_MAP[type]; | ||
var getterAnnotation = '' + _settings2['default'].annotationPrefix + 'isGetter'; | ||
var toWrap = get ? get : value; | ||
if (get) { | ||
copyMetaData(get, getter); | ||
descriptor.get = copyMetaData(toWrap, instanceDecoratorWrapper); | ||
} else { | ||
descriptor.value = copyMetaData(toWrap, instanceDecoratorWrapper); | ||
} | ||
return { get: getter, set: setter, configurable: true }; | ||
return descriptor; | ||
function setter(value) { | ||
Object.defineProperty(this, name, { | ||
configurable: true, | ||
value: value, | ||
writable: writable | ||
}); | ||
} | ||
function instanceDecoratorWrapper() { | ||
for (var _len9 = arguments.length, methodArgs = Array(_len9), _key9 = 0; _key9 < _len9; _key9++) { | ||
methodArgs[_key9] = arguments[_key9]; | ||
} | ||
function getter() { | ||
var isGetter = Boolean(getter[getterAnnotation]); | ||
var newDescriptor = { configurable: true }; | ||
if ((0, _lodash.isFunction)(get)) { | ||
var toWrap = isGetter ? get : get.call(this); | ||
newDescriptor.get = action.apply(undefined, [method, this, toWrap].concat(args)); | ||
copyMetaData(toWrap, newDescriptor.get); | ||
Object.defineProperty(this, name, newDescriptor); | ||
return isGetter ? newDescriptor.get() : newDescriptor.get; | ||
if (!objectMap.has([this, toWrap])) { | ||
objectMap.set([this, toWrap], action.apply(undefined, [method, this, toWrap].concat(args))); | ||
} | ||
newDescriptor.value = action.apply(undefined, [method, this, value].concat(args)); | ||
copyMetaData(value, newDescriptor.value); | ||
var fn = objectMap.get([this, toWrap]); | ||
Object.defineProperty(this, name, newDescriptor); | ||
return newDescriptor.value; | ||
} | ||
return fn.apply(this, methodArgs); | ||
}; | ||
}; | ||
@@ -190,0 +172,0 @@ }; |
@@ -17,6 +17,2 @@ 'use strict'; | ||
var _getter = require('./getter'); | ||
var _getter2 = _interopRequireDefault(_getter); | ||
var _bind = require('./bind'); | ||
@@ -32,6 +28,2 @@ | ||
var _settings = require('./settings'); | ||
var _settings2 = _interopRequireDefault(_settings); | ||
var _applyTypes = require('./applyTypes'); | ||
@@ -55,3 +47,2 @@ | ||
_lodash2['default'].assign(result, { | ||
getter: _getter2['default'], | ||
bind: _bind2['default'], | ||
@@ -68,3 +59,3 @@ tap: _tap2['default'] | ||
exports['default'] = _lodash2['default'].assign(result, { settings: _settings2['default'] }); | ||
exports['default'] = result; | ||
module.exports = exports['default']; |
{ | ||
"name": "lodash-decorators", | ||
"author": "Steven Sojka", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"engines": { | ||
@@ -20,22 +20,22 @@ "node": ">=0.12.0" | ||
"devDependencies": { | ||
"chai": "^2.2.0", | ||
"chalk": "^1.0.0", | ||
"del": "^1.1.1", | ||
"gulp": "^3.8.11", | ||
"gulp-babel": "^5.0.0", | ||
"gulp-chmod": "^1.2.0", | ||
"gulp-jshint": "^1.10.0", | ||
"gulp-mocha": "^2.0.1", | ||
"gulp-plumber": "^1.0.0", | ||
"jshint-stylish": "^1.0.1", | ||
"mocha": "^2.2.1", | ||
"run-sequence": "^1.0.2", | ||
"sinon": "^1.14.1", | ||
"sinon-chai": "^2.7.0", | ||
"yargs": "^3.6.0", | ||
"babel": "^5.0.9" | ||
"chai": "~2.2.0", | ||
"chalk": "~1.0.0", | ||
"del": "~1.1.1", | ||
"gulp": "~3.8.11", | ||
"gulp-babel": "~5.0.0", | ||
"gulp-chmod": "~1.2.0", | ||
"gulp-jshint": "~1.10.0", | ||
"gulp-mocha": "~2.0.1", | ||
"gulp-plumber": "~1.0.0", | ||
"jshint-stylish": "~1.0.1", | ||
"mocha": "~2.2.1", | ||
"run-sequence": "~1.0.2", | ||
"sinon": "~1.14.1", | ||
"sinon-chai": "~2.7.0", | ||
"yargs": "~3.6.0", | ||
"babel": "~5.0.9" | ||
}, | ||
"dependencies": { | ||
"lodash": "^3.9.0" | ||
"lodash": "~3.9.0" | ||
} | ||
} |
@@ -194,29 +194,2 @@ # lodash-decorators | ||
### Getters | ||
When apply a decorator to a getter, a special annotation | ||
is required to distinguish between a getter property and | ||
an instance decorator. | ||
- `getter` | ||
#### Example | ||
```javascript | ||
import { getter, debounce } from 'lodash-decorators' | ||
class Person { | ||
constructor(firstName, lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
@getter | ||
@debounce(100) | ||
get name() { | ||
return `${this.firstName} ${this.lastName}`; | ||
} | ||
} | ||
``` | ||
### Bind | ||
@@ -223,0 +196,0 @@ |
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
21770
355
254
+ Addedlodash@3.9.3(transitive)
- Removedlodash@3.10.1(transitive)
Updatedlodash@~3.9.0