diff --git a/changelog.md b/changelog.md index 3732cf5..62f0018 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,46 @@ +## 0.1.12 (2015-08-20) + +Update: +* @filter + +> the $stateful property is now deprecated +> use the stateful parameter instead + +*before* + +````javascript +import {filter, inject} from 'node_modules/ng-annotations'; + +@filter('statefulFilter') +@inject('someDependency') +class StatefulFilter { + $stateful = true; + $filter(input) { + return input; //do something with the dependency + } +} + +```` + +*after* + +````javascript +import {filter, inject} from 'node_modules/ng-annotations'; + +@filter({name: 'statefulFilter', stateful:true}) +@inject('someDependency') +class StatefulFilter { + $filter(input) { + return input; //do something with the dependency + } +} + +```` + + ## 0.1.11 (2015-08-20) -Bugfix: +Feature: * @filter > now supports the stateful filters diff --git a/package.json b/package.json index e0a3dc3..ddd3028 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ng-annotations", - "version": "0.1.11", + "version": "0.1.12", "description": "angular wrapper based on annotations", "main": "index.js", "scripts": { diff --git a/readme.md b/readme.md index f3d5247..5ca42af 100644 --- a/readme.md +++ b/readme.md @@ -548,7 +548,9 @@ export default class SomeRun { #### type: *function* #### Params: - - **name**: *(Optional)* String. angular filter name, by default the decorator will take the class name. + - **properties**: *(Optional)* Object|String. angular filter properties. contains the name and the stateful attribute + - name: String. angular filter name, by default the decorator will take the class name. + - stateful: Boolean. default false #### Usage: > The decorated filter is slightly different than the original. @@ -571,17 +573,16 @@ export default class Capitalize { ```` #### Note: -> If you need to write a stateful filter, you have to mark the filter as `$stateful` by defining a $stateful property to true +> If you need to write a stateful filter, you must give a literal objet as parameter to the filter decorator ````javascript //inspired by https://docs.angularjs.org/guide/filter import {filter, inject, attach} from 'node_modules/ng-annotations'; -@filter('decorate') +@filter({name:'decorate', stateful:true}) @inject('decoration') export default Decorate { - $stateful=true; @attach('decoration', 'symbol') decorator; diff --git a/src/decorators/components/filter.js b/src/decorators/components/filter.js index 3c43e5e..49249f6 100644 --- a/src/decorators/components/filter.js +++ b/src/decorators/components/filter.js @@ -7,13 +7,21 @@ import inject from 'src/decorators/utils/inject'; * * declares a new angular filter * - * @param name (optional) replaces the class name + * @param filterProps (optional) filter properties containing name and the stateful attribute * * @returns {Function} */ -export default function NgFilter(name = '') { +export default function NgFilter(filterProps = {name:'',stateful:false}) { + return (target) => { - name = name || target.name; + + let name = '', stateful = false; + if(filterProps instanceof Object){ + name = filterProps.name || target.name; + stateful = !!filterProps.stateful; + } + else + name = filterProps || target.name; var component = function(...injections) { let instance = new target(...injections); @@ -22,8 +30,15 @@ export default function NgFilter(name = '') { throw Error('an annotated "filter" must implement the "$filter" method'); utils.applyTransformations(target, instance, injections); - if(instance.$stateful === true) + //@todo remove it in the next version + if(instance.$stateful === true) { + console.warn('the $stateful property is deprecated and will be removed in the next versions, use the @filter parameter instead'); + console.warn('https://github.com/PillowPillow/ng-annotations#d_filter'); filter.$stateful = true; + } + + if(stateful) + filter.$stateful = stateful; return filter; function filter(...parameters) {