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

feat: app lifecycle

上级 6f15a5a1
import { isArray, isFunction, isPlainObject } from '@vue/shared' import { isArray, isFunction, isPlainObject, remove } from '@vue/shared'
import { import {
HOOKS, HOOKS,
...@@ -38,12 +38,11 @@ function removeInterceptorHook( ...@@ -38,12 +38,11 @@ function removeInterceptorHook(
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return return
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook as HOOKS])) { const hooks = interceptors[name as HOOKS]
removeHook( const hook = interceptor[name as HOOKS]
interceptors[hook as HOOKS], if (isArray(hooks) && isFunction(hook)) {
interceptor[hook as HOOKS] as Function remove(hooks, hook)
)
} }
}) })
} }
...@@ -72,16 +71,6 @@ function dedupeHooks(hooks: Function[]) { ...@@ -72,16 +71,6 @@ function dedupeHooks(hooks: Function[]) {
return res return res
} }
function removeHook(hooks: Function[] | undefined, hook: Function) {
if (!hooks) {
return
}
const index = hooks.indexOf(hook)
if (index !== -1) {
hooks.splice(index, 1)
}
}
export const addInterceptor = defineSyncApi( export const addInterceptor = defineSyncApi(
API_ADD_INTERCEPTOR, API_ADD_INTERCEPTOR,
(method: string | Interceptor, interceptor: Interceptor | undefined) => { (method: string | Interceptor, interceptor: Interceptor | undefined) => {
......
import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform' import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform'
import { ON_HIDE, ON_SHOW } from '@dcloudio/uni-shared' import {
import { defineSyncApi } from '../../helpers/api' ON_ERROR,
ON_HIDE,
ON_PAGE_NOT_FOUND,
ON_SHOW,
ON_UNHANDLE_REJECTION,
} from '@dcloudio/uni-shared'
import { ComponentInternalInstance, injectHook } from 'vue' import { ComponentInternalInstance, injectHook } from 'vue'
import { removeHook } from '@dcloudio/uni-core'
import { remove } from '@vue/shared'
import { defineSyncApi } from '../../helpers/api'
type AppShowHook = (options: UniApp.LaunchOptionsApp) => void type AppShowHook = (options: UniApp.LaunchOptionsApp) => void
type AppHideHook = () => void type AppHideHook = () => void
interface AppHooks { interface AppHooks {
onUnhandledRejection: UniApp.OnUnhandledRejectionCallback[]
onPageNotFound: UniApp.OnPageNotFoundCallback[]
onError: UniApp.OnAppErrorCallback[]
onShow: AppShowHook[] onShow: AppShowHook[]
onHide: AppHideHook[] onHide: AppHideHook[]
} }
const appHooks: AppHooks = { const appHooks: AppHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [], [ON_SHOW]: [],
[ON_HIDE]: [], [ON_HIDE]: [],
} }
...@@ -24,21 +38,64 @@ function onAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) { ...@@ -24,21 +38,64 @@ function onAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) {
appHooks[type].push(hook) appHooks[type].push(hook)
} }
export function injectAppHooks(appInstance: ComponentInternalInstance) {
Object.keys(appHooks).forEach((type) => {
appHooks[type as keyof AppHooks].forEach((hook) => {
injectHook(type, hook, appInstance)
})
})
}
function offAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) {
const app = getApp({ allowDefault: true })
if (app && app.$vm) {
return removeHook(app.$vm, type, hook)
}
remove(appHooks[type] as Function[], hook)
}
export function onUnhandledRejection(
hook: UniApp.OnUnhandledRejectionCallback
) {
onAppHook(ON_UNHANDLE_REJECTION, hook)
}
export function offUnhandledRejection(
hook: UniApp.OnUnhandledRejectionCallback
) {
offAppHook(ON_UNHANDLE_REJECTION, hook)
}
export function onPageNotFound(hook: UniApp.OnPageNotFoundCallback) {
onAppHook(ON_PAGE_NOT_FOUND, hook)
}
export function offPageNotFound(hook: UniApp.OnPageNotFoundCallback) {
offAppHook(ON_PAGE_NOT_FOUND, hook)
}
export function onError(hook: UniApp.OnAppErrorCallback) {
onAppHook(ON_ERROR, hook)
}
export function offError(hook: UniApp.OnAppErrorCallback) {
offAppHook(ON_ERROR, hook)
}
export function onAppShow(hook: AppShowHook) { export function onAppShow(hook: AppShowHook) {
onAppHook(ON_SHOW, hook) onAppHook(ON_SHOW, hook)
} }
export function offAppShow(hook: AppShowHook) {
offAppHook(ON_SHOW, hook)
}
export function onAppHide(hook: AppHideHook) { export function onAppHide(hook: AppHideHook) {
onAppHook(ON_HIDE, hook) onAppHook(ON_HIDE, hook)
} }
export function injectAppHooks( export function offAppHide(hook: AppHideHook) {
type: keyof AppHooks, offAppHook(ON_HIDE, hook)
appInstance: ComponentInternalInstance
) {
appHooks[type].forEach((hook) => {
injectHook(type, hook, appInstance)
})
} }
type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync
......
...@@ -106,6 +106,12 @@ var serviceContext = (function (vue) { ...@@ -106,6 +106,12 @@ var serviceContext = (function (vue) {
: {}; : {};
(process.env.NODE_ENV !== 'production') ? Object.freeze([]) : []; (process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
const extend = Object.assign; const extend = Object.assign;
const remove = (arr, el) => {
const i = arr.indexOf(el);
if (i > -1) {
arr.splice(i, 1);
}
};
const hasOwnProperty$1 = Object.prototype.hasOwnProperty; const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
const hasOwn$1 = (val, key) => hasOwnProperty$1.call(val, key); const hasOwn$1 = (val, key) => hasOwnProperty$1.call(val, key);
const isArray$1 = Array.isArray; const isArray$1 = Array.isArray;
...@@ -2172,6 +2178,13 @@ var serviceContext = (function (vue) { ...@@ -2172,6 +2178,13 @@ var serviceContext = (function (vue) {
}; };
} }
function removeHook(vm, name, hook) {
const hooks = vm.$[name];
if (!isArray$1(hooks)) {
return;
}
remove(hooks, hook);
}
function invokeHook(vm, name, args) { function invokeHook(vm, name, args) {
if (isString(vm)) { if (isString(vm)) {
args = name; args = name;
...@@ -9863,9 +9876,11 @@ var serviceContext = (function (vue) { ...@@ -9863,9 +9876,11 @@ var serviceContext = (function (vue) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray$1(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -9888,15 +9903,6 @@ var serviceContext = (function (vue) { ...@@ -9888,15 +9903,6 @@ var serviceContext = (function (vue) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
...@@ -11652,6 +11658,64 @@ var serviceContext = (function (vue) { ...@@ -11652,6 +11658,64 @@ var serviceContext = (function (vue) {
}); });
}); });
const appHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [],
[ON_HIDE]: [],
};
function onAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return vue.injectHook(type, hook, app.$vm.$);
}
appHooks[type].push(hook);
}
function injectAppHooks(appInstance) {
Object.keys(appHooks).forEach((type) => {
appHooks[type].forEach((hook) => {
vue.injectHook(type, hook, appInstance);
});
});
}
function offAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return removeHook(app.$vm, type, hook);
}
remove(appHooks[type], hook);
}
function onUnhandledRejection(hook) {
onAppHook(ON_UNHANDLE_REJECTION, hook);
}
function offUnhandledRejection(hook) {
offAppHook(ON_UNHANDLE_REJECTION, hook);
}
function onPageNotFound(hook) {
onAppHook(ON_PAGE_NOT_FOUND, hook);
}
function offPageNotFound(hook) {
offAppHook(ON_PAGE_NOT_FOUND, hook);
}
function onError(hook) {
onAppHook(ON_ERROR, hook);
}
function offError(hook) {
offAppHook(ON_ERROR, hook);
}
function onAppShow(hook) {
onAppHook(ON_SHOW, hook);
}
function offAppShow(hook) {
offAppHook(ON_SHOW, hook);
}
function onAppHide(hook) {
onAppHook(ON_HIDE, hook);
}
function offAppHide(hook) {
offAppHook(ON_HIDE, hook);
}
const API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync'; const API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync';
const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions(); return getEnterOptions();
...@@ -17527,6 +17591,7 @@ var serviceContext = (function (vue) { ...@@ -17527,6 +17591,7 @@ var serviceContext = (function (vue) {
// } // }
function initAppLaunch(appVm) { function initAppLaunch(appVm) {
injectAppHooks(appVm.$);
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig; const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig;
const args = initLaunchOptions({ const args = initLaunchOptions({
path: entryPagePath, path: entryPagePath,
...@@ -19958,6 +20023,16 @@ var serviceContext = (function (vue) { ...@@ -19958,6 +20023,16 @@ var serviceContext = (function (vue) {
getPushCid: getPushCid, getPushCid: getPushCid,
onPushMessage: onPushMessage, onPushMessage: onPushMessage,
offPushMessage: offPushMessage, offPushMessage: offPushMessage,
onAppHide: onAppHide,
onAppShow: onAppShow,
onError: onError,
onPageNotFound: onPageNotFound,
onUnhandledRejection: onUnhandledRejection,
offAppHide: offAppHide,
offAppShow: offAppShow,
offError: offError,
offPageNotFound: offPageNotFound,
offUnhandledRejection: offUnhandledRejection,
invokePushCallback: invokePushCallback, invokePushCallback: invokePushCallback,
setStorageSync: setStorageSync, setStorageSync: setStorageSync,
setStorage: setStorage, setStorage: setStorage,
......
...@@ -118,6 +118,16 @@ export { ...@@ -118,6 +118,16 @@ export {
getPushCid, getPushCid,
onPushMessage, onPushMessage,
offPushMessage, offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
// 内部使用 // 内部使用
invokePushCallback, invokePushCallback,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
import { invokeHook } from '@dcloudio/uni-core' import { invokeHook } from '@dcloudio/uni-core'
import { injectAppHooks } from '@dcloudio/uni-api'
import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared' import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
import { initLaunchOptions } from './utils' import { initLaunchOptions } from './utils'
export function initAppLaunch(appVm: ComponentPublicInstance) { export function initAppLaunch(appVm: ComponentPublicInstance) {
injectAppHooks(appVm.$)
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig
const args = initLaunchOptions({ const args = initLaunchOptions({
path: entryPagePath, path: entryPagePath,
......
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
import { isString } from '@vue/shared' import { isString, isArray, remove } from '@vue/shared'
import { invokeArrayFns } from '@dcloudio/uni-shared' import { invokeArrayFns } from '@dcloudio/uni-shared'
import { getCurrentPageVm } from './page' import { getCurrentPageVm } from './page'
export function removeHook(
vm: ComponentPublicInstance,
name: string,
hook: Function
) {
const hooks = (vm.$ as unknown as { [name: string]: Function[] })[
name as string
]
if (!isArray(hooks)) {
return
}
remove(hooks, hook)
}
export function invokeHook(name: string, args?: unknown): unknown export function invokeHook(name: string, args?: unknown): unknown
export function invokeHook(id: number, name: string, args?: unknown): unknown export function invokeHook(id: number, name: string, args?: unknown): unknown
export function invokeHook( export function invokeHook(
......
...@@ -75,22 +75,32 @@ ...@@ -75,22 +75,32 @@
"navigateBack", "navigateBack",
"navigateTo", "navigateTo",
"offAccelerometerChange", "offAccelerometerChange",
"offAppHide",
"offAppShow",
"offCompassChange", "offCompassChange",
"offError",
"offNetworkStatusChange", "offNetworkStatusChange",
"offPageNotFound",
"offPushMessage", "offPushMessage",
"offUnhandledRejection",
"offWindowResize", "offWindowResize",
"onAccelerometerChange", "onAccelerometerChange",
"onAppHide",
"onAppShow",
"onCompassChange", "onCompassChange",
"onError",
"onGyroscopeChange", "onGyroscopeChange",
"onLocaleChange", "onLocaleChange",
"onMemoryWarning", "onMemoryWarning",
"onNetworkStatusChange", "onNetworkStatusChange",
"onPageNotFound",
"onPushMessage", "onPushMessage",
"onSocketClose", "onSocketClose",
"onSocketError", "onSocketError",
"onSocketMessage", "onSocketMessage",
"onSocketOpen", "onSocketOpen",
"onTabBarMidButtonTap", "onTabBarMidButtonTap",
"onUnhandledRejection",
"onUserCaptureScreen", "onUserCaptureScreen",
"onWindowResize", "onWindowResize",
"openDocument", "openDocument",
......
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, injectHook, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue"; import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared"; import { isString, extend, isArray, remove, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared"; import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
export { onCreateVueApp } from "@dcloudio/uni-shared"; export { onCreateVueApp } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n"; import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router"; import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
...@@ -887,6 +887,13 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel) ...@@ -887,6 +887,13 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel)
statusBarStyle: meta.navigationBar.titleColor === "#000000" ? "dark" : "light" statusBarStyle: meta.navigationBar.titleColor === "#000000" ? "dark" : "light"
}; };
} }
function removeHook(vm, name, hook) {
const hooks = vm.$[name];
if (!isArray(hooks)) {
return;
}
remove(hooks, hook);
}
function invokeHook(vm, name, args) { function invokeHook(vm, name, args) {
if (isString(vm)) { if (isString(vm)) {
args = name; args = name;
...@@ -2843,9 +2850,11 @@ function removeInterceptorHook(interceptors2, interceptor) { ...@@ -2843,9 +2850,11 @@ function removeInterceptorHook(interceptors2, interceptor) {
if (!interceptors2 || !interceptor) { if (!interceptors2 || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors2[name];
removeHook(interceptors2[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -2862,15 +2871,6 @@ function dedupeHooks(hooks) { ...@@ -2862,15 +2871,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index2 = hooks.indexOf(hook);
if (index2 !== -1) {
hooks.splice(index2, 1);
}
}
const addInterceptor = /* @__PURE__ */ defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = /* @__PURE__ */ defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === "string" && isPlainObject(interceptor)) { if (typeof method === "string" && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
...@@ -4473,6 +4473,64 @@ const getSelectedTextRange$1 = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_T ...@@ -4473,6 +4473,64 @@ const getSelectedTextRange$1 = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_T
} }
}); });
}); });
const appHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [],
[ON_HIDE]: []
};
function onAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return injectHook(type, hook, app.$vm.$);
}
appHooks[type].push(hook);
}
function injectAppHooks(appInstance) {
Object.keys(appHooks).forEach((type) => {
appHooks[type].forEach((hook) => {
injectHook(type, hook, appInstance);
});
});
}
function offAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return removeHook(app.$vm, type, hook);
}
remove(appHooks[type], hook);
}
function onUnhandledRejection(hook) {
onAppHook(ON_UNHANDLE_REJECTION, hook);
}
function offUnhandledRejection(hook) {
offAppHook(ON_UNHANDLE_REJECTION, hook);
}
function onPageNotFound(hook) {
onAppHook(ON_PAGE_NOT_FOUND, hook);
}
function offPageNotFound(hook) {
offAppHook(ON_PAGE_NOT_FOUND, hook);
}
function onError(hook) {
onAppHook(ON_ERROR, hook);
}
function offError(hook) {
offAppHook(ON_ERROR, hook);
}
function onAppShow(hook) {
onAppHook(ON_SHOW, hook);
}
function offAppShow(hook) {
offAppHook(ON_SHOW, hook);
}
function onAppHide(hook) {
onAppHook(ON_HIDE, hook);
}
function offAppHide(hook) {
offAppHook(ON_HIDE, hook);
}
const API_GET_ENTER_OPTIONS_SYNC = "getEnterOptionsSync"; const API_GET_ENTER_OPTIONS_SYNC = "getEnterOptionsSync";
const getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { const getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions(); return getEnterOptions();
...@@ -14130,7 +14188,8 @@ function setupApp(comp) { ...@@ -14130,7 +14188,8 @@ function setupApp(comp) {
setup(instance2) { setup(instance2) {
const route = usePageRoute(); const route = usePageRoute();
const onLaunch = () => { const onLaunch = () => {
const { onLaunch: onLaunch2, onShow, onPageNotFound } = instance2; injectAppHooks(instance2);
const { onLaunch: onLaunch2, onShow, onPageNotFound: onPageNotFound2 } = instance2;
const path = route.path.slice(1); const path = route.path.slice(1);
const launchOptions2 = initLaunchOptions({ const launchOptions2 = initLaunchOptions({
path: path || __uniRoutes[0].meta.route, path: path || __uniRoutes[0].meta.route,
...@@ -14147,7 +14206,7 @@ function setupApp(comp) { ...@@ -14147,7 +14206,7 @@ function setupApp(comp) {
query: {}, query: {},
scene: 1001 scene: 1001
}; };
onPageNotFound && invokeArrayFns$1(onPageNotFound, pageNotFoundOptions); onPageNotFound2 && invokeArrayFns$1(onPageNotFound2, pageNotFoundOptions);
} }
} }
}; };
...@@ -19842,6 +19901,16 @@ var api = { ...@@ -19842,6 +19901,16 @@ var api = {
getPushCid, getPushCid,
onPushMessage, onPushMessage,
offPushMessage, offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
invokePushCallback, invokePushCallback,
cssVar, cssVar,
cssEnv, cssEnv,
...@@ -22004,4 +22073,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ ...@@ -22004,4 +22073,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]); return openBlock(), createBlock("div", clazz, [loadingVNode]);
} }
}); });
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushCid, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offPushMessage, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort }; export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushCid, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offAppHide, offAppShow, offCompassChange, offError, offNetworkStatusChange, offPageNotFound, offPushMessage, offUnhandledRejection, offWindowResize, onAccelerometerChange, onAppHide, onAppShow, onCompassChange, onError, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPageNotFound, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUnhandledRejection, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
...@@ -22,6 +22,7 @@ import { ...@@ -22,6 +22,7 @@ import {
ON_WEB_INVOKE_APP_SERVICE, ON_WEB_INVOKE_APP_SERVICE,
WEB_INVOKE_APPSERVICE, WEB_INVOKE_APPSERVICE,
} from '@dcloudio/uni-shared' } from '@dcloudio/uni-shared'
import { injectAppHooks } from '@dcloudio/uni-api'
import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core' import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core'
import { LayoutComponent } from '../..' import { LayoutComponent } from '../..'
import { initApp } from './app' import { initApp } from './app'
...@@ -139,6 +140,7 @@ export function setupApp(comp: any) { ...@@ -139,6 +140,7 @@ export function setupApp(comp: any) {
return route.query return route.query
} }
const onLaunch = () => { const onLaunch = () => {
injectAppHooks(instance)
const { onLaunch, onShow, onPageNotFound } = instance const { onLaunch, onShow, onPageNotFound } = instance
const path = route.path.slice(1) const path = route.path.slice(1)
const launchOptions = initLaunchOptions({ const launchOptions = initLaunchOptions({
......
...@@ -100,6 +100,16 @@ export { ...@@ -100,6 +100,16 @@ export {
getPushCid, getPushCid,
onPushMessage, onPushMessage,
offPushMessage, offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
// 内部使用 // 内部使用
invokePushCallback, invokePushCallback,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -463,9 +463,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -463,9 +463,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -488,15 +490,6 @@ function dedupeHooks(hooks) { ...@@ -488,15 +490,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; return res;
} }
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册