custom-ability
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -45,3 +45,3 @@ (function() { | ||
} | ||
result.push(vK); | ||
result.push(k); | ||
} | ||
@@ -101,3 +101,3 @@ } | ||
vExcludes = injectMethodsFromNonEnum(aClassPrototype, AbilityClass.prototype); | ||
extend(aClassPrototype, AbilityClass.prototype, function(k) { | ||
extendFilter(aClassPrototype, AbilityClass.prototype, function(k) { | ||
return !(indexOf.call(vExcludes, k) >= 0); | ||
@@ -104,0 +104,0 @@ }); |
{ | ||
"name": "custom-ability", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "make custom ability more easy. generate the ability which can be added to any class directly.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/snowyu/custom-ability.js", |
@@ -1,2 +0,2 @@ | ||
### 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) | ||
# 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) | ||
@@ -6,7 +6,6 @@ generate the ability which can be added to any class directly. | ||
Sometimes, we still feel that the class is a liitle big, and too many features in it. | ||
Sometimes, we still feel that the class is a little big, and too many features in it. | ||
We just need some of the features(methods) inside. So as a class developer can | ||
consider these functions to extract, as a kind of ability to the user. | ||
## Usage | ||
@@ -91,3 +90,2 @@ | ||
## additional $abilities | ||
@@ -153,3 +151,3 @@ | ||
# API | ||
## API | ||
@@ -162,3 +160,3 @@ just one function: | ||
## customAbility(abilityClass[, coreMethod[, isGetClassFunction]]) | ||
### customAbility(abilityClass[, coreMethod[, isGetClassFunction]]) | ||
@@ -181,8 +179,8 @@ __arguments__ | ||
* `options` *(object)*: optional options | ||
* `include `*(array|string)*: only these methods will be added to the class | ||
* `include`*(array|string)*: only these methods will be added to the class | ||
* **note**: `@` prefix means class/static method. | ||
* `exclude `*(array|string)*: these methods would not be added to the class | ||
* `exclude`*(array|string)*: these methods would not be added to the class | ||
* **note**: the `coreMethod` could not be excluded. It's always added to the class. | ||
* **note**: `@` prefix means class/static method. | ||
* `methods `*(object)*: injected/hooked methods to the class | ||
* `methods`*(object)*: injected/hooked methods to the class | ||
* key: the method name to hook. | ||
@@ -196,7 +194,6 @@ * value: the new method function, if original method is exists or not in replacedMethods: | ||
## Specification | ||
# Specification | ||
### V1.6.0 | ||
## 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. | ||
@@ -210,7 +207,8 @@ | ||
init(){ | ||
if (this.super && this.self) { | ||
inherited = this.super // the original init method | ||
that = this.self // the class instance | ||
inherited.apply(that, arguments) | ||
const Super = this.super // the original init method | ||
const that = this.self || this // the instance | ||
if (Super) { | ||
Super.apply(that, arguments) | ||
} | ||
// do the init from MyFeature | ||
console.log('init from MyFeature') | ||
@@ -234,3 +232,3 @@ }; | ||
## V1.5.0 | ||
### V1.5.0 | ||
@@ -241,3 +239,3 @@ * **broken change** the class method name conversation to: `@` prefix means class/static method. | ||
## V1.4.x | ||
### V1.4.x | ||
@@ -263,3 +261,3 @@ * Inject additional ability to each parent classes When the some parent classes has additional ability, | ||
$abilities: | ||
Test: -> # additinal ability to Test | ||
Test: -> # additional ability to Test | ||
methods: | ||
@@ -271,3 +269,3 @@ additional:-> | ||
$abilities: | ||
Test: -> # additinal ability to Test | ||
Test: -> # additional ability to Test | ||
methods: | ||
@@ -305,3 +303,3 @@ additional:-> Mid.__super__.additional.apply(@, arguments) | ||
## V1.3.3 | ||
### V1.3.3 | ||
@@ -333,6 +331,6 @@ + use the injectMethods(AOP) for the methods of non-enumerable and beginning with '$' in an ability | ||
## V1.3.x | ||
### V1.3.x | ||
+ add the replaceMethods option to custom ability function. | ||
* **<broken change>**: additional abilities usage changed | ||
* add the replaceMethods option to custom ability function. | ||
* **`<broken change>`**: additional abilities usage changed | ||
* separate ability options object. | ||
@@ -388,5 +386,4 @@ | ||
### V1.2.x *(deprecated)* | ||
## V1.2.x *(deprecated)* | ||
* Put the 'ability.js' file in your NPM Package folder which means this can be | ||
@@ -393,0 +390,0 @@ as ability. So you can use this way to get the ability: |
@@ -566,3 +566,4 @@ var assert, chai, customAbility, defineProperty, inherits, setImmediate, should, sinon, sinonChai; | ||
}); | ||
return describe('use the injectMethods(AOP) to hook', function() { | ||
describe('use the injectMethods(AOP) to hook', function() { | ||
var oneTestable; | ||
@@ -585,2 +586,4 @@ class OneAbility {}; | ||
OneAbility.prototype.init = sinon.spy(); | ||
OneAbility.cone = sinon.spy(); | ||
@@ -620,2 +623,3 @@ | ||
a = new A(123); | ||
OneAbility.prototype.init.should.not.be.called; | ||
OneAbility.prototype.$init.should.be.calledOnce; | ||
@@ -670,2 +674,41 @@ OneAbility.prototype.$init.should.be.calledWith(123); | ||
}); | ||
describe('How to ensure that the injected object does not have the same method', function() { | ||
var init = sinon.spy() | ||
var emit = sinon.spy() | ||
class TheAbility { | ||
constructor() { | ||
this.init.apply(this, arguments) | ||
} | ||
init() { | ||
var Super = this.super | ||
var that = this.self || this | ||
if (Super) { | ||
Super.apply(that, arguments) | ||
} | ||
init.apply(that, arguments) | ||
} | ||
emit() { | ||
emit.apply(this, arguments) | ||
} | ||
} | ||
var testable = customAbility(TheAbility, 'emit'); | ||
it('should call init correctly', () => { | ||
var oInit = sinon.spy() | ||
class My { | ||
constructor() { | ||
this.init.apply(this, arguments) | ||
} | ||
init() { | ||
oInit.apply(this, arguments) | ||
} | ||
} | ||
testable(My) | ||
new My(5,3,1) | ||
init.should.be.calledOnce | ||
init.should.be.calledWith(5,3,1) | ||
oInit.should.be.calledOnce | ||
oInit.should.be.calledWith(5,3,1) | ||
}); | ||
}); | ||
}); |
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
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
73852
978
0
420