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

fix(runtime): 修复、迭代生命周期 #6996

Merged
merged 7 commits into from
Jul 13, 2020
Merged

Conversation

Chen-jj
Copy link
Contributor

@Chen-jj Chen-jj commented Jul 10, 2020

这个 PR 做了什么? (简要描述所做更改)

修复

特性

这个 PR 是什么类型? (至少选择一个)

这个 PR 满足以下需求:

  • 提交到 next 分支
  • Commit 信息遵循 Angular Style Commit Message Conventions
  • 所有测试用例已经通过
  • 代码遵循相关包中的 .eslintrc, .tslintrc, .stylelintrc 所规定的规范
  • 在本地测试可用,不会影响到其它功能

这个 PR 涉及以下平台:

  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 头条小程序
  • QQ 轻应用
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)

* 生命周期 hooks 在组件销毁时,同时销毁监听回调。
* 修复页面为 Class 组件,子组件使用生命周期 hooks 时不触发回调的问题。
* 增加 onAddToFavorites、onShareTimeline 页面事件 hooks
* 【Breaking】使用 onShareAppMessage,useShareAppMessage 时,必须设置页面的 enableShareAppMessage 属性为 true,#6825
@Chen-jj Chen-jj merged commit b2398fc into next Jul 13, 2020
@Chen-jj Chen-jj deleted the fix/runtime-lifecycle branch July 13, 2020 12:33
@fjc0k fjc0k mentioned this pull request Jul 14, 2020
20 tasks
}

// onShareAppMessage 和 onShareTimeline 一样,会影响小程序右上方按钮的选项,因此不能默认注册。
if (component.onShareAppMessage || component.enableShareAppMessage) {
Copy link
Contributor

@cncolder cncolder Jul 14, 2020

Choose a reason for hiding this comment

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

@Chen-jj 这里不应该是 component.prototype.onShareAppMessage 吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

component.onShareAppMessage 是给 Vue 用的,根据 prototype 判断可以加下,那么 Class Component 就不用配置 enable 了。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

记录一下:这样还是不完美,HOC 如 connect 后的页面组件会跪,还是要编译时处理一下以自动兼容大部分情况。

} else {
inst![lifecycle] = callback
if (isFunction(inst[lifecycle])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Chen-jj 如果上面 common.ts 里修复了, 页面实例就没有默认的 onShareAppMessage 回调了, 在函数式组件里 inst[lifecycle] 永远是 undefined, 我们还是应该用 lifecycle 这个字符串上来判断, 以实现页面第一次初始化时设置 onShareAppMessage/onShareTimeline/onAddToFavorites

Copy link
Contributor Author

Choose a reason for hiding this comment

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

createPageConfig 时 inst 是 undefined,小程序 onLoad 时才会绑定。

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