Last active
February 14, 2017 02:40
-
-
Save jeffwhelpley/8f862be52d555a8312de3b99184d1a05 to your computer and use it in GitHub Desktop.
Examples of different types of decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function ClassDecorator(meta?: any): Function { | |
return function (target: any) { | |
let targetProto = target.prototype; | |
let targetMeta = targetProto.__meta = targetProto.__meta || {}; | |
targetMeta.cls = meta; | |
}; | |
} | |
export function MethodDecorator(meta?: any): Function { | |
return function (targetProto: any, methodName: string) { | |
let targetMeta = targetProto.__meta = targetProto.__meta || {}; | |
targetMeta.methods = targetMeta.methods || {}; | |
targetMeta.methods[methodName] = meta; | |
}; | |
} | |
export function PropertyDecorator(meta?: any): Function { | |
return function (targetProto: any, propertyName: string) { | |
let targetMeta = targetProto.__meta = targetProto.__meta || {}; | |
targetMeta.properties = targetMeta.properties || {}; | |
targetMeta.properties[propertyName] = meta; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment