diff --git a/packages/uni-api/src/service/base/interceptor.ts b/packages/uni-api/src/service/base/interceptor.ts index 6c3e7f40e257b74a3001f278f06bbdc7c87cfd60..02bfd3511c8cd52ffbf305a9d301bb851d466b3c 100644 --- a/packages/uni-api/src/service/base/interceptor.ts +++ b/packages/uni-api/src/service/base/interceptor.ts @@ -1,4 +1,4 @@ -import { isArray, isFunction, isPlainObject } from '@vue/shared' +import { isArray, isFunction, isPlainObject, remove } from '@vue/shared' import { HOOKS, @@ -38,12 +38,11 @@ function removeInterceptorHook( if (!interceptors || !interceptor) { return } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook as HOOKS])) { - removeHook( - interceptors[hook as HOOKS], - interceptor[hook as HOOKS] as Function - ) + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name as HOOKS] + const hook = interceptor[name as HOOKS] + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook) } }) } @@ -72,16 +71,6 @@ function dedupeHooks(hooks: Function[]) { 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( API_ADD_INTERCEPTOR, (method: string | Interceptor, interceptor: Interceptor | undefined) => { diff --git a/packages/uni-api/src/service/lifecycle/app.ts b/packages/uni-api/src/service/lifecycle/app.ts index e5c664e8931654ef04863817b4f5d2057fa4530a..20939584e7fe1a261eeffc470b439f7e93b0d359 100644 --- a/packages/uni-api/src/service/lifecycle/app.ts +++ b/packages/uni-api/src/service/lifecycle/app.ts @@ -1,17 +1,31 @@ import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform' -import { ON_HIDE, ON_SHOW } from '@dcloudio/uni-shared' -import { defineSyncApi } from '../../helpers/api' - +import { + ON_ERROR, + ON_HIDE, + ON_PAGE_NOT_FOUND, + ON_SHOW, + ON_UNHANDLE_REJECTION, +} from '@dcloudio/uni-shared' 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 AppHideHook = () => void interface AppHooks { + onUnhandledRejection: UniApp.OnUnhandledRejectionCallback[] + onPageNotFound: UniApp.OnPageNotFoundCallback[] + onError: UniApp.OnAppErrorCallback[] onShow: AppShowHook[] onHide: AppHideHook[] } const appHooks: AppHooks = { + [ON_UNHANDLE_REJECTION]: [], + [ON_PAGE_NOT_FOUND]: [], + [ON_ERROR]: [], [ON_SHOW]: [], [ON_HIDE]: [], } @@ -24,21 +38,64 @@ function onAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) { 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) { onAppHook(ON_SHOW, hook) } +export function offAppShow(hook: AppShowHook) { + offAppHook(ON_SHOW, hook) +} + export function onAppHide(hook: AppHideHook) { onAppHook(ON_HIDE, hook) } -export function injectAppHooks( - type: keyof AppHooks, - appInstance: ComponentInternalInstance -) { - appHooks[type].forEach((hook) => { - injectHook(type, hook, appInstance) - }) +export function offAppHide(hook: AppHideHook) { + offAppHook(ON_HIDE, hook) } type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index 381d4b1c8160446798560040a51de54d0332002f..96ddd8a68494ff6728ccedc426c87adda3b43681 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -106,6 +106,12 @@ var serviceContext = (function (vue) { : {}; (process.env.NODE_ENV !== 'production') ? Object.freeze([]) : []; 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 hasOwn$1 = (val, key) => hasOwnProperty$1.call(val, key); const isArray$1 = Array.isArray; @@ -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) { if (isString(vm)) { args = name; @@ -9863,9 +9876,11 @@ var serviceContext = (function (vue) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray$1(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -9888,15 +9903,6 @@ var serviceContext = (function (vue) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); @@ -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 getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { return getEnterOptions(); @@ -17527,6 +17591,7 @@ var serviceContext = (function (vue) { // } function initAppLaunch(appVm) { + injectAppHooks(appVm.$); const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig; const args = initLaunchOptions({ path: entryPagePath, @@ -19958,6 +20023,16 @@ var serviceContext = (function (vue) { getPushCid: getPushCid, onPushMessage: onPushMessage, offPushMessage: offPushMessage, + onAppHide: onAppHide, + onAppShow: onAppShow, + onError: onError, + onPageNotFound: onPageNotFound, + onUnhandledRejection: onUnhandledRejection, + offAppHide: offAppHide, + offAppShow: offAppShow, + offError: offError, + offPageNotFound: offPageNotFound, + offUnhandledRejection: offUnhandledRejection, invokePushCallback: invokePushCallback, setStorageSync: setStorageSync, setStorage: setStorage, diff --git a/packages/uni-app-plus/src/service/api/index.ts b/packages/uni-app-plus/src/service/api/index.ts index 357df0f9bba2f072c07dbe204776174e8bf29768..282d4e30c6bea799508297aa15d60d281450a3ff 100644 --- a/packages/uni-app-plus/src/service/api/index.ts +++ b/packages/uni-app-plus/src/service/api/index.ts @@ -118,6 +118,16 @@ export { getPushCid, onPushMessage, offPushMessage, + onAppHide, + onAppShow, + onError, + onPageNotFound, + onUnhandledRejection, + offAppHide, + offAppShow, + offError, + offPageNotFound, + offUnhandledRejection, // 内部使用 invokePushCallback, } from '@dcloudio/uni-api' diff --git a/packages/uni-app-plus/src/service/framework/app/initAppLaunch.ts b/packages/uni-app-plus/src/service/framework/app/initAppLaunch.ts index dd7c50011aec051cfbe5d3c7abebcf7225cab830..e7654940819c605b4974357c0a82a1684823c177 100644 --- a/packages/uni-app-plus/src/service/framework/app/initAppLaunch.ts +++ b/packages/uni-app-plus/src/service/framework/app/initAppLaunch.ts @@ -1,9 +1,11 @@ import { invokeHook } from '@dcloudio/uni-core' +import { injectAppHooks } from '@dcloudio/uni-api' import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared' import { ComponentPublicInstance } from 'vue' import { initLaunchOptions } from './utils' export function initAppLaunch(appVm: ComponentPublicInstance) { + injectAppHooks(appVm.$) const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig const args = initLaunchOptions({ path: entryPagePath, diff --git a/packages/uni-core/src/helpers/hook.ts b/packages/uni-core/src/helpers/hook.ts index c067eb6aa9af3868c9d8ead7406a17ee7ef8a3fa..516c114207ce02e2c5f44c695a96d49a3eb3f883 100644 --- a/packages/uni-core/src/helpers/hook.ts +++ b/packages/uni-core/src/helpers/hook.ts @@ -1,8 +1,22 @@ import { ComponentPublicInstance } from 'vue' -import { isString } from '@vue/shared' +import { isString, isArray, remove } from '@vue/shared' import { invokeArrayFns } from '@dcloudio/uni-shared' 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(id: number, name: string, args?: unknown): unknown export function invokeHook( diff --git a/packages/uni-h5-vite/lib/api.json b/packages/uni-h5-vite/lib/api.json index c83e4061adc65bf0453d6a339585b1df274829c4..144328b553a64b6aea931d238985d54d6eb426ff 100644 --- a/packages/uni-h5-vite/lib/api.json +++ b/packages/uni-h5-vite/lib/api.json @@ -75,22 +75,32 @@ "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", diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index 6ba849cc266bd99a743c7441a92d83081001f546..bebe10974bec33175743a0f56fb3536b82e900b4 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -1,6 +1,6 @@ -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 { 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 { 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 { 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, 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, 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"; 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"; @@ -887,6 +887,13 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel) 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) { if (isString(vm)) { args = name; @@ -2843,9 +2850,11 @@ function removeInterceptorHook(interceptors2, interceptor) { if (!interceptors2 || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors2[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors2[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -2862,15 +2871,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === "string" && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); @@ -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 getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { return getEnterOptions(); @@ -14130,7 +14188,8 @@ function setupApp(comp) { setup(instance2) { const route = usePageRoute(); const onLaunch = () => { - const { onLaunch: onLaunch2, onShow, onPageNotFound } = instance2; + injectAppHooks(instance2); + const { onLaunch: onLaunch2, onShow, onPageNotFound: onPageNotFound2 } = instance2; const path = route.path.slice(1); const launchOptions2 = initLaunchOptions({ path: path || __uniRoutes[0].meta.route, @@ -14147,7 +14206,7 @@ function setupApp(comp) { query: {}, scene: 1001 }; - onPageNotFound && invokeArrayFns$1(onPageNotFound, pageNotFoundOptions); + onPageNotFound2 && invokeArrayFns$1(onPageNotFound2, pageNotFoundOptions); } } }; @@ -19842,6 +19901,16 @@ var api = { getPushCid, onPushMessage, offPushMessage, + onAppHide, + onAppShow, + onError, + onPageNotFound, + onUnhandledRejection, + offAppHide, + offAppShow, + offError, + offPageNotFound, + offUnhandledRejection, invokePushCallback, cssVar, cssEnv, @@ -22004,4 +22073,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ 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 }; diff --git a/packages/uni-h5/src/framework/setup/index.ts b/packages/uni-h5/src/framework/setup/index.ts index 0079b51377b1c26d69df86971d3088034da48960..8d5366b923d9f27651955d8b9e41eb58c8418e35 100644 --- a/packages/uni-h5/src/framework/setup/index.ts +++ b/packages/uni-h5/src/framework/setup/index.ts @@ -22,6 +22,7 @@ import { ON_WEB_INVOKE_APP_SERVICE, WEB_INVOKE_APPSERVICE, } from '@dcloudio/uni-shared' +import { injectAppHooks } from '@dcloudio/uni-api' import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core' import { LayoutComponent } from '../..' import { initApp } from './app' @@ -139,6 +140,7 @@ export function setupApp(comp: any) { return route.query } const onLaunch = () => { + injectAppHooks(instance) const { onLaunch, onShow, onPageNotFound } = instance const path = route.path.slice(1) const launchOptions = initLaunchOptions({ diff --git a/packages/uni-h5/src/service/api/index.ts b/packages/uni-h5/src/service/api/index.ts index a37a5d80160b3f60b0fbce1d775179b28811a0a0..c0722e61ce4f38a7ed7f33c51a487b13635e1ef8 100644 --- a/packages/uni-h5/src/service/api/index.ts +++ b/packages/uni-h5/src/service/api/index.ts @@ -100,6 +100,16 @@ export { getPushCid, onPushMessage, offPushMessage, + onAppHide, + onAppShow, + onError, + onPageNotFound, + onUnhandledRejection, + offAppHide, + offAppShow, + offError, + offPageNotFound, + offUnhandledRejection, // 内部使用 invokePushCallback, } from '@dcloudio/uni-api' diff --git a/packages/uni-mp-alipay/dist/uni.api.esm.js b/packages/uni-mp-alipay/dist/uni.api.esm.js index b5619b63e7a6ad3fe4edb923688cedb7e749045d..02a6f1cdbbdf8fc47298a3579e55ab75232f4e36 100644 --- a/packages/uni-mp-alipay/dist/uni.api.esm.js +++ b/packages/uni-mp-alipay/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-mp-baidu/dist/uni.api.esm.js b/packages/uni-mp-baidu/dist/uni.api.esm.js index b9841620b283c52fa5bd83b2b1fd56e3f9286556..6e65dd43d9ba510e6e55c41acddeea6b211b8d2a 100644 --- a/packages/uni-mp-baidu/dist/uni.api.esm.js +++ b/packages/uni-mp-baidu/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-mp-kuaishou/dist/uni.api.esm.js b/packages/uni-mp-kuaishou/dist/uni.api.esm.js index aebe12758e7fa149b3e35679ae1cf409fe9a96e5..3cd1910f8d181c583c83ad92f030f498225d49da 100644 --- a/packages/uni-mp-kuaishou/dist/uni.api.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-mp-lark/dist/uni.api.esm.js b/packages/uni-mp-lark/dist/uni.api.esm.js index 3fac7651c44a2da55e540fe49b40819f6872a6c7..cce70c47cb36f621672f9a297eb6b0500c4c58a9 100644 --- a/packages/uni-mp-lark/dist/uni.api.esm.js +++ b/packages/uni-mp-lark/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-mp-qq/dist/uni.api.esm.js b/packages/uni-mp-qq/dist/uni.api.esm.js index dc26037b0ada4d87b864e43a00efbeec018230f5..4b7efbb2829521d84063cd487bcc0cb952b99aa9 100644 --- a/packages/uni-mp-qq/dist/uni.api.esm.js +++ b/packages/uni-mp-qq/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-mp-toutiao/dist/uni.api.esm.js b/packages/uni-mp-toutiao/dist/uni.api.esm.js index 09d30b7d5da60c84440c905c87724aa5fd83d980..b2a373e2758e27505d0c701a2b389f327c9ee623 100644 --- a/packages/uni-mp-toutiao/dist/uni.api.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-mp-weixin/dist/uni.api.esm.js b/packages/uni-mp-weixin/dist/uni.api.esm.js index d0c95dd32f6a290afe9047a9b7f839905a0cb3c1..b97ef8afab7f6b9efa8cd6a0069259674aefdc26 100644 --- a/packages/uni-mp-weixin/dist/uni.api.esm.js +++ b/packages/uni-mp-weixin/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -463,9 +463,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -488,15 +490,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); diff --git a/packages/uni-quickapp-webview/dist/uni.api.esm.js b/packages/uni-quickapp-webview/dist/uni.api.esm.js index b8e03aaf738368ba84db00f2faf24cefc65cbf0a..175d5bc04282a19e1cc5f30eff9e37f3eed9d615 100644 --- a/packages/uni-quickapp-webview/dist/uni.api.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.api.esm.js @@ -1,4 +1,4 @@ -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; const createVueAppHooks = []; @@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { if (!interceptors || !interceptor) { return; } - Object.keys(interceptor).forEach((hook) => { - if (isFunction(interceptor[hook])) { - removeHook(interceptors[hook], interceptor[hook]); + Object.keys(interceptor).forEach((name) => { + const hooks = interceptors[name]; + const hook = interceptor[name]; + if (isArray(hooks) && isFunction(hook)) { + remove(hooks, hook); } }); } @@ -524,15 +526,6 @@ function dedupeHooks(hooks) { } 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) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);