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

vue源码阅读: src/compiler/helpers.js #31

Open
Link-Fight opened this issue Aug 12, 2019 · 0 comments
Open

vue源码阅读: src/compiler/helpers.js #31

Link-Fight opened this issue Aug 12, 2019 · 0 comments

Comments

@Link-Fight
Copy link
Owner

Link-Fight commented Aug 12, 2019

vue的源码阅读

vue的使用一直伴随着本人的前端生涯,从刚刚开始的的vue@1.0.15vue@2.6.0
一开始只是在官网的API文档中翻江倒海,后来是到各大社区中东翻西找,现在还是回归到源码来大佬淘沙。
从vue的1.x版本起,就断断续续再看源码,现在到vue2.x版本还是在断断续续地看。目的性不强,没有想着折腾篇读后感,去社区混下知名度。这两三年过去了,发现源码好像没看个完全,在社区还是默默潜水。
想了想,还是要留下点什么,记录点什么。


源码:compiler/helpers.js,当前git版本号是dbc05825

这文件是在compiler目录下,该目录下的代码主要工作内容是解析template就是模板的内容,而该文件helpers.js就是一个工具集,提供一些工具方法来便于解析模板。

function pluckModuleFunction // 从同类型modules提取相同的key的值出来

function addProp // 增加到props属性集合

function addAttr // 根据dynamic参数,分别加入到dynamicAttrs或attrs集合

function addRawAttr // 加入到attrsMap集合,以name为key,同时push入attrsList数组

function addDirective // 把指令都收集到directives集合中

function prependModifierMarker // 用于处理加了修饰的事件处理的事件名,例如对于click.capture根据dynamic参数,分别产生`_p(click,!)`或`!click`的事件名,主要是在下面的addHandler上归类到对于的事件集合中

function addHandler // 用于处理ast节点上的绑定的事件,将分别加入到nativeEvents或events集合中

通过查看git的log记录,已有52次提交记录。主要涉及到的issue有:

#3468:确保v-modal比v-on有更高的优先级。在该文件中,主要就是给addHandler暴漏出个important参数,这可以控制在添加事件时候,事件是加在队列头还是尾部。

#8492:把事件修饰符为click.right/click.middle规范为contextmenumouseup事件

'#7127':有更加详细的错误信息输出

'#4267':v-on支持once修饰符

'#9373':支持动态指令参数

#7020:实现.right.middle修饰符下的事件监听,其实际是监听contextmenumouseup事件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant