我们大python这儿decorator已经流行好几年了。
随便哪个framework都用decorator。
自己开发程序也用这个来进行元编程。
据我观察,你这个有滥用decorator的嫌疑。。。。
在我python里看到这么多decorator一般就会换种写法了,
比如只对class进行装饰,或者用meta class pattern,或者用变量命名约束。
decorator本身不是一个很好维护的东西。
你这decorator的条款比类本身还多,这种代码估计过个一年半载自己都不想碰了。。。
【 在 facilitator (黄书中自有颜如玉 脸书中自有黄金屋) 的大作中提到: 】
: typescript的强大功能主要在于静态类型和@ decorator
: 静态类型的自动提示和查错功能就不用多说了
: 而有decorator的typescript可不止是个es6的马甲
: angular2是native typescript 里面绝大多数功能都是用decorator写的
: 我这也实现过一个用decorator做的动态双向数据绑定、函数-事件关联、Observable Array事件侦听等功能的框架
https://github.com/errisy/bindable: 我做的序列化标注方案和Remote Procedure Call方案都是用decorator写的
: 好的decorator应用 可以用极其简单的语法实现各种复杂的功能
: typescript另一个强大优势就在于它是一个开源的编译器 只要稍微改改编译器 就可以自动把typescript定义的类型和函数包括注释转译成其他语言
: 我现在写API完全是typescript的remote procedure call服务,然后利用编译器自动生成web前端typescript client类型和xamarin(android/ios共用)前端的C# client类型 连标注都直接转译过去 开发跨平台API完全不用写文档的
: decorator的例子:
:
: @obs.bindable
: class Person {
: @obs.property
: public Name: Name; //if you assign a Name object here, a binding will be automatically set up.
: @obs
: .bind(()=>Person.prototyope.Name.FirstName) //here defines the binding
: .before(()=>Person.prototype.beforeFirstNameChange)
: .after(()=>Person.prototype.FirstNameChanged)
: .property
: public FirstName: string;
: @obs.event
: public beforeFirstNameChange = () => {
: console.log('before first name is changed.');
: }
: @obs.event
: public FirstNameChanged = () => {
: console.log('first name is changed.');
: }
: }
: @obs.bindable
: class Name{
: @obs.property
: public Surname: string;
: @obs.property
: public FirstName: string;
: }
:
--
FROM 115.231.148.*