Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute的一处代码建议 #6

Closed
lianqin7 opened this issue Oct 11, 2012 · 5 comments
Closed

Attribute的一处代码建议 #6

lianqin7 opened this issue Oct 11, 2012 · 5 comments
Labels
Milestone

Comments

@lianqin7
Copy link
Member

@lifesinger

attribute.js里42-43行代码(initAttrs 方法中):

// Convert `on/before/afterXxx` config to event handler.
parseEventsFromAttrs(this, attrs);

这段代码的作用是做 自定义事件绑定及AOP绑定语法糖 ,不过attribute.js这个文件应该更专注于attribute的处理,这段代码及相关操作放base.js里会不会 更直观

P.S. 吐槽下,这是个非常好用的语法糖,可是各个文档里的都没有介绍,如果不是认真看了源码,还真可能漏了(囧) ,望文档补全,谢谢:)

@lifesinger
Copy link
Member

感谢 @lianqin7 的指正

这段代码放在 attribute.js 的确显得有点不妥当,我看能否移动到 base.js 里。
文档目前还缺不少,正在封装补充中,预计这个月会把基础组件的文档,以及组件开发等相关文档补全。

感谢。

@popomore
Copy link
Member

parseEventsFromInstance 绑定 _onChange

copySpecialProps 将指定属性复制到 this 上

感觉这两个都可以放到 base 中

@popomore
Copy link
Member

还有 �parseEventsFromAttrs #15

@popomore
Copy link
Member

copySpecialProps 有些特殊,在 getInheritedAttrs 也有处理,有点复杂,先不动了。

@popomore
Copy link
Member

原来的执行顺序 parseEventsFromInstance -> setSetterAttrs -> copySpecialProps

现在的执行顺序 setSetterAttrs -> copySpecialProps -> parseEventsFromInstance

parseEventsFromInstance 当有 '_onChangeXxx' 方法时监听属性变化的事件。

setSetterAttrs 如果属性有 setter 就调用一下 set 方法

copySpecialProps 将 attr 上的指定属性复制到 prop 上

从功能上看这三者并没有必然的联系,所以调整顺序应该不会有什么影响,而且初始化后再监听事件也是合情合理的。

popomore added a commit that referenced this issue Apr 23, 2013
popomore added a commit to aralejs/widget that referenced this issue May 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants