lodash-decorators
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -36,2 +36,4 @@ 'use strict'; | ||
var getterSetterMap = new _utilsCompositeKeyWeakMap2['default'](); | ||
return applicator === applicators.single ? wrapper() : wrapper; | ||
@@ -47,6 +49,12 @@ | ||
var get = descriptor.get; | ||
var set = descriptor.set; | ||
if (get) { | ||
if (get && !getterSetterMap.has([target, name, 'get'])) { | ||
descriptor.get = _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, target, get].concat(args)); | ||
_Applicator2['default'].copyMetaData(get, descriptor.get); | ||
getterSetterMap.set([target, name, 'get'], descriptor.get); | ||
} else if (set && !getterSetterMap.has([target, name, 'set'])) { | ||
descriptor.set = _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, target, set].concat(args)); | ||
_Applicator2['default'].copyMetaData(get, descriptor.set); | ||
getterSetterMap.set([target, name, 'set'], descriptor.set); | ||
} else if (value) { | ||
@@ -66,2 +74,3 @@ descriptor.value = _Applicator2['default'].invoke.apply(_Applicator2['default'], [applicator, method, target, value].concat(args)); | ||
var objectMap = new _utilsCompositeKeyWeakMap2['default'](); | ||
var getterSetterMap = new _utilsCompositeKeyWeakMap2['default'](); | ||
@@ -78,9 +87,12 @@ return applicator === applicators.single ? wrapper() : wrapper; | ||
var get = descriptor.get; | ||
var set = descriptor.set; | ||
var toWrap = get ? get : value; | ||
if (get) { | ||
descriptor.get = _Applicator2['default'].copyMetaData(toWrap, instanceDecoratorWrapper); | ||
} else { | ||
descriptor.value = _Applicator2['default'].copyMetaData(toWrap, instanceDecoratorWrapper); | ||
if (get && !getterSetterMap.has([target, name, 'get'])) { | ||
descriptor.get = _Applicator2['default'].copyMetaData(get, (0, _lodashFunctionPartial2['default'])(instanceDecoratorWrapper, get)); | ||
getterSetterMap.set([target, name, 'get'], descriptor.get); | ||
} else if (set && !getterSetterMap.has([target, name, 'set'])) { | ||
descriptor.set = _Applicator2['default'].copyMetaData(set, (0, _lodashFunctionPartial2['default'])(instanceDecoratorWrapper, set)); | ||
getterSetterMap.set([target, name, 'set'], descriptor.set); | ||
} else if (value) { | ||
descriptor.value = _Applicator2['default'].copyMetaData(value, (0, _lodashFunctionPartial2['default'])(instanceDecoratorWrapper, value)); | ||
} | ||
@@ -90,5 +102,5 @@ | ||
function instanceDecoratorWrapper() { | ||
for (var _len3 = arguments.length, methodArgs = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
methodArgs[_key3] = arguments[_key3]; | ||
function instanceDecoratorWrapper(toWrap) { | ||
for (var _len3 = arguments.length, methodArgs = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
methodArgs[_key3 - 1] = arguments[_key3]; | ||
} | ||
@@ -95,0 +107,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "A collection of decorators using lodash at it's core.", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"engines": { | ||
@@ -8,0 +8,0 @@ "node": ">=0.12.0" |
@@ -7,2 +7,25 @@ # lodash-decorators | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
- [Install](#install) | ||
- [Usage](#usage) | ||
- [With Arguments](#with-arguments) | ||
- [Example](#example) | ||
- [Without Arguments](#without-arguments) | ||
- [Example](#example-1) | ||
- [Partials](#partials) | ||
- [Example](#example-2) | ||
- [Composition](#composition) | ||
- [Example](#example-3) | ||
- [Instance Decorators](#instance-decorators) | ||
- [Getters and Setters](#getters-and-setters) | ||
- [Example](#example-4) | ||
- [Bind](#bind) | ||
- [Example](#example-5) | ||
- [Example](#example-6) | ||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
## Install | ||
@@ -195,2 +218,32 @@ | ||
### Getters and Setters | ||
Most decorators can be applied directly to getter and setter methods. | ||
#### Example | ||
```javascript | ||
import { once } from 'lodash-decorators' | ||
import _ from 'lodash'; | ||
class Person { | ||
constructor() {} | ||
@once | ||
get name() { | ||
return `${this.firstName} ${this.lastName}`; | ||
} | ||
@compose(_.trim) | ||
set name(name) { | ||
[this.firstName, this.lastName] = name.split(' '); | ||
} | ||
} | ||
const person = new Person(); | ||
person.name = ' Joe Smith '; | ||
person.name; //=> Joe Smith | ||
``` | ||
### Bind | ||
@@ -197,0 +250,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
26479
406
307