From 415b832d37da68aced1bfbe76e51b900b2a10ea3 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 16 Sep 2020 16:25:26 +0800 Subject: [PATCH] refactor: createApi --- packages/uni-api/src/helpers/api.ts | 45 +++- packages/uni-api/src/index.ts | 9 +- packages/uni-api/src/service/base/base64.ts | 4 +- .../uni-api/src/service/base/interceptor.ts | 4 +- packages/uni-api/src/service/base/upx2px.ts | 3 +- .../service/ui/createIntersectionObserver.ts | 4 +- .../src/service/ui/createSelectorQuery.ts | 1 + packages/uni-h5/dist/uni-h5.esm.js | 75 +++--- .../uni-h5/src/service/api/base/canIUse.ts | 18 +- .../src/service/api/device/getSystemInfo.ts | 11 +- .../service/api/device/getSystemInfoSync.ts | 223 +++++++++--------- .../src/service/api/device/makePhoneCall.ts | 16 +- .../src/service/api/file/openDocument.ts | 16 +- packages/uni-h5/src/service/api/index.ts | 3 +- .../src/service/api/media/getImageInfo.ts | 18 +- .../src/service/api/route/navigateBack.ts | 7 +- .../src/service/api/route/navigateTo.ts | 13 +- .../uni-h5/src/service/api/route/reLaunch.ts | 4 +- .../src/service/api/route/redirectTo.ts | 4 +- .../uni-h5/src/service/api/route/switchTab.ts | 4 +- .../src/service/api/util/getRealPath.ts | 11 +- packages/uni-mp-alipay/dist/uni.api.esm.js | 27 ++- packages/uni-mp-baidu/dist/uni.api.esm.js | 27 ++- packages/uni-mp-qq/dist/uni.api.esm.js | 27 ++- packages/uni-mp-toutiao/dist/uni.api.esm.js | 27 ++- packages/uni-mp-weixin/dist/uni.api.esm.js | 27 ++- .../uni-quickapp-webview/dist/uni.api.esm.js | 27 ++- 27 files changed, 418 insertions(+), 237 deletions(-) create mode 100644 packages/uni-api/src/service/ui/createSelectorQuery.ts diff --git a/packages/uni-api/src/helpers/api.ts b/packages/uni-api/src/helpers/api.ts index 25a56201f..507e4e0a8 100644 --- a/packages/uni-api/src/helpers/api.ts +++ b/packages/uni-api/src/helpers/api.ts @@ -1,14 +1,45 @@ import { ApiOptions, ApiProtocol, ProtocolOptions } from '../protocols/type' +type ApiProtocols = ApiProtocol | ProtocolOptions[] + +interface CreateApiOptions { + type: API_TYPES + name?: string + options?: ApiOptions +} + +export const API_TYPE_ON = 0 +export const API_TYPE_SYNC = 1 +export const API_TYPE_ASYNC = 2 +export const API_TYPE_RETURN = 3 + +type API_TYPES = + | typeof API_TYPE_ON + | typeof API_TYPE_SYNC + | typeof API_TYPE_ASYNC + | typeof API_TYPE_RETURN + +function validateProtocol(name: string, args: any[], protocol: ApiProtocols) { + console.log(name, args, protocol) + return true +} + +function formatApiArgs(args: any[], options?: ApiOptions) { + if (!options) { + return args + } +} + export function createApi( + { type, name, options }: CreateApiOptions, fn: T, - protocol?: ApiProtocol | ProtocolOptions[], - options?: ApiOptions + protocol?: ApiProtocols ) { - if (__DEV__ && protocol) { - } - if (options) { - console.log(options) + return function(...args: any[]) { + if (type === API_TYPE_SYNC) { + if (!(__DEV__ && protocol && !validateProtocol(name!, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)) + } + } } - return fn } diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 2781d876d..c091abd93 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -3,6 +3,7 @@ export * from './service/base/upx2px' export * from './service/base/interceptor' export * from './service/ui/createIntersectionObserver' +export * from './service/ui/createSelectorQuery' // protocols export * from './protocols/base/canIUse' @@ -21,5 +22,11 @@ export * from './protocols/media/chooseVideo' export * from './protocols/media/getImageInfo' // helpers -export { createApi } from './helpers/api' +export { + createApi, + API_TYPE_ON, + API_TYPE_SYNC, + API_TYPE_ASYNC, + API_TYPE_RETURN +} from './helpers/api' export { isSyncApi, isContextApi, promisify } from './helpers/promise' diff --git a/packages/uni-api/src/service/base/base64.ts b/packages/uni-api/src/service/base/base64.ts index 90f2924f1..7671253eb 100644 --- a/packages/uni-api/src/service/base/base64.ts +++ b/packages/uni-api/src/service/base/base64.ts @@ -1,7 +1,7 @@ // @ts-ignore import { encode, decode } from '../../helpers/base64-arraybuffer' -import { createApi } from '../../helpers/api' +import { API_TYPE_SYNC, createApi } from '../../helpers/api' import { Base64ToArrayBufferProtocol, @@ -9,6 +9,7 @@ import { } from '../../protocols/base/base64' export const base64ToArrayBuffer = createApi( + { type: API_TYPE_SYNC, name: 'base64ToArrayBuffer' }, base64 => { return decode(base64) as ArrayBuffer }, @@ -16,6 +17,7 @@ export const base64ToArrayBuffer = createApi( ) export const arrayBufferToBase64 = createApi( + { type: API_TYPE_SYNC, name: 'arrayBufferToBase64' }, arrayBuffer => { return encode(arrayBuffer) as string }, diff --git a/packages/uni-api/src/service/base/interceptor.ts b/packages/uni-api/src/service/base/interceptor.ts index ab6964893..2f23d39e7 100644 --- a/packages/uni-api/src/service/base/interceptor.ts +++ b/packages/uni-api/src/service/base/interceptor.ts @@ -8,7 +8,7 @@ import { HOOKS } from '../../helpers/interceptor' -import { createApi } from '../../helpers/api' +import { API_TYPE_SYNC, createApi } from '../../helpers/api' import { AddInterceptorProtocol, @@ -80,6 +80,7 @@ function removeHook(hooks: Function[] | undefined, hook: Function) { } export const addInterceptor = createApi( + { type: API_TYPE_SYNC, name: 'addInterceptor' }, (method: string | Interceptor, interceptor: Interceptor | undefined) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook( @@ -94,6 +95,7 @@ export const addInterceptor = createApi( ) export const removeInterceptor = createApi( + { type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method: string | Interceptor, interceptor: Interceptor | undefined) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { diff --git a/packages/uni-api/src/service/base/upx2px.ts b/packages/uni-api/src/service/base/upx2px.ts index 878295870..c353aeb73 100644 --- a/packages/uni-api/src/service/base/upx2px.ts +++ b/packages/uni-api/src/service/base/upx2px.ts @@ -1,4 +1,4 @@ -import { createApi } from '../../helpers/api' +import { API_TYPE_SYNC, createApi } from '../../helpers/api' import { Upx2pxProtocol } from '../../protocols/base/upx2px' const EPS = 1e-4 @@ -15,6 +15,7 @@ function checkDeviceWidth() { } export const upx2px = createApi( + { type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth?: number) => { if (deviceWidth === 0) { checkDeviceWidth() diff --git a/packages/uni-api/src/service/ui/createIntersectionObserver.ts b/packages/uni-api/src/service/ui/createIntersectionObserver.ts index 6c3c8adcb..3ebfc6ef4 100644 --- a/packages/uni-api/src/service/ui/createIntersectionObserver.ts +++ b/packages/uni-api/src/service/ui/createIntersectionObserver.ts @@ -2,7 +2,7 @@ import { extend } from '@vue/shared' import { ServiceJSBridge } from '@dcloudio/uni-core' -import { createApi } from '../../helpers/api' +import { API_TYPE_RETURN, createApi } from '../../helpers/api' import { getCurrentPageVm } from '../utils' const defaultOptions = { @@ -122,7 +122,7 @@ class ServiceIntersectionObserver { export const createIntersectionObserver = createApi< typeof uni.createIntersectionObserver ->((context?, options?) => { +>({ type: API_TYPE_RETURN }, (context?, options?) => { if (!context) { context = getCurrentPageVm() } diff --git a/packages/uni-api/src/service/ui/createSelectorQuery.ts b/packages/uni-api/src/service/ui/createSelectorQuery.ts new file mode 100644 index 000000000..cf7a959de --- /dev/null +++ b/packages/uni-api/src/service/ui/createSelectorQuery.ts @@ -0,0 +1 @@ +export const createSelectorQuery = () => {} diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 0cd0f656a..f50c16394 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -1248,12 +1248,26 @@ var decode = function(base64) { } return arraybuffer; }; -function createApi(fn, protocol, options) { - if (process.env.NODE_ENV !== "production" && protocol) - ; - if (options) { +const API_TYPE_SYNC = 1; +const API_TYPE_ASYNC = 2; +const API_TYPE_RETURN = 3; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; } - return fn; +} +function createApi({type: type2, name, options}, fn, protocol) { + return function(...args) { + if (type2 === API_TYPE_SYNC) { + if (!(process.env.NODE_ENV !== "production" && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Base64ToArrayBufferProtocol = [ { @@ -1269,10 +1283,10 @@ const ArrayBufferToBase64Protocol = [ required: true } ]; -const base64ToArrayBuffer = /* @__PURE__ */ createApi((base642) => { +const base64ToArrayBuffer = /* @__PURE__ */ createApi({type: API_TYPE_SYNC, name: "base64ToArrayBuffer"}, (base642) => { return decode(base642); }, Base64ToArrayBufferProtocol); -const arrayBufferToBase64 = /* @__PURE__ */ createApi((arrayBuffer) => { +const arrayBufferToBase64 = /* @__PURE__ */ createApi({type: API_TYPE_SYNC, name: "arrayBufferToBase64"}, (arrayBuffer) => { return encode(arrayBuffer); }, ArrayBufferToBase64Protocol); const Upx2pxProtocol = [ @@ -1293,7 +1307,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === "ios"; } -const upx2px = /* @__PURE__ */ createApi((number, newDeviceWidth) => { +const upx2px = /* @__PURE__ */ createApi({type: API_TYPE_SYNC, name: "upx2px"}, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -1372,14 +1386,14 @@ function removeHook(hooks, hook) { hooks.splice(index2, 1); } } -const addInterceptor = /* @__PURE__ */ createApi((method, interceptor3) => { +const addInterceptor = /* @__PURE__ */ createApi({type: API_TYPE_SYNC, name: "addInterceptor"}, (method, interceptor3) => { if (typeof method === "string" && isPlainObject(interceptor3)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor3); } else if (isPlainObject(method)) { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = /* @__PURE__ */ createApi((method, interceptor3) => { +const removeInterceptor = /* @__PURE__ */ createApi({type: API_TYPE_SYNC, name: "removeInterceptor"}, (method, interceptor3) => { if (typeof method === "string") { if (isPlainObject(interceptor3)) { removeInterceptorHook(scopedInterceptors[method], interceptor3); @@ -1467,12 +1481,14 @@ class ServiceIntersectionObserver { }, this._pageId); } } -const createIntersectionObserver$1 = /* @__PURE__ */ createApi((context, options) => { +const createIntersectionObserver$1 = /* @__PURE__ */ createApi({type: API_TYPE_RETURN}, (context, options) => { if (!context) { context = getCurrentPageVm(); } return new ServiceIntersectionObserver(context, options); }); +const createSelectorQuery$1 = () => { +}; const CanIUseProtocol = [ { name: "schema", @@ -1521,19 +1537,19 @@ const SCHEMA_CSS = { "css.env": cssSupports("top:env(a)"), "css.constant": cssSupports("top:constant(a)") }; -const canIUse = /* @__PURE__ */ createApi((schema) => { +const canIUse = /* @__PURE__ */ createApi({type: API_TYPE_SYNC, name: "canIUse"}, (schema) => { if (hasOwn(SCHEMA_CSS, schema)) { return SCHEMA_CSS[schema]; } return true; }, CanIUseProtocol); -const makePhoneCall = /* @__PURE__ */ createApi((option) => { +const makePhoneCall = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC, name: "makePhoneCall"}, (option) => { window.location.href = `tel:${option.phoneNumber}`; }, MakePhoneCallProtocol); const ua = navigator.userAgent; const isAndroid = /android/i.test(ua); const isIOS$1 = /iphone|ipad|ipod/i.test(ua); -const getSystemInfoSync = /* @__PURE__ */ createApi(() => { +const getSystemInfoSync = /* @__PURE__ */ createApi({type: API_TYPE_SYNC}, () => { var screen = window.screen; var pixelRatio = window.devicePixelRatio; const screenFix = /^Apple/.test(navigator.vendor) && typeof window.orientation === "number"; @@ -1634,47 +1650,45 @@ const getSystemInfoSync = /* @__PURE__ */ createApi(() => { } }; }); -const getSystemInfo = /* @__PURE__ */ createApi(() => { +const getSystemInfo = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC, name: "getSystemInfo"}, () => { return getSystemInfoSync(); }); -const openDocument = /* @__PURE__ */ createApi((option) => { +const openDocument = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC, name: "openDocument"}, (option) => { window.open(option.filePath); }, OpenDocumentProtocol); function _getServiceAddress() { return window.location.protocol + "//" + window.location.host; } -const getImageInfo = /* @__PURE__ */ createApi(({src}, callbackId) => { - const {invokeCallbackHandler: invoke} = UniServiceJSBridge; +const getImageInfo = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC, name: "getImageInfo", options: GetImageInfoOptions}, ({src}, callback) => { const img = new Image(); - const realPath = src; img.onload = function() { - invoke(callbackId, { + callback({ errMsg: "getImageInfo:ok", width: img.naturalWidth, height: img.naturalHeight, - path: realPath.indexOf("/") === 0 ? _getServiceAddress() + realPath : realPath + path: src.indexOf("/") === 0 ? _getServiceAddress() + src : src }); }; img.onerror = function() { - invoke(callbackId, { + callback({ errMsg: "getImageInfo:fail" }); }; img.src = src; -}, GetImageInfoProtocol, GetImageInfoOptions); -const navigateBack = /* @__PURE__ */ createApi(() => { +}, GetImageInfoProtocol); +const navigateBack = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC}, () => { }); -const navigateTo = /* @__PURE__ */ createApi((options) => { +const navigateTo = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC}, (options) => { const router = getApp().$router; router.push(options.url); }); -const redirectTo = /* @__PURE__ */ createApi(() => { +const redirectTo = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC}, () => { }); -const reLaunch = /* @__PURE__ */ createApi(() => { +const reLaunch = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC}, () => { }); -const switchTab = /* @__PURE__ */ createApi(() => { +const switchTab = /* @__PURE__ */ createApi({type: API_TYPE_ASYNC}, () => { }); -const getRealPath = /* @__PURE__ */ createApi((path) => { +const getRealPath = /* @__PURE__ */ createApi({type: API_TYPE_SYNC}, (path) => { return path; }); var api = /* @__PURE__ */ Object.freeze({ @@ -1686,6 +1700,7 @@ var api = /* @__PURE__ */ Object.freeze({ arrayBufferToBase64, base64ToArrayBuffer, createIntersectionObserver: createIntersectionObserver$1, + createSelectorQuery: createSelectorQuery$1, canIUse, makePhoneCall, getSystemInfo, @@ -2831,4 +2846,4 @@ function render$a(_ctx, _cache, $props, $setup, $data, $options) { ; script$a.render = render$a; script$a.__file = "packages/uni-h5/src/framework/components/async-loading/index.vue"; -export {script$9 as AsyncErrorComponent, script$a as AsyncLoadingComponent, script$8 as PageComponent, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver$1 as createIntersectionObserver, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getRealPath, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px}; +export {script$9 as AsyncErrorComponent, script$a as AsyncLoadingComponent, script$8 as PageComponent, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver$1 as createIntersectionObserver, createSelectorQuery$1 as createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getRealPath, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px}; diff --git a/packages/uni-h5/src/service/api/base/canIUse.ts b/packages/uni-h5/src/service/api/base/canIUse.ts index ce6535e0d..1d22f9bb0 100644 --- a/packages/uni-h5/src/service/api/base/canIUse.ts +++ b/packages/uni-h5/src/service/api/base/canIUse.ts @@ -1,6 +1,6 @@ import { hasOwn } from '@vue/shared' -import { createApi, CanIUseProtocol } from '@dcloudio/uni-api' +import { createApi, CanIUseProtocol, API_TYPE_SYNC } from '@dcloudio/uni-api' function cssSupports(css: string) { return window.CSS && window.CSS.supports && window.CSS.supports(css) @@ -12,9 +12,13 @@ const SCHEMA_CSS = { 'css.constant': cssSupports('top:constant(a)') } -export const canIUse = createApi((schema: string) => { - if (hasOwn(SCHEMA_CSS, schema)) { - return SCHEMA_CSS[schema] - } - return true -}, CanIUseProtocol) +export const canIUse = createApi( + { type: API_TYPE_SYNC, name: 'canIUse' }, + (schema: string) => { + if (hasOwn(SCHEMA_CSS, schema)) { + return SCHEMA_CSS[schema] + } + return true + }, + CanIUseProtocol +) diff --git a/packages/uni-h5/src/service/api/device/getSystemInfo.ts b/packages/uni-h5/src/service/api/device/getSystemInfo.ts index 2eca6cda5..a4f6fd910 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfo.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfo.ts @@ -1,7 +1,10 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api' import { getSystemInfoSync } from './getSystemInfoSync' -export const getSystemInfo = createApi(() => { - return getSystemInfoSync() -}) +export const getSystemInfo = createApi( + { type: API_TYPE_ASYNC, name: 'getSystemInfo' }, + () => { + return getSystemInfoSync() + } +) diff --git a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts index be41999b0..0b20c8613 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts @@ -1,6 +1,6 @@ import safeAreaInsets from 'safe-area-insets' -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_SYNC, createApi } from '@dcloudio/uni-api' import { getWindowOffset } from '@dcloudio/uni-core' @@ -16,122 +16,125 @@ const isIOS = /iphone|ipad|ipod/i.test(ua) /** * 获取系统信息-同步 */ -export const getSystemInfoSync = createApi(() => { - var screen = window.screen - var pixelRatio = window.devicePixelRatio - // 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正 - const screenFix = - /^Apple/.test(navigator.vendor) && typeof window.orientation === 'number' - const landscape = screenFix && Math.abs(window.orientation as number) === 90 - var screenWidth = screenFix - ? Math[landscape ? 'max' : 'min'](screen.width, screen.height) - : screen.width - var screenHeight = screenFix - ? Math[landscape ? 'min' : 'max'](screen.height, screen.width) - : screen.height - var windowWidth = - Math.min( - window.innerWidth, - document.documentElement.clientWidth, - screenWidth - ) || screenWidth - var windowHeight = window.innerHeight - var language = navigator.language - var statusBarHeight = safeAreaInsets.top - var osname - var osversion - var model +export const getSystemInfoSync = createApi( + { type: API_TYPE_SYNC }, + () => { + var screen = window.screen + var pixelRatio = window.devicePixelRatio + // 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正 + const screenFix = + /^Apple/.test(navigator.vendor) && typeof window.orientation === 'number' + const landscape = screenFix && Math.abs(window.orientation as number) === 90 + var screenWidth = screenFix + ? Math[landscape ? 'max' : 'min'](screen.width, screen.height) + : screen.width + var screenHeight = screenFix + ? Math[landscape ? 'min' : 'max'](screen.height, screen.width) + : screen.height + var windowWidth = + Math.min( + window.innerWidth, + document.documentElement.clientWidth, + screenWidth + ) || screenWidth + var windowHeight = window.innerHeight + var language = navigator.language + var statusBarHeight = safeAreaInsets.top + var osname + var osversion + var model - if (isIOS) { - osname = 'iOS' - const osversionFind = ua.match(/OS\s([\w_]+)\slike/) - if (osversionFind) { - osversion = osversionFind[1].replace(/_/g, '.') - } - const modelFind = ua.match(/\(([a-zA-Z]+);/) - if (modelFind) { - model = modelFind[1] - } - } else if (isAndroid) { - osname = 'Android' - // eslint-disable-next-line no-useless-escape - const osversionFind = ua.match(/Android[\s/]([\w\.]+)[;\s]/) - if (osversionFind) { - osversion = osversionFind[1] - } - const infoFind = ua.match(/\((.+?)\)/) - const infos = infoFind ? infoFind[1].split(';') : ua.split(' ') - // eslint-disable-next-line no-useless-escape - const otherInfo = [ - /\bAndroid\b/i, - /\bLinux\b/i, - /\bU\b/i, - /^\s?[a-z][a-z]$/i, - /^\s?[a-z][a-z]-[a-z][a-z]$/i, - /\bwv\b/i, - /\/[\d\.,]+$/, - /^\s?[\d\.,]+$/, - /\bBrowser\b/i, - /\bMobile\b/i - ] - for (let i = 0; i < infos.length; i++) { - const info = infos[i] - if (info.indexOf('Build') > 0) { - model = info.split('Build')[0].trim() - break + if (isIOS) { + osname = 'iOS' + const osversionFind = ua.match(/OS\s([\w_]+)\slike/) + if (osversionFind) { + osversion = osversionFind[1].replace(/_/g, '.') + } + const modelFind = ua.match(/\(([a-zA-Z]+);/) + if (modelFind) { + model = modelFind[1] + } + } else if (isAndroid) { + osname = 'Android' + // eslint-disable-next-line no-useless-escape + const osversionFind = ua.match(/Android[\s/]([\w\.]+)[;\s]/) + if (osversionFind) { + osversion = osversionFind[1] } - let other - for (let o = 0; o < otherInfo.length; o++) { - if (otherInfo[o].test(info)) { - other = true + const infoFind = ua.match(/\((.+?)\)/) + const infos = infoFind ? infoFind[1].split(';') : ua.split(' ') + // eslint-disable-next-line no-useless-escape + const otherInfo = [ + /\bAndroid\b/i, + /\bLinux\b/i, + /\bU\b/i, + /^\s?[a-z][a-z]$/i, + /^\s?[a-z][a-z]-[a-z][a-z]$/i, + /\bwv\b/i, + /\/[\d\.,]+$/, + /^\s?[\d\.,]+$/, + /\bBrowser\b/i, + /\bMobile\b/i + ] + for (let i = 0; i < infos.length; i++) { + const info = infos[i] + if (info.indexOf('Build') > 0) { + model = info.split('Build')[0].trim() + break + } + let other + for (let o = 0; o < otherInfo.length; o++) { + if (otherInfo[o].test(info)) { + other = true + break + } + } + if (!other) { + model = info.trim() break } } - if (!other) { - model = info.trim() - break - } + } else { + osname = 'Other' + osversion = '0' } - } else { - osname = 'Other' - osversion = '0' - } - var system = `${osname} ${osversion}` - var platform = osname.toLocaleLowerCase() - var safeArea = { - left: safeAreaInsets.left, - right: windowWidth - safeAreaInsets.right, - top: safeAreaInsets.top, - bottom: windowHeight - safeAreaInsets.bottom, - width: windowWidth - safeAreaInsets.left - safeAreaInsets.right, - height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom - } + var system = `${osname} ${osversion}` + var platform = osname.toLocaleLowerCase() + var safeArea = { + left: safeAreaInsets.left, + right: windowWidth - safeAreaInsets.right, + top: safeAreaInsets.top, + bottom: windowHeight - safeAreaInsets.bottom, + width: windowWidth - safeAreaInsets.left - safeAreaInsets.right, + height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom + } - const { top: windowTop, bottom: windowBottom } = getWindowOffset() + const { top: windowTop, bottom: windowBottom } = getWindowOffset() - windowHeight -= windowTop - windowHeight -= windowBottom + windowHeight -= windowTop + windowHeight -= windowBottom - return { - windowTop, - windowBottom, - windowWidth, - windowHeight, - pixelRatio, - screenWidth, - screenHeight, - language, - statusBarHeight, - system, - platform, - model, - safeArea, - safeAreaInsets: { - top: safeAreaInsets.top, - right: safeAreaInsets.right, - bottom: safeAreaInsets.bottom, - left: safeAreaInsets.left - } - } as UniApp.GetSystemInfoResult -}) + return { + windowTop, + windowBottom, + windowWidth, + windowHeight, + pixelRatio, + screenWidth, + screenHeight, + language, + statusBarHeight, + system, + platform, + model, + safeArea, + safeAreaInsets: { + top: safeAreaInsets.top, + right: safeAreaInsets.right, + bottom: safeAreaInsets.bottom, + left: safeAreaInsets.left + } + } as UniApp.GetSystemInfoResult + } +) diff --git a/packages/uni-h5/src/service/api/device/makePhoneCall.ts b/packages/uni-h5/src/service/api/device/makePhoneCall.ts index 368452ea8..7920c61ac 100644 --- a/packages/uni-h5/src/service/api/device/makePhoneCall.ts +++ b/packages/uni-h5/src/service/api/device/makePhoneCall.ts @@ -1,5 +1,13 @@ -import { createApi, MakePhoneCallProtocol } from '@dcloudio/uni-api' +import { + API_TYPE_ASYNC, + createApi, + MakePhoneCallProtocol +} from '@dcloudio/uni-api' -export const makePhoneCall = createApi(option => { - window.location.href = `tel:${option.phoneNumber}` -}, MakePhoneCallProtocol) +export const makePhoneCall = createApi( + { type: API_TYPE_ASYNC, name: 'makePhoneCall' }, + option => { + window.location.href = `tel:${option.phoneNumber}` + }, + MakePhoneCallProtocol +) diff --git a/packages/uni-h5/src/service/api/file/openDocument.ts b/packages/uni-h5/src/service/api/file/openDocument.ts index b7483df78..92d12dabd 100644 --- a/packages/uni-h5/src/service/api/file/openDocument.ts +++ b/packages/uni-h5/src/service/api/file/openDocument.ts @@ -1,5 +1,13 @@ -import { createApi, OpenDocumentProtocol } from '@dcloudio/uni-api' +import { + API_TYPE_ASYNC, + createApi, + OpenDocumentProtocol +} from '@dcloudio/uni-api' -export const openDocument = createApi(option => { - window.open(option.filePath) -}, OpenDocumentProtocol) +export const openDocument = createApi( + { type: API_TYPE_ASYNC, name: 'openDocument' }, + option => { + window.open(option.filePath) + }, + OpenDocumentProtocol +) diff --git a/packages/uni-h5/src/service/api/index.ts b/packages/uni-h5/src/service/api/index.ts index de15009ee..c3df6e038 100644 --- a/packages/uni-h5/src/service/api/index.ts +++ b/packages/uni-h5/src/service/api/index.ts @@ -23,5 +23,6 @@ export { promiseInterceptor, arrayBufferToBase64, base64ToArrayBuffer, - createIntersectionObserver + createIntersectionObserver, + createSelectorQuery } from '@dcloudio/uni-api' diff --git a/packages/uni-h5/src/service/api/media/getImageInfo.ts b/packages/uni-h5/src/service/api/media/getImageInfo.ts index df58314af..90a37e3b1 100644 --- a/packages/uni-h5/src/service/api/media/getImageInfo.ts +++ b/packages/uni-h5/src/service/api/media/getImageInfo.ts @@ -1,4 +1,5 @@ import { + API_TYPE_ASYNC, createApi, GetImageInfoOptions, GetImageInfoProtocol @@ -9,28 +10,23 @@ function _getServiceAddress() { } export const getImageInfo = createApi( - ({ src }, callbackId?: number) => { - const { invokeCallbackHandler: invoke } = UniServiceJSBridge + { type: API_TYPE_ASYNC, name: 'getImageInfo', options: GetImageInfoOptions }, + ({ src }, callback?: Function) => { const img = new Image() - const realPath = src img.onload = function() { - invoke(callbackId, { + callback!({ errMsg: 'getImageInfo:ok', width: img.naturalWidth, height: img.naturalHeight, - path: - realPath.indexOf('/') === 0 - ? _getServiceAddress() + realPath - : realPath + path: src.indexOf('/') === 0 ? _getServiceAddress() + src : src }) } img.onerror = function() { - invoke(callbackId, { + callback!({ errMsg: 'getImageInfo:fail' }) } img.src = src }, - GetImageInfoProtocol, - GetImageInfoOptions + GetImageInfoProtocol ) diff --git a/packages/uni-h5/src/service/api/route/navigateBack.ts b/packages/uni-h5/src/service/api/route/navigateBack.ts index 6cc4755e9..94ec294c5 100644 --- a/packages/uni-h5/src/service/api/route/navigateBack.ts +++ b/packages/uni-h5/src/service/api/route/navigateBack.ts @@ -1,3 +1,6 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api' -export const navigateBack = createApi(() => {}) +export const navigateBack = createApi( + { type: API_TYPE_ASYNC }, + () => {} +) diff --git a/packages/uni-h5/src/service/api/route/navigateTo.ts b/packages/uni-h5/src/service/api/route/navigateTo.ts index f05f8dfce..db55f4445 100644 --- a/packages/uni-h5/src/service/api/route/navigateTo.ts +++ b/packages/uni-h5/src/service/api/route/navigateTo.ts @@ -1,6 +1,9 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api' -export const navigateTo = createApi(options => { - const router = getApp().$router - router.push(options.url) -}) +export const navigateTo = createApi( + { type: API_TYPE_ASYNC }, + options => { + const router = getApp().$router + router.push(options.url) + } +) diff --git a/packages/uni-h5/src/service/api/route/reLaunch.ts b/packages/uni-h5/src/service/api/route/reLaunch.ts index 01bf1f4c5..ab359159d 100644 --- a/packages/uni-h5/src/service/api/route/reLaunch.ts +++ b/packages/uni-h5/src/service/api/route/reLaunch.ts @@ -1,3 +1,3 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api' -export const reLaunch = createApi(() => {}) +export const reLaunch = createApi({ type: API_TYPE_ASYNC }, () => {}) diff --git a/packages/uni-h5/src/service/api/route/redirectTo.ts b/packages/uni-h5/src/service/api/route/redirectTo.ts index 9e7d28445..eabbf9931 100644 --- a/packages/uni-h5/src/service/api/route/redirectTo.ts +++ b/packages/uni-h5/src/service/api/route/redirectTo.ts @@ -1,3 +1,3 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api' -export const redirectTo = createApi(() => {}) +export const redirectTo = createApi({ type: API_TYPE_ASYNC }, () => {}) diff --git a/packages/uni-h5/src/service/api/route/switchTab.ts b/packages/uni-h5/src/service/api/route/switchTab.ts index 653b8bc8f..8e6882ce6 100644 --- a/packages/uni-h5/src/service/api/route/switchTab.ts +++ b/packages/uni-h5/src/service/api/route/switchTab.ts @@ -1,3 +1,3 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_ASYNC, createApi } from '@dcloudio/uni-api' -export const switchTab = createApi(() => {}) +export const switchTab = createApi({ type: API_TYPE_ASYNC }, () => {}) diff --git a/packages/uni-h5/src/service/api/util/getRealPath.ts b/packages/uni-h5/src/service/api/util/getRealPath.ts index 8b10986e7..27cfe7ae2 100644 --- a/packages/uni-h5/src/service/api/util/getRealPath.ts +++ b/packages/uni-h5/src/service/api/util/getRealPath.ts @@ -1,5 +1,8 @@ -import { createApi } from '@dcloudio/uni-api' +import { API_TYPE_SYNC, createApi } from '@dcloudio/uni-api' -export const getRealPath = createApi((path: string) => { - return path -}) +export const getRealPath = createApi( + { type: API_TYPE_SYNC }, + (path: string) => { + return path + } +) diff --git a/packages/uni-mp-alipay/dist/uni.api.esm.js b/packages/uni-mp-alipay/dist/uni.api.esm.js index 884615c04..d1ffce34a 100644 --- a/packages/uni-mp-alipay/dist/uni.api.esm.js +++ b/packages/uni-mp-alipay/dist/uni.api.esm.js @@ -1,8 +1,23 @@ import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared'; -function createApi(fn, protocol, options) { - if ((process.env.NODE_ENV !== 'production') && protocol) ; - return fn; +const API_TYPE_SYNC = 1; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; + } +} +function createApi({ type, name, options }, fn, protocol) { + return function (...args) { + if (type === API_TYPE_SYNC) { + if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Upx2pxProtocol = [ @@ -24,7 +39,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createApi((number, newDeviceWidth) => { +const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -206,7 +221,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createApi((method, interceptor) => { +const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createApi((method, interceptor) => { +const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(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 8dab33754..508f23874 100644 --- a/packages/uni-mp-baidu/dist/uni.api.esm.js +++ b/packages/uni-mp-baidu/dist/uni.api.esm.js @@ -1,8 +1,23 @@ import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared'; -function createApi(fn, protocol, options) { - if ((process.env.NODE_ENV !== 'production') && protocol) ; - return fn; +const API_TYPE_SYNC = 1; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; + } +} +function createApi({ type, name, options }, fn, protocol) { + return function (...args) { + if (type === API_TYPE_SYNC) { + if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Upx2pxProtocol = [ @@ -24,7 +39,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createApi((number, newDeviceWidth) => { +const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -206,7 +221,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createApi((method, interceptor) => { +const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createApi((method, interceptor) => { +const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(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 aef09c723..9a0d8877a 100644 --- a/packages/uni-mp-qq/dist/uni.api.esm.js +++ b/packages/uni-mp-qq/dist/uni.api.esm.js @@ -1,8 +1,23 @@ import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared'; -function createApi(fn, protocol, options) { - if ((process.env.NODE_ENV !== 'production') && protocol) ; - return fn; +const API_TYPE_SYNC = 1; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; + } +} +function createApi({ type, name, options }, fn, protocol) { + return function (...args) { + if (type === API_TYPE_SYNC) { + if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Upx2pxProtocol = [ @@ -24,7 +39,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createApi((number, newDeviceWidth) => { +const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -206,7 +221,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createApi((method, interceptor) => { +const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createApi((method, interceptor) => { +const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(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 403cebdd6..e60a89cf6 100644 --- a/packages/uni-mp-toutiao/dist/uni.api.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.api.esm.js @@ -1,8 +1,23 @@ import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared'; -function createApi(fn, protocol, options) { - if ((process.env.NODE_ENV !== 'production') && protocol) ; - return fn; +const API_TYPE_SYNC = 1; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; + } +} +function createApi({ type, name, options }, fn, protocol) { + return function (...args) { + if (type === API_TYPE_SYNC) { + if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Upx2pxProtocol = [ @@ -24,7 +39,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createApi((number, newDeviceWidth) => { +const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -206,7 +221,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createApi((method, interceptor) => { +const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createApi((method, interceptor) => { +const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(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 178b38dad..eb50c7707 100644 --- a/packages/uni-mp-weixin/dist/uni.api.esm.js +++ b/packages/uni-mp-weixin/dist/uni.api.esm.js @@ -1,8 +1,23 @@ import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared'; -function createApi(fn, protocol, options) { - if ((process.env.NODE_ENV !== 'production') && protocol) ; - return fn; +const API_TYPE_SYNC = 1; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; + } +} +function createApi({ type, name, options }, fn, protocol) { + return function (...args) { + if (type === API_TYPE_SYNC) { + if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Upx2pxProtocol = [ @@ -24,7 +39,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createApi((number, newDeviceWidth) => { +const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -206,7 +221,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createApi((method, interceptor) => { +const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createApi((method, interceptor) => { +const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(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 e6a0157fe..ac85e0913 100644 --- a/packages/uni-quickapp-webview/dist/uni.api.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.api.esm.js @@ -1,8 +1,23 @@ import { isArray, isPromise, isFunction, isPlainObject, hasOwn, isString } from '@vue/shared'; -function createApi(fn, protocol, options) { - if ((process.env.NODE_ENV !== 'production') && protocol) ; - return fn; +const API_TYPE_SYNC = 1; +function validateProtocol(name, args, protocol) { + console.log(name, args, protocol); + return true; +} +function formatApiArgs(args, options) { + if (!options) { + return args; + } +} +function createApi({ type, name, options }, fn, protocol) { + return function (...args) { + if (type === API_TYPE_SYNC) { + if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) { + return fn.apply(null, formatApiArgs(args, options)); + } + } + }; } const Upx2pxProtocol = [ @@ -24,7 +39,7 @@ function checkDeviceWidth() { deviceDPR = pixelRatio; isIOS = platform === 'ios'; } -const upx2px = createApi((number, newDeviceWidth) => { +const upx2px = createApi({ type: API_TYPE_SYNC, name: 'upx2px' }, (number, newDeviceWidth) => { if (deviceWidth === 0) { checkDeviceWidth(); } @@ -206,7 +221,7 @@ function removeHook(hooks, hook) { hooks.splice(index, 1); } } -const addInterceptor = createApi((method, interceptor) => { +const addInterceptor = createApi({ type: API_TYPE_SYNC, name: 'addInterceptor' }, (method, interceptor) => { if (typeof method === 'string' && isPlainObject(interceptor)) { mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); } @@ -214,7 +229,7 @@ const addInterceptor = createApi((method, interceptor) => { mergeInterceptorHook(globalInterceptors, method); } }, AddInterceptorProtocol); -const removeInterceptor = createApi((method, interceptor) => { +const removeInterceptor = createApi({ type: API_TYPE_SYNC, name: 'removeInterceptor' }, (method, interceptor) => { if (typeof method === 'string') { if (isPlainObject(interceptor)) { removeInterceptorHook(scopedInterceptors[method], interceptor); -- GitLab