-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor(components): [backTop] refactor #5371
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,20 @@ export const backTopProps = { | |
// visible: PropTypes.looseBool, // Only for test. Don't use it. | ||
}; | ||
|
||
export const backTopEmits = { | ||
click: (e: Event) => e instanceof Event, | ||
}; | ||
export type BackTopEmits = typeof backTopEmits; | ||
|
||
export type BackTopInstance = InstanceType<typeof BackTop>; | ||
|
||
export type BackTopProps = Partial<ExtractPropTypes<typeof backTopProps>>; | ||
|
||
const BackTop = defineComponent({ | ||
name: 'ABackTop', | ||
inheritAttrs: false, | ||
props: backTopProps, | ||
emits: ['click'], | ||
emits: backTopEmits, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我们计划去掉 emits 声明,全都放入 props 中去声明 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔全部放props里面?这样不好吧,vue不同于react,react所有的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在之前issue中也能找到一些相关的问题,但是在 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我觉得合并数组的问题可以尝试给 vue 提PR,添加配置项 如果想统一掉,props 是一个合适(唯一)的选择 PS:在 vue2中,props + emits + slots相对独立,在 vue3 中已经渐渐淡化这个概念了,而且 slots 未来有可能也会有定义在 props 中的语法糖:vuejs/rfcs#192 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 关于您提到的两点: PS:在vue3中,以前vue2中适用的概念确实被淡化了不少,但我觉得slots被定义在props这个可能性不大,而且之前vue与ts存在的类型系统断层问题,现在通过工具链的支持已经变得很好了,即是说vue与ts相性不好的问题通过工具链的桥接一样可以做到react + ts的体验。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
对于组件库来说,统一规范定义在props,可以减少很多工作量。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 对于非文档中公开的API(黑科技)的使用确实需要考量,行!那我明白了。然后大概看了下目录源码,感觉还可以精简很多 |
||
setup(props, { slots, attrs, emit }) { | ||
const { prefixCls, direction } = useConfigInject('back-top', props); | ||
const domRef = ref(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个主要用来做什么用呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些用到的时候自然有用,例如:通过ref调用组件实例方法的时候
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个我们只需要暴露组件内 expose 出去的方法就好了,其他方法都是不安全的,不应该暴露给用户。
如果非要用,在用户层面自己 InstanceType 好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK