提交 c37c3e6c 编写于 作者: fxy060608's avatar fxy060608

feat(mp): support page lifecycle in component

上级 739e0b48
...@@ -30,6 +30,19 @@ const ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED = 'onNavigationBarSearchInputClicke ...@@ -30,6 +30,19 @@ const ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED = 'onNavigationBarSearchInputClicke
const ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED = 'onNavigationBarSearchInputChanged'; const ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED = 'onNavigationBarSearchInputChanged';
const ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED = 'onNavigationBarSearchInputConfirmed'; const ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED = 'onNavigationBarSearchInputConfirmed';
const ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED = 'onNavigationBarSearchInputFocusChanged'; const ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED = 'onNavigationBarSearchInputFocusChanged';
const PAGE_HOOKS = [
ON_SHOW,
ON_HIDE,
ON_BACK_PRESS,
ON_PAGE_SCROLL,
ON_TAB_ITEM_TAP,
ON_REACH_BOTTOM,
ON_PULL_DOWN_REFRESH,
];
function isRootHook(name) {
return PAGE_HOOKS.indexOf(name) > -1;
}
const UniLifecycleHooks = [ const UniLifecycleHooks = [
ON_SHOW, ON_SHOW,
ON_HIDE, ON_HIDE,
...@@ -1491,6 +1504,10 @@ function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) { ...@@ -1491,6 +1504,10 @@ function injectToKeepAliveRoot(hook, type, target, keepAliveRoot) {
function injectHook(type, hook, target = currentInstance, prepend = false) { function injectHook(type, hook, target = currentInstance, prepend = false) {
if (target) { if (target) {
// fixed by xxxxxx
if (isRootHook(type)) {
target = target.root;
}
const hooks = target[type] || (target[type] = []); const hooks = target[type] || (target[type] = []);
// cache the error handling wrapper for injected hooks so the same hook // cache the error handling wrapper for injected hooks so the same hook
// can be properly deduped by the scheduler. "__weh" stands for "with error // can be properly deduped by the scheduler. "__weh" stands for "with error
...@@ -1506,7 +1523,7 @@ function injectHook(type, hook, target = currentInstance, prepend = false) { ...@@ -1506,7 +1523,7 @@ function injectHook(type, hook, target = currentInstance, prepend = false) {
// Set currentInstance during hook invocation. // Set currentInstance during hook invocation.
// This assumes the hook does not synchronously trigger other hooks, which // This assumes the hook does not synchronously trigger other hooks, which
// can only be false when the user does something really funky. // can only be false when the user does something really funky.
setCurrentInstance(target); setCurrentInstance(target); // fixed by xxxxxx
const res = callWithAsyncErrorHandling(hook, target, type, args); const res = callWithAsyncErrorHandling(hook, target, type, args);
unsetCurrentInstance(); unsetCurrentInstance();
resetTracking(); resetTracking();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册