custom-ability
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -32,4 +32,6 @@ (function() { | ||
var v, vK; | ||
if (k[0] === '$' && isFunction(v = aObject[k])) { | ||
k = k.substr(1); | ||
if ((isStatic || k !== 'constructor') && isFunction(v = aObject[k])) { | ||
if (k[0] === '$') { | ||
k = k.substr(1); | ||
} | ||
vK = isStatic ? '@' + k : k; | ||
@@ -44,3 +46,2 @@ if (!filter || filter(vK)) { | ||
} | ||
delete aObject[k]; | ||
result.push(vK); | ||
@@ -74,3 +75,3 @@ } | ||
if (vhasCoreMethod[0] !== '@') { | ||
vhasCoreMethod = aClass.prototype.hasOwnProperty(vhasCoreMethod); | ||
vhasCoreMethod = aClassPrototype.hasOwnProperty(vhasCoreMethod); | ||
} else { | ||
@@ -77,0 +78,0 @@ vhasCoreMethod = vhasCoreMethod.substr(1); |
{ | ||
"name": "custom-ability", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "make custom ability more easy. generate the ability which can be added to any class directly.", | ||
@@ -19,11 +19,12 @@ "homepage": "https://github.com/snowyu/custom-ability.js", | ||
"dependencies": { | ||
"inherits-ex": "~1.2.0", | ||
"inherits-ex": "~1.3.0", | ||
"util-ex": "^0.3.15" | ||
}, | ||
"devDependencies": { | ||
"chai": "~4.1.0", | ||
"chai": "~2.0.0", | ||
"coffee-script": "^1.12.7", | ||
"connect-livereload": "*", | ||
"grunt": "*", | ||
"grunt-contrib-clean": "*", | ||
"grunt-contrib-coffee": "*", | ||
"grunt-contrib-coffee": "1.0.0", | ||
"grunt-contrib-copy": "*", | ||
@@ -34,4 +35,2 @@ "grunt-contrib-jshint": "*", | ||
"grunt-newer": "*", | ||
"grunt-release": "*", | ||
"grunt-saucelabs": "*", | ||
"mocha": "~3.4.2", | ||
@@ -51,2 +50,3 @@ "pre-commit": "~1.2.2", | ||
"keywords": [ | ||
"feature", | ||
"ability", | ||
@@ -57,7 +57,5 @@ "object", | ||
"prototype", | ||
"state", | ||
"stateful", | ||
"event", | ||
"aop", | ||
"framework", | ||
"reference", | ||
"addref", | ||
"refcount" | ||
@@ -64,0 +62,0 @@ ], |
@@ -96,3 +96,3 @@ ### custom-ability [![Build Status](https://img.shields.io/travis/snowyu/custom-ability.js/master.png)](http://travis-ci.org/snowyu/custom-ability.js) [![npm](https://img.shields.io/npm/v/custom-ability.svg)](https://npmjs.org/package/custom-ability) [![downloads](https://img.shields.io/npm/dm/custom-ability.svg)](https://npmjs.org/package/custom-ability) [![license](https://img.shields.io/npm/l/custom-ability.svg)](https://npmjs.org/package/custom-ability) | ||
the "additional abilities" now. eg, the event-able ability to [AbstractObject](https://github.com/snowyu/abstract-object). | ||
We need to send a notification event when the state of the object changes. | ||
We need to send a notification event when the state of the object changes(life cycle). | ||
So the event-able of [AbstractObject](https://github.com/snowyu/abstract-object) | ||
@@ -164,3 +164,3 @@ should be: | ||
* abilityClass *(function)*: the class will become to ability able. | ||
* abilityClass *(function)*: the class will become to abilitiable. | ||
* coreMethod *(string|arrayOf string)*: optional must have coreMethod(s). | ||
@@ -196,2 +196,35 @@ * **note**: `@` prefix means class/static method. | ||
## V1.6.0 | ||
* **broken change** The methods in ES6 Class all are non-enumerable. So they have an ability to call `super` method too if the target has the same method. | ||
```javascript | ||
const createAbility = require('custom-ability') | ||
class MyFeature { | ||
static coreAbilityClassMethod(){}; | ||
coreAbilityMethod(){}; | ||
init(){ | ||
if (this.super && this.self) { | ||
inherited = this.super // the original init method | ||
that = this.self // the class instance | ||
inherited.apply(that, arguments) | ||
} | ||
console.log('init from MyFeature') | ||
}; | ||
} | ||
const addFeatureTo = createAbility(MyFeature, ['coreAbilityMethod', '@coreAbilityClassMethod']); | ||
class MyClass { | ||
init(hi) { | ||
console.log('init from MyClass', hi) | ||
} | ||
} | ||
// inject the static and instance methods to the MyClass. | ||
addFeatureTo(MyClass); | ||
const instance = new MyClass; | ||
instance.init('hello'); | ||
``` | ||
## V1.5.0 | ||
@@ -267,3 +300,3 @@ | ||
+ use the injectMethods(AOP) for the methods of non-enumerable and beginning with '$' in an ability | ||
to call `super` method. you can exclude it with normal name if it's not a core method. | ||
to call `super` method if the target has the same method. you can exclude it with normal name if it's not a core method. | ||
@@ -278,3 +311,3 @@ ```coffee | ||
defineProperty @::, '$initialize', -> | ||
options = arugments[gOptPos] | ||
options = arguments[gOptPos] | ||
options?={} | ||
@@ -285,3 +318,3 @@ that = @ | ||
that = @self | ||
inherited.apply(that, arugments) | ||
inherited.apply(that, arguments) | ||
that._initialize options if isFunction that._initialize | ||
@@ -288,0 +321,0 @@ that.defineProperties(options.attributes) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
72731
16
23
938
423
1
+ Addedinherits-ex@1.3.6(transitive)
- Removedinherits-ex@1.2.3(transitive)
Updatedinherits-ex@~1.3.0