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(taro): 修复小程序生命周期 hook 在 rerender 后只触发最后一个 #4642

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/taro/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@ export function useState (initialState) {

function usePageLifecycle (callback, lifecycle) {
const hook = getHooks(Current.index++)
let originalLifecycle
hook.component = Current.current
const component = hook.component

if (!hook.marked) {
hook.marked = true
originalLifecycle = component[lifecycle]
}
hook.component[lifecycle] = function () {
originalLifecycle && originalLifecycle.call(component, ...arguments)
return callback && callback.call(component, ...arguments)
hook.component = Current.current
hook.callback = callback

const component = hook.component
const originalLifecycle = component[lifecycle]

hook.component[lifecycle] = function () {
const callback = hook.callback
originalLifecycle && originalLifecycle.call(component, ...arguments)
return callback && callback.call(component, ...arguments)
}
} else {
hook.callback = callback
}
}

Expand Down