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

chore: add listeners and messages types for san.component #707

Closed
wants to merge 1 commit into from

Conversation

Wiihame
Copy link

@Wiihame Wiihame commented Feb 9, 2022

补充 Component 的 listeners 和 messages 属性的类型

types/index.d.ts Outdated
@@ -95,6 +95,9 @@ declare namespace san {

nodeType: NodeType.CMPT;
lifeCycle: LifeCycleStage;

listeners: ComponentListener<T>[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的listeners应该是object不是array

types/index.d.ts Outdated
@@ -95,6 +95,9 @@ declare namespace san {

nodeType: NodeType.CMPT;
lifeCycle: LifeCycleStage;

listeners: ComponentListener<T>[];
messages: ComponentDefineOptionMessages

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少行末分号

types/index.d.ts Outdated
@@ -469,6 +472,11 @@ declare namespace san {
nodeType: NodeType.SLOT;
}

interface ComponentListener<T> {
fn: DataChangeListener<T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ComponentListener 和 DataChangeListener不是一个东西,this的指向不同

Copy link
Contributor

@jinzhan jinzhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有些问题,看下评论

types/index.d.ts Outdated
@@ -469,6 +472,13 @@ declare namespace san {
nodeType: NodeType.SLOT;
}

interface ComponentListener<T> {
[k: string]: {
fn: (this: Component<T>, change: DataChangeInfo) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn 的参数是 event 啊,这个跟 Data 的listener是2个东西,别混淆了,https://github.com/baidu/san/blob/master/src/view/component.js#L471

@coveralls
Copy link

coveralls commented Feb 9, 2022

Pull Request Test Coverage Report for Build 1816984829

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.211%

Totals Coverage Status
Change from base Build 1665909351: 0.0%
Covered Lines: 3180
Relevant Lines: 3196

💛 - Coveralls

@errorrik
Copy link
Contributor

errorrik commented Feb 9, 2022

listeners 和 messages 不用加在 component 声明里。

  • listeners 本来就偏向私有成员,用于组件事件机制,通过 on 注册,fire 触发。绝大多数情况不应该感知它
  • messages 是组件声明的东西,和 computed、filters、template 等是一回事。不是像 el 这种,组件实例提供的,期望方法内可访问的属性。所以也不在 component 声明

@errorrik errorrik closed this Feb 9, 2022
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

Successfully merging this pull request may close these issues.

None yet

5 participants