custom-ability
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -1,1 +0,2 @@ | ||
module.exports = require("./lib/custom-ability") | ||
var ability = module.exports = require("./lib/custom-ability") | ||
ability.require = require('./lib/require') |
@@ -40,3 +40,3 @@ (function() { | ||
} else if (!((vCoreMethod && aClass.prototype[vCoreMethod]) || (vName && aClass.prototype.$abilities && aClass.prototype.$abilities['$' + vName]))) { | ||
if (!(aOptions && aOptions.inited) && vName && aClass.prototype.$abilities && (vAbility = aClass.prototype.$abilities[vName.toLowerCase()])) { | ||
if (!(aOptions && aOptions.inited) && vName && aClass.prototype.$abilities && (vAbility = aClass.prototype.$abilities[vName])) { | ||
if (aOptions) { | ||
@@ -43,0 +43,0 @@ aOptions.inited = true; |
{ | ||
"name": "custom-ability", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"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", |
@@ -6,3 +6,7 @@ ### 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) | ||
Sometimes, we still feel that the class is a liitle big, and too many features in it. | ||
We just need some of the features inside. So as a class developer can | ||
consider these functions to extract, as a kind of ability to the user. | ||
# API | ||
@@ -43,3 +47,53 @@ | ||
# Specification | ||
## V1.2.x | ||
* Put the 'ability.js' file in your NPM Package folder which means this can be | ||
as ability. So you can use this way to get the ability: | ||
```coffee | ||
ability = require('custom-ability/require') | ||
class MyClass | ||
#get the stateable ability from AbstractObject for MyClass | ||
ability 'abstract-object', MyClass | ||
``` | ||
* Put the '$abilities'*(object)* property on your prototype of class if need to modify | ||
the class before apply ability. | ||
* the `$abilities` object key is the AbilityClass Name | ||
* the value is the modified ability function | ||
```coffee | ||
AbstractObject = require('./lib/abstract-object') | ||
AbstractObject.$abilities = { | ||
# "Eventable" is the AbilityClass name | ||
# the value is modified ability function. | ||
Eventable: require('./eventable') | ||
} | ||
module.exports = AbstractObject | ||
``` | ||
the AbstractObject's 'eventable' function: | ||
```coffee | ||
eventable = require 'events-ex/eventable' | ||
module.exports = (aClass)-> | ||
eventable aClass, methods: | ||
# override methods: | ||
# we need to emit event when object state changes. | ||
setObjectState: (value, emitted = true)-> | ||
self= @self | ||
@super.call(self, value) | ||
self.emit value, self if emitted | ||
return | ||
... | ||
# more detail on [AbstractObject/src/eventable](https://github.com/snowyu/abstract-object) | ||
``` | ||
## Usage | ||
@@ -161,5 +215,6 @@ | ||
AbstractObject.$abilities = | ||
eventable: require('./eventable') | ||
# "Eventable" is the AbilityClass name | ||
Eventable: require('./eventable') | ||
module.exports = AbstractObject | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
28729
15
135
218