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

feat: createApi => defineApi

上级 9151b16f
......@@ -63,12 +63,12 @@ function wrapperApi<T extends Function>(
} as unknown) as T
}
export function createOnApi<T extends Function>(
export function defineOnApi<T extends Function>(
name: string,
fn: T,
options?: ApiOptions
) {
return createApi(
return defineApi(
API_TYPE_ON,
name,
fn,
......@@ -77,13 +77,13 @@ export function createOnApi<T extends Function>(
)
}
export function createTaskApi<T extends Function>(
export function defineTaskApi<T extends Function>(
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(
return defineApi(
API_TYPE_TASK,
name,
fn,
......@@ -92,13 +92,13 @@ export function createTaskApi<T extends Function>(
)
}
export function createSyncApi<T extends Function>(
export function defineSyncApi<T extends Function>(
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(
return defineApi(
API_TYPE_SYNC,
name,
fn,
......@@ -107,18 +107,18 @@ export function createSyncApi<T extends Function>(
)
}
export function createAsyncApi<T extends Function>(
export function defineAsyncApi<T extends Function>(
name: string,
fn: T,
protocol?: ApiProtocols,
options?: ApiOptions
) {
return promisify(
createApi(API_TYPE_ASYNC, name, fn, __DEV__ ? protocol : undefined, options)
defineApi(API_TYPE_ASYNC, name, fn, __DEV__ ? protocol : undefined, options)
)
}
function createApi<T extends Function>(
function defineApi<T extends Function>(
type: API_TYPES,
name: string,
fn: T,
......
......@@ -23,10 +23,10 @@ export * from './protocols/media/getImageInfo'
// helpers
export {
createOnApi,
createTaskApi,
createSyncApi,
createAsyncApi,
defineOnApi,
defineTaskApi,
defineSyncApi,
defineAsyncApi,
} from './helpers/api'
export { handlePromise } from './helpers/api/promise'
......
import { getRealPath } from '@dcloudio/uni-platform'
import { ApiOptions, ApiProtocol } from '../type'
export const GetImageInfoOptions: ApiOptions = {
formatArgs: {
src(src, params) {
params.src = (uni as any).getRealPath(src)
params.src = getRealPath(src)
},
},
}
......
// @ts-ignore
import { encode, decode } from '../../helpers/base64-arraybuffer'
import { createSyncApi } from '../../helpers/api'
import { defineSyncApi } from '../../helpers/api'
import {
Base64ToArrayBufferProtocol,
ArrayBufferToBase64Protocol,
} from '../../protocols/base/base64'
export const base64ToArrayBuffer = createSyncApi<
export const base64ToArrayBuffer = defineSyncApi<
typeof uni.base64ToArrayBuffer
>(
'base64ToArrayBuffer',
......@@ -18,7 +18,7 @@ export const base64ToArrayBuffer = createSyncApi<
Base64ToArrayBufferProtocol
)
export const arrayBufferToBase64 = createSyncApi<
export const arrayBufferToBase64 = defineSyncApi<
typeof uni.arrayBufferToBase64
>(
'arrayBufferToBase64',
......
......@@ -8,7 +8,7 @@ import {
HOOKS,
} from '../../helpers/interceptor'
import { createSyncApi } from '../../helpers/api'
import { defineSyncApi } from '../../helpers/api'
import {
AddInterceptorProtocol,
......@@ -80,7 +80,7 @@ function removeHook(hooks: Function[] | undefined, hook: Function) {
}
}
export const addInterceptor = createSyncApi(
export const addInterceptor = defineSyncApi(
'addInterceptor',
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
......@@ -95,7 +95,7 @@ export const addInterceptor = createSyncApi(
AddInterceptorProtocol
)
export const removeInterceptor = createSyncApi(
export const removeInterceptor = defineSyncApi(
'removeInterceptor',
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
if (typeof method === 'string') {
......
import { getBaseSystemInfo } from '@dcloudio/uni-platform'
import { createSyncApi } from '../../helpers/api'
import { defineSyncApi } from '../../helpers/api'
import { Upx2pxProtocol } from '../../protocols/base/upx2px'
const EPS = 1e-4
......@@ -15,7 +15,7 @@ function checkDeviceWidth() {
isIOS = platform === 'ios'
}
export const upx2px = createSyncApi<typeof uni.upx2px>(
export const upx2px = defineSyncApi<typeof uni.upx2px>(
'upx2px',
(number, newDeviceWidth?: number) => {
if (deviceWidth === 0) {
......
......@@ -2,7 +2,7 @@ import { extend } from '@vue/shared'
import { ServiceJSBridge } from '@dcloudio/uni-core'
import { createSyncApi } from '../../helpers/api'
import { defineSyncApi } from '../../helpers/api'
import { getCurrentPageVm } from '../utils'
const defaultOptions = {
......@@ -120,7 +120,7 @@ class ServiceIntersectionObserver {
}
}
export const createIntersectionObserver = createSyncApi<
export const createIntersectionObserver = defineSyncApi<
typeof uni.createIntersectionObserver
>('createIntersectionObserver', (context?, options?) => {
if (!context) {
......
......@@ -3319,7 +3319,7 @@ function addBase(filePath) {
}
return base + filePath;
}
function getRealPath$1(filePath) {
function getRealPath(filePath) {
if (__uniConfig.router.base === "./") {
filePath = filePath.replace(/^\.\/static\//, "/static/");
}
......@@ -3395,7 +3395,7 @@ const _sfc_main$j = {
return this.originalWidth && this.originalHeight ? this.originalWidth / this.originalHeight : 0;
},
realImagePath() {
return getRealPath$1(this.src);
return getRealPath(this.src);
},
modeStyle() {
let size = "auto";
......@@ -7716,13 +7716,13 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options);
}
function createAsyncApi(name, fn, protocol, options) {
return promisify(createApi(API_TYPE_ASYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options));
function defineAsyncApi(name, fn, protocol, options) {
return promisify(defineApi(API_TYPE_ASYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options));
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -7748,10 +7748,10 @@ const ArrayBufferToBase64Protocol = [
required: true
}
];
const base64ToArrayBuffer = /* @__PURE__ */ createSyncApi("base64ToArrayBuffer", (base64) => {
const base64ToArrayBuffer = defineSyncApi("base64ToArrayBuffer", (base64) => {
return decode(base64);
}, Base64ToArrayBufferProtocol);
const arrayBufferToBase64 = /* @__PURE__ */ createSyncApi("arrayBufferToBase64", (arrayBuffer) => {
const arrayBufferToBase64 = defineSyncApi("arrayBufferToBase64", (arrayBuffer) => {
return encode(arrayBuffer);
}, ArrayBufferToBase64Protocol);
const Upx2pxProtocol = [
......@@ -7772,7 +7772,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio2;
isIOS = platform === "ios";
}
const upx2px = /* @__PURE__ */ createSyncApi("upx2px", (number, newDeviceWidth) => {
const upx2px = defineSyncApi("upx2px", (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -7851,14 +7851,14 @@ function removeHook(hooks, hook) {
hooks.splice(index2, 1);
}
}
const addInterceptor = /* @__PURE__ */ createSyncApi("addInterceptor", (method, interceptor) => {
const addInterceptor = defineSyncApi("addInterceptor", (method, interceptor) => {
if (typeof method === "string" && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
} else if (isPlainObject(method)) {
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = /* @__PURE__ */ createSyncApi("removeInterceptor", (method, interceptor) => {
const removeInterceptor = defineSyncApi("removeInterceptor", (method, interceptor) => {
if (typeof method === "string") {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......@@ -7946,7 +7946,7 @@ class ServiceIntersectionObserver {
}, this._pageId);
}
}
const createIntersectionObserver = /* @__PURE__ */ createSyncApi("createIntersectionObserver", (context, options) => {
const createIntersectionObserver = defineSyncApi("createIntersectionObserver", (context, options) => {
if (!context) {
context = getCurrentPageVm();
}
......@@ -7984,7 +7984,7 @@ const OpenDocumentProtocol = {
const GetImageInfoOptions = {
formatArgs: {
src(src, params) {
params.src = uni.getRealPath(src);
params.src = getRealPath(src);
}
}
};
......@@ -8002,16 +8002,16 @@ const SCHEMA_CSS = {
"css.env": cssSupports("top:env(a)"),
"css.constant": cssSupports("top:constant(a)")
};
const canIUse = /* @__PURE__ */ createSyncApi("canIUse", (schema) => {
const canIUse = defineSyncApi("canIUse", (schema) => {
if (hasOwn$1(SCHEMA_CSS, schema)) {
return SCHEMA_CSS[schema];
}
return true;
}, CanIUseProtocol);
const makePhoneCall = /* @__PURE__ */ createAsyncApi("makePhoneCall", (option) => {
const makePhoneCall = defineAsyncApi("makePhoneCall", (option) => {
window.location.href = `tel:${option.phoneNumber}`;
}, MakePhoneCallProtocol);
const getSystemInfoSync = /* @__PURE__ */ createSyncApi("getSystemInfoSync", () => {
const getSystemInfoSync = defineSyncApi("getSystemInfoSync", () => {
const pixelRatio2 = window.devicePixelRatio;
const screenFix = getScreenFix();
const landscape = isLandscape(screenFix);
......@@ -8111,16 +8111,16 @@ const getSystemInfoSync = /* @__PURE__ */ createSyncApi("getSystemInfoSync", ()
}
};
});
const getSystemInfo = /* @__PURE__ */ createAsyncApi("getSystemInfo", () => {
const getSystemInfo = defineAsyncApi("getSystemInfo", () => {
return getSystemInfoSync();
});
const openDocument = /* @__PURE__ */ createAsyncApi("openDocument", (option) => {
const openDocument = defineAsyncApi("openDocument", (option) => {
window.open(option.filePath);
}, OpenDocumentProtocol);
function _getServiceAddress() {
return window.location.protocol + "//" + window.location.host;
}
const getImageInfo = /* @__PURE__ */ createAsyncApi("getImageInfo", ({src}, callback) => {
const getImageInfo = defineAsyncApi("getImageInfo", ({src}, callback) => {
const img = new Image();
img.onload = function() {
callback({
......@@ -8137,9 +8137,9 @@ const getImageInfo = /* @__PURE__ */ createAsyncApi("getImageInfo", ({src}, call
};
img.src = src;
}, GetImageInfoProtocol, GetImageInfoOptions);
const navigateBack = /* @__PURE__ */ createAsyncApi("navigateBack", () => {
const navigateBack = defineAsyncApi("navigateBack", () => {
});
const navigateTo = /* @__PURE__ */ createAsyncApi("navigateTo", (options) => {
const navigateTo = defineAsyncApi("navigateTo", (options) => {
const router = getApp().$router;
router.push({
path: options.url,
......@@ -8147,14 +8147,11 @@ const navigateTo = /* @__PURE__ */ createAsyncApi("navigateTo", (options) => {
state: createPageState("navigateTo")
});
});
const redirectTo = /* @__PURE__ */ createAsyncApi("redirectTo", () => {
const redirectTo = defineAsyncApi("redirectTo", () => {
});
const reLaunch = /* @__PURE__ */ createAsyncApi("reLaunch", () => {
const reLaunch = defineAsyncApi("reLaunch", () => {
});
const switchTab = /* @__PURE__ */ createAsyncApi("switchTab", () => {
});
const getRealPath = /* @__PURE__ */ createSyncApi("getRealPath", (path) => {
return path;
const switchTab = defineAsyncApi("switchTab", () => {
});
var api = /* @__PURE__ */ Object.freeze({
__proto__: null,
......@@ -8177,8 +8174,7 @@ var api = /* @__PURE__ */ Object.freeze({
navigateTo,
redirectTo,
reLaunch,
switchTab,
getRealPath
switchTab
});
const uni$1 = api;
const UniServiceJSBridge$1 = extend(ServiceJSBridge, {
......@@ -8464,7 +8460,7 @@ function usePageHeadButtons(navigationBar) {
const fonts = Object.create(null);
buttons.forEach((btn) => {
if (btn.fontSrc && !btn.fontFamily) {
const fontSrc = getRealPath$1(btn.fontSrc);
const fontSrc = getRealPath(btn.fontSrc);
let fontFamily = fonts[fontSrc];
if (!fontFamily) {
fontFamily = `font${Date.now()}`;
......@@ -9268,4 +9264,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
]);
}
_sfc_main.render = _sfc_render;
export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$p as Audio, _sfc_main$o as Canvas, _sfc_main$n as Checkbox, _sfc_main$m as CheckboxGroup, _sfc_main$l as Editor, _sfc_main$k as Form, index$1 as Icon, _sfc_main$j as Image, _sfc_main$i as Input, _sfc_main$h as Label, _sfc_main$g as MovableView, _sfc_main$f as Navigator, index as PageComponent, _sfc_main$e as Progress, _sfc_main$d as Radio, _sfc_main$c as RadioGroup, _sfc_main$b as ResizeSensor, _sfc_main$a as RichText, _sfc_main$9 as ScrollView, _sfc_main$8 as Slider, _sfc_main$7 as SwiperItem, _sfc_main$6 as Switch, _sfc_main$5 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getRealPath, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index$2 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px};
export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$p as Audio, _sfc_main$o as Canvas, _sfc_main$n as Checkbox, _sfc_main$m as CheckboxGroup, _sfc_main$l as Editor, _sfc_main$k as Form, index$1 as Icon, _sfc_main$j as Image, _sfc_main$i as Input, _sfc_main$h as Label, _sfc_main$g as MovableView, _sfc_main$f as Navigator, index as PageComponent, _sfc_main$e as Progress, _sfc_main$d as Radio, _sfc_main$c as RadioGroup, _sfc_main$b as ResizeSensor, _sfc_main$a as RichText, _sfc_main$9 as ScrollView, _sfc_main$8 as Slider, _sfc_main$7 as SwiperItem, _sfc_main$6 as Switch, _sfc_main$5 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getSystemInfo, getSystemInfoSync, makePhoneCall, navigateBack, navigateTo, openDocument, index$2 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, switchTab, uni$1 as uni, upx2px};
import { hasOwn } from '@vue/shared'
import { CanIUseProtocol, createSyncApi } from '@dcloudio/uni-api'
import { CanIUseProtocol, defineSyncApi } from '@dcloudio/uni-api'
function cssSupports(css: string) {
return window.CSS && window.CSS.supports && window.CSS.supports(css)
......@@ -12,7 +12,7 @@ const SCHEMA_CSS = {
'css.constant': cssSupports('top:constant(a)'),
}
export const canIUse = createSyncApi<typeof uni.canIUse>(
export const canIUse = defineSyncApi<typeof uni.canIUse>(
'canIUse',
(schema: string) => {
if (hasOwn(SCHEMA_CSS, schema)) {
......
import { createAsyncApi } from '@dcloudio/uni-api'
import { defineAsyncApi } from '@dcloudio/uni-api'
import { getSystemInfoSync } from './getSystemInfoSync'
export const getSystemInfo = createAsyncApi<typeof uni.getSystemInfo>(
export const getSystemInfo = defineAsyncApi<typeof uni.getSystemInfo>(
'getSystemInfo',
() => {
return getSystemInfoSync()
......
import safeAreaInsets from 'safe-area-insets'
import { createSyncApi } from '@dcloudio/uni-api'
import { defineSyncApi } from '@dcloudio/uni-api'
import { getWindowOffset } from '@dcloudio/uni-core'
......@@ -18,7 +18,7 @@ import {
/**
* 获取系统信息-同步
*/
export const getSystemInfoSync = createSyncApi<typeof uni.getSystemInfoSync>(
export const getSystemInfoSync = defineSyncApi<typeof uni.getSystemInfoSync>(
'getSystemInfoSync',
() => {
const pixelRatio = window.devicePixelRatio
......
import { createAsyncApi, MakePhoneCallProtocol } from '@dcloudio/uni-api'
import { defineAsyncApi, MakePhoneCallProtocol } from '@dcloudio/uni-api'
export const makePhoneCall = createAsyncApi<typeof uni.makePhoneCall>(
export const makePhoneCall = defineAsyncApi<typeof uni.makePhoneCall>(
'makePhoneCall',
(option) => {
window.location.href = `tel:${option.phoneNumber}`
......
import { createAsyncApi, OpenDocumentProtocol } from '@dcloudio/uni-api'
import { defineAsyncApi, OpenDocumentProtocol } from '@dcloudio/uni-api'
export const openDocument = createAsyncApi<typeof uni.openDocument>(
export const openDocument = defineAsyncApi<typeof uni.openDocument>(
'openDocument',
(option) => {
window.open(option.filePath)
......
......@@ -14,8 +14,6 @@ export * from './route/redirectTo'
export * from './route/reLaunch'
export * from './route/switchTab'
export * from './util/getRealPath'
export {
upx2px,
addInterceptor,
......
import {
createAsyncApi,
defineAsyncApi,
GetImageInfoOptions,
GetImageInfoProtocol,
} from '@dcloudio/uni-api'
......@@ -8,7 +8,7 @@ function _getServiceAddress() {
return window.location.protocol + '//' + window.location.host
}
export const getImageInfo = createAsyncApi<typeof uni.getImageInfo>(
export const getImageInfo = defineAsyncApi<typeof uni.getImageInfo>(
'getImageInfo',
({ src }, callback?: Function) => {
const img = new Image()
......
import { createAsyncApi } from '@dcloudio/uni-api'
import { defineAsyncApi } from '@dcloudio/uni-api'
export const navigateBack = createAsyncApi<typeof uni.navigateBack>(
export const navigateBack = defineAsyncApi<typeof uni.navigateBack>(
'navigateBack',
() => {}
)
import { Router } from 'vue-router'
import { createAsyncApi } from '@dcloudio/uni-api'
import { defineAsyncApi } from '@dcloudio/uni-api'
import { createPageState } from '../../../framework/plugin/page'
export const navigateTo = createAsyncApi<typeof uni.navigateTo>(
export const navigateTo = defineAsyncApi<typeof uni.navigateTo>(
'navigateTo',
(options) => {
const router = getApp().$router as Router
......
import { createAsyncApi } from '@dcloudio/uni-api'
import { defineAsyncApi } from '@dcloudio/uni-api'
export const reLaunch = createAsyncApi('reLaunch', () => {})
export const reLaunch = defineAsyncApi('reLaunch', () => {})
import { createAsyncApi } from '@dcloudio/uni-api'
import { defineAsyncApi } from '@dcloudio/uni-api'
export const redirectTo = createAsyncApi('redirectTo', () => {})
export const redirectTo = defineAsyncApi('redirectTo', () => {})
import { createAsyncApi } from '@dcloudio/uni-api'
import { defineAsyncApi } from '@dcloudio/uni-api'
export const switchTab = createAsyncApi('switchTab', () => {})
export const switchTab = defineAsyncApi('switchTab', () => {})
import { createSyncApi } from '@dcloudio/uni-api'
export const getRealPath = createSyncApi('getRealPath', (path: string) => {
return path
})
......@@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -324,7 +324,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -506,7 +506,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) =>
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
export function getBaseSystemInfo() {
return my.getSystemInfoSync()
}
export function getRealPath() {}
......@@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -324,7 +324,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -506,7 +506,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) =>
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
export function getBaseSystemInfo() {
return swan.getSystemInfoSync()
}
export function getRealPath() {}
......@@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -324,7 +324,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -506,7 +506,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) =>
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
export function getBaseSystemInfo() {
return qq.getSystemInfoSync()
}
export function getRealPath() {}
......@@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -324,7 +324,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -506,7 +506,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) =>
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
export function getBaseSystemInfo() {
return tt.getSystemInfoSync()
}
export function getRealPath() {}
......@@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -324,7 +324,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -506,7 +506,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) =>
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
export function getBaseSystemInfo() {
return wx.getSystemInfoSync()
}
export function getRealPath() {}
......@@ -285,10 +285,10 @@ function wrapperApi(fn, name, protocol, options) {
return fn.apply(null, formatApiArgs(args));
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
function defineSyncApi(name, fn, protocol, options) {
return defineApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
function defineApi(type, name, fn, protocol, options) {
switch (type) {
case API_TYPE_ON:
return wrapperApi(wrapperOnApi(name, fn), name, protocol);
......@@ -324,7 +324,7 @@ function checkDeviceWidth() {
deviceDPR = pixelRatio;
isIOS = platform === 'ios';
}
const upx2px = createSyncApi('upx2px', (number, newDeviceWidth) => {
const upx2px = defineSyncApi('upx2px', (number, newDeviceWidth) => {
if (deviceWidth === 0) {
checkDeviceWidth();
}
......@@ -506,7 +506,7 @@ function removeHook(hooks, hook) {
hooks.splice(index, 1);
}
}
const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) => {
const addInterceptor = defineSyncApi('addInterceptor', (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
......@@ -514,7 +514,7 @@ const addInterceptor = createSyncApi('addInterceptor', (method, interceptor) =>
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = createSyncApi('removeInterceptor', (method, interceptor) => {
const removeInterceptor = defineSyncApi('removeInterceptor', (method, interceptor) => {
if (typeof method === 'string') {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
......
export function getBaseSystemInfo() {
return qa.getSystemInfoSync()
}
export function getRealPath() {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册