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

chore: typeof x === 'function' => isFunction

上级 21bbe4a3
import { ComponentInternalInstance, ComponentPublicInstance } from 'vue'
import { isArray } from '@vue/shared'
import { isArray, isFunction } from '@vue/shared'
import { resolveComponentInstance } from '@dcloudio/uni-shared'
import { getCurrentPageVm, getPageIdByVm } from '@dcloudio/uni-core'
import { requestComponentInfo } from '@dcloudio/uni-platform'
......@@ -146,12 +146,12 @@ class SelectorQuery implements UniApp.SelectorQuery {
convertContext(result)
}
const queueCb = queueCbs[index]
if (typeof queueCb === 'function') {
if (isFunction(queueCb)) {
queueCb.call(this, result)
}
})
// isFn(callback) &&
if (typeof callback === 'function') {
if (isFunction(callback)) {
callback.call(this, res)
}
}
......
......@@ -1766,7 +1766,7 @@ function showPage({ context = {}, url, data = {}, style = {}, onMessage, onClose
});
page.addEventListener('close', onClose);
addEventListener(pageId, (message) => {
if (typeof onMessage === 'function') {
if (isFunction(onMessage)) {
onMessage(message.data);
}
if (!message.keep) {
......@@ -10753,12 +10753,12 @@ class SelectorQuery {
convertContext(result);
}
const queueCb = queueCbs[index];
if (typeof queueCb === 'function') {
if (isFunction(queueCb)) {
queueCb.call(this, result);
}
});
// isFn(callback) &&
if (typeof callback === 'function') {
if (isFunction(callback)) {
callback.call(this, res);
}
});
......@@ -12677,7 +12677,7 @@ function warpPlusSuccessCallback(resolve, after) {
return function successCallback(data) {
delete data.code;
delete data.message;
if (typeof after === 'function') {
if (isFunction(after)) {
data = after(data);
}
resolve(data);
......@@ -12707,7 +12707,7 @@ function warpPlusEvent(plusObject, event) {
function warpPlusMethod(plusObject, before, after) {
return function (options, { resolve, reject }) {
const object = plusObject();
object(extend({}, typeof before === 'function' ? before(options) : options, {
object(extend({}, isFunction(before) ? before(options) : options, {
success: warpPlusSuccessCallback(resolve, after),
fail: warpPlusErrorCallback(reject),
}));
......@@ -14120,7 +14120,7 @@ const previewImage = defineAsyncApi(API_PREVIEW_IMAGE, ({ current = 0, indicator
plus.nativeUI.actionSheet(options, (e) => {
if (e.index > 0) {
if (hasLongPressActions) {
typeof longPressActions.success === 'function' &&
isFunction(longPressActions.success) &&
longPressActions.success({
tapIndex: e.index - 1,
index: res.index,
......@@ -14134,7 +14134,7 @@ const previewImage = defineAsyncApi(API_PREVIEW_IMAGE, ({ current = 0, indicator
});
}
else if (hasLongPressActions) {
typeof longPressActions.fail === 'function' &&
isFunction(longPressActions.fail) &&
longPressActions.fail({
errMsg: 'showActionSheet:fail cancel',
});
......@@ -14219,7 +14219,7 @@ function onRecorderStateChange(res) {
const state = res.state;
delete res.state;
delete res.errMsg;
if (state && typeof callbacks$1[state] === 'function') {
if (state && isFunction(callbacks$1[state])) {
callbacks$1[state](res);
}
}
......@@ -14500,7 +14500,7 @@ class DownloadTask {
this._downloader.abort();
}
onProgressUpdate(callback) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return;
}
this._callbacks.push(callback);
......@@ -14851,7 +14851,7 @@ class SocketTask {
}
// WYQ fix: App平台修复websocket onOpen时发送数据报错的Bug
this._callbacks[name].forEach((callback) => {
if (typeof callback === 'function') {
if (isFunction(callback)) {
callback(data);
}
});
......@@ -14974,7 +14974,7 @@ class UploadTask {
this._uploader.abort();
}
onProgressUpdate(callback) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return;
}
this._callbacks.push(callback);
......@@ -15293,7 +15293,7 @@ const initInnerAudioContextEventOnce = /*#__PURE__*/ once(() => {
// 批量设置音频上下文事件监听方法
innerAudioContextEventNames.forEach((eventName) => {
InnerAudioContext.prototype[eventName] = function (callback) {
if (typeof callback === 'function') {
if (isFunction(callback)) {
this._callbacks[eventName].push(callback);
}
};
......@@ -15312,7 +15312,7 @@ const initInnerAudioContextEventOnce = /*#__PURE__*/ once(() => {
function emit(audio, state, errMsg, errCode) {
const name = `on${capitalize(state)}`;
audio._callbacks[name].forEach((callback) => {
if (typeof callback === 'function') {
if (isFunction(callback)) {
callback(state === 'error'
? {
errMsg,
......@@ -16879,7 +16879,7 @@ class AdEventHandler {
this._removeEventListener(EventType.error, callback);
}
_addEventListener(type, callback) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return;
}
if (!this._callbacks[type]) {
......
import { extend, isArray } from '@vue/shared'
import { extend, isArray, isFunction } from '@vue/shared'
import { addLeadingSlash, formatLog } from '@dcloudio/uni-shared'
import { getRouteOptions } from '@dcloudio/uni-core'
interface PlusResult extends Record<string, any> {
......@@ -17,7 +17,7 @@ export function warpPlusSuccessCallback(
return function successCallback(data: PlusResult) {
delete data.code
delete data.message
if (typeof after === 'function') {
if (isFunction(after)) {
data = after(data)
}
resolve(data)
......@@ -58,7 +58,7 @@ export function warpPlusMethod(
) {
const object = plusObject()
object(
extend({}, typeof before === 'function' ? before(options) : options, {
extend({}, isFunction(before) ? before(options) : options, {
success: warpPlusSuccessCallback(resolve, after),
fail: warpPlusErrorCallback(reject),
})
......
import { isFunction } from '@vue/shared'
const EventType = {
load: 'load',
close: 'close',
......@@ -42,7 +43,7 @@ class AdEventHandler {
}
_addEventListener(type: string, callback: Function) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return
}
if (!this._callbacks[type]) {
......
import { extend, capitalize } from '@vue/shared'
import { extend, capitalize, isFunction } from '@vue/shared'
import {
API_CREATE_INNER_AUDIO_CONTEXT,
defineSyncApi,
......@@ -436,7 +436,7 @@ const initInnerAudioContextEventOnce = /*#__PURE__*/ once(() => {
// 批量设置音频上下文事件监听方法
innerAudioContextEventNames.forEach((eventName) => {
InnerAudioContext.prototype[eventName] = function (callback: Function) {
if (typeof callback === 'function') {
if (isFunction(callback)) {
this._callbacks[eventName]!.push(callback)
}
}
......@@ -462,7 +462,7 @@ function emit(
) {
const name = `on${capitalize(state)}` as InnerAudioContextEvent
audio._callbacks[name]!.forEach((callback) => {
if (typeof callback === 'function') {
if (isFunction(callback)) {
callback(
state === 'error'
? {
......
import { extend } from '@vue/shared'
import { extend, isFunction } from '@vue/shared'
import {
API_GET_RECORDER_MANAGER,
API_TYPE_GET_RECORDER_MANAGER,
......@@ -98,7 +98,7 @@ function onRecorderStateChange(res: { state?: string; errMsg?: string }) {
const state = res.state
delete res.state
delete res.errMsg
if (state && typeof callbacks[state] === 'function') {
if (state && isFunction(callbacks[state])) {
callbacks[state]!(res)
}
}
......
......@@ -8,7 +8,7 @@ import {
API_TYPE_CLOSE_PREVIEW_IMAGE,
} from '@dcloudio/uni-api'
import { isPlainObject } from '@vue/shared'
import { isFunction, isPlainObject } from '@vue/shared'
import { initI18nPreviewImageMsgsOnce, useI18n } from '@dcloudio/uni-core'
......@@ -67,8 +67,8 @@ export const previewImage = <API_TYPE_PREVIEW_IMAGE>defineAsyncApi(
plus.nativeUI.actionSheet(options, (e) => {
if (e.index > 0) {
if (hasLongPressActions) {
typeof longPressActions!.success === 'function' &&
longPressActions!.success({
isFunction(longPressActions.success) &&
longPressActions.success({
tapIndex: e.index - 1,
index: res.index,
})
......@@ -85,8 +85,8 @@ export const previewImage = <API_TYPE_PREVIEW_IMAGE>defineAsyncApi(
}
)
} else if (hasLongPressActions) {
typeof longPressActions!.fail === 'function' &&
longPressActions!.fail({
isFunction(longPressActions.fail) &&
longPressActions.fail({
errMsg: 'showActionSheet:fail cancel',
})
}
......
import { TEMP_PATH } from '../constants'
import { hasOwn } from '@vue/shared'
import { hasOwn, isFunction } from '@vue/shared'
import {
defineTaskApi,
API_DOWNLOAD_FILE,
......@@ -33,7 +33,7 @@ class DownloadTask implements UniApp.DownloadTask {
this._downloader.abort()
}
onProgressUpdate(callback: (result: any) => void) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return
}
this._callbacks.push(callback)
......
......@@ -15,7 +15,7 @@ import {
} from '@dcloudio/uni-api'
import { requireNativePlugin } from '../plugin/requireNativePlugin'
import { base64ToArrayBuffer, arrayBufferToBase64 } from '@dcloudio/uni-api'
import { extend, capitalize, isArray } from '@vue/shared'
import { extend, capitalize, isArray, isFunction } from '@vue/shared'
import { callOptions } from '@dcloudio/uni-shared'
type Socket = {
......@@ -181,7 +181,7 @@ class SocketTask implements UniApp.SocketTask {
// WYQ fix: App平台修复websocket onOpen时发送数据报错的Bug
this._callbacks[name].forEach((callback) => {
if (typeof callback === 'function') {
if (isFunction(callback)) {
callback(data)
}
})
......
......@@ -5,7 +5,7 @@ import {
UploadFileProtocol,
UploadFileOptions,
} from '@dcloudio/uni-api'
import { hasOwn } from '@vue/shared'
import { hasOwn, isFunction } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
type Uploader = ReturnType<typeof plus.uploader.createUpload>
......@@ -35,7 +35,7 @@ class UploadTask implements UniApp.UploadTask {
}
onProgressUpdate(callback: Function) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return
}
this._callbacks.push(callback)
......
......@@ -9,6 +9,7 @@ import { Plugin } from '../plugin'
import { ResolvedConfig } from '../config'
import { cleanUrl, normalizePath } from '../utils'
import { withSourcemap } from '../../../../vite/utils/utils'
import { isFunction } from '@vue/shared'
export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g
......@@ -190,7 +191,7 @@ export function assetFileNamesToFileName(
const name = basename.slice(0, -extname.length)
const hash = contentHash
if (typeof assetFileNames === 'function') {
if (isFunction(assetFileNames)) {
assetFileNames = assetFileNames({
name: file,
source: content,
......
......@@ -40,7 +40,7 @@ import { transform, formatMessages } from 'esbuild'
import { preCss, preNVueCss } from '../../../../preprocess'
import { PAGES_JSON_JS } from '../../../../constants'
import { emptyCssComments } from '../cleanString'
import { isArray } from '@vue/shared'
import { isArray, isFunction } from '@vue/shared'
// const debug = createDebugger('vite:css')
export interface CSSOptions {
......@@ -530,7 +530,7 @@ async function compileCSS(
outputFileName: string
) {
modules = _modules
if (modulesOptions && typeof modulesOptions.getJSON === 'function') {
if (modulesOptions && isFunction(modulesOptions.getJSON)) {
modulesOptions.getJSON(cssFileName, _modules, outputFileName)
}
},
......@@ -1395,7 +1395,7 @@ async function getSource(
): Promise<{ content: string; map?: ExistingRawSourceMap }> {
if (!additionalData) return { content: source }
if (typeof additionalData === 'function') {
if (isFunction(additionalData)) {
const newContent = await additionalData(source, filename)
if (typeof newContent === 'string') {
return { content: newContent }
......
import { createElementVNode, defineComponent, createVNode, mergeProps, getCurrentInstance, provide, watch, onUnmounted, shallowRef, reactive, watchEffect, ref, inject, onBeforeUnmount, computed, Text as Text$1, isVNode, Fragment, onMounted, resolveComponent, parseClassList } from "vue";
import { extend, hasOwn, isPlainObject, isArray } from "@vue/shared";
import { extend, hasOwn, isFunction, isPlainObject, isArray } from "@vue/shared";
import { cacheStringFunction, PRIMARY_COLOR } from "@dcloudio/uni-shared";
const OPEN_TYPES = [
"navigate",
......@@ -272,7 +272,7 @@ function showPage({
});
page.addEventListener("close", onClose);
addEventListener(pageId, (message) => {
if (typeof onMessage === "function") {
if (isFunction(onMessage)) {
onMessage(message.data);
}
if (!message.keep) {
......@@ -988,7 +988,7 @@ function useTouchtrack(method) {
}
function addListener(type, callback2) {
__event[type] = function($event) {
if (typeof callback2 === "function") {
if (isFunction(callback2)) {
$event.touches = $event.changedTouches;
if (callback2($event) === false) {
$event.stopPropagation();
......
import { isFunction } from '@vue/shared'
import { Friction } from './Friction'
import { Spring } from './Spring'
import { Scroll } from './Scroll'
......@@ -233,7 +234,7 @@ export class Scroller {
this._position = c
this.updatePosition()
}
if (typeof this._options.onSnap === 'function') {
if (isFunction(this._options.onSnap)) {
this._options.onSnap(
Math.floor(Math.abs(this._position) / this._itemSize)
)
......@@ -265,7 +266,7 @@ export class Scroller {
if (this._position !== i) {
this._snapping = true
this.scrollTo(-i)
if (typeof this._options.onSnap === 'function') {
if (isFunction(this._options.onSnap)) {
this._options.onSnap(
Math.floor(Math.abs(this._position) / this._itemSize)
)
......@@ -295,7 +296,7 @@ export class Scroller {
}
dispatchScroll() {
if (
typeof this._options.onScroll === 'function' &&
isFunction(this._options.onScroll) &&
Math.round(Number(this._lastPos)) !== Math.round(this._position)
) {
this._lastPos = this._position
......@@ -342,7 +343,7 @@ export class Scroller {
this.updatePosition()
if (position !== this._position) {
this.dispatchScroll()
if (typeof this._options.onSnap === 'function') {
if (isFunction(this._options.onSnap)) {
this._options.onSnap(
Math.floor(Math.abs(this._position) / this._itemSize)
)
......
......@@ -9,7 +9,7 @@ import {
reactive,
nextTick,
} from 'vue'
import { extend } from '@vue/shared'
import { extend, isFunction } from '@vue/shared'
import { debounce } from '@dcloudio/uni-shared'
import { getCurrentPageId, registerViewMethod } from '@dcloudio/uni-core'
import { throttle } from './throttle'
......@@ -371,10 +371,7 @@ function useEvent(
}
const onInput = function (event: Event, force?: boolean) {
event.stopPropagation()
if (
typeof beforeInput === 'function' &&
beforeInput(event, state) === false
) {
if (isFunction(beforeInput) && beforeInput(event, state) === false) {
return
}
state.value = field.value
......
import { onBeforeUnmount } from 'vue'
import { isFunction } from '@vue/shared'
const addListenerToElement = function (
element: HTMLElement,
......@@ -10,7 +11,7 @@ const addListenerToElement = function (
element.addEventListener(
type,
($event: Event) => {
if (typeof callback === 'function') {
if (isFunction(callback)) {
if (callback($event) === false) {
if (
typeof $event.cancelable !== 'undefined' ? $event.cancelable : true
......
......@@ -26,7 +26,3 @@ export const firstLetterToLowerCase = cached((str: string) => {
export function isDef(v: any) {
return typeof v !== 'undefined'
}
export function isFn(fn: any) {
return typeof fn === 'function'
}
import { isFunction } from '@vue/shared'
type State = 'start' | 'move' | 'end' | 'cancel'
type TouchOrMouseEvent = TouchEvent | MouseEvent
type Detail = {
......@@ -32,7 +33,7 @@ export function useTouchtrack(
}
function addListener(type: CallbackType, callback: Function) {
__event[type] = function ($event: TouchtrackEvent) {
if (typeof callback === 'function') {
if (isFunction(callback)) {
$event.touches = $event.changedTouches
if (callback($event) === false) {
$event.stopPropagation()
......
import { ref, computed, ExtractPropTypes, Ref, onMounted } from 'vue'
import { extend } from '@vue/shared'
import { extend, isFunction } from '@vue/shared'
import type { Actions, OperateCanvasType } from '@dcloudio/uni-api'
import {
useAttrs,
......@@ -698,7 +698,7 @@ function useMethods(
resolve: (res: { callbackId: number; data: any }) => void
) {
let method = methods[type]
if (type.indexOf('_') !== 0 && typeof method === 'function') {
if (type.indexOf('_') !== 0 && isFunction(method)) {
method(data as any, resolve)
}
}
......
import { extend } from '@vue/shared'
import { extend, isFunction } from '@vue/shared'
declare interface BroadcastChannel {
new (id: string): BroadcastChannel
......@@ -157,7 +157,7 @@ export function showPage({
})
page.addEventListener('close', onClose)
addEventListener(pageId, (message) => {
if (typeof onMessage === 'function') {
if (isFunction(onMessage)) {
onMessage(message.data)
}
if (!message.keep) {
......
......@@ -11,6 +11,7 @@ import {
isExternalUrl,
} from '@dcloudio/uni-cli-shared'
import { OutputOptions } from 'rollup'
import { isFunction } from '@vue/shared'
function isCombineBuiltInCss(config: ResolvedConfig) {
return config.command === 'build' && config.build.cssCodeSplit
......@@ -126,7 +127,7 @@ export function assetFileNamesToFileName(
const name = basename.slice(0, -extname.length)
const hash = contentHash
if (typeof assetFileNames === 'function') {
if (isFunction(assetFileNames)) {
assetFileNames = assetFileNames({
name: file,
source: content,
......
......@@ -2107,7 +2107,7 @@ function useMethods(props2, canvasRef, actionsWaiting) {
};
function _handleSubscribe(type, data, resolve) {
let method = methods[type];
if (type.indexOf("_") !== 0 && typeof method === "function") {
if (type.indexOf("_") !== 0 && shared.isFunction(method)) {
method(data, resolve);
}
}
......@@ -3057,7 +3057,7 @@ function useEvent(fieldRef, state, props2, trigger, triggerInput, beforeInput) {
};
const onInput = function(event, force) {
event.stopPropagation();
if (typeof beforeInput === "function" && beforeInput(event, state) === false) {
if (shared.isFunction(beforeInput) && beforeInput(event, state) === false) {
return;
}
state.value = field.value;
......@@ -8164,7 +8164,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({
callout.setPosition(b);
}
const cb = data.animationEnd;
if (typeof cb === "function") {
if (shared.isFunction(cb)) {
cb();
}
});
......
......@@ -4313,11 +4313,11 @@ class SelectorQuery {
convertContext(result);
}
const queueCb = queueCbs[index2];
if (typeof queueCb === "function") {
if (isFunction(queueCb)) {
queueCb.call(this, result);
}
});
if (typeof callback === "function") {
if (isFunction(callback)) {
callback.call(this, res);
}
});
......@@ -7002,7 +7002,7 @@ function useMethods(props2, canvasRef, actionsWaiting) {
};
function _handleSubscribe(type, data, resolve) {
let method = methods[type];
if (type.indexOf("_") !== 0 && typeof method === "function") {
if (type.indexOf("_") !== 0 && isFunction(method)) {
method(data, resolve);
}
}
......@@ -8642,7 +8642,7 @@ function useEvent(fieldRef, state2, props2, trigger, triggerInput, beforeInput)
};
const onInput = function(event, force) {
event.stopPropagation();
if (typeof beforeInput === "function" && beforeInput(event, state2) === false) {
if (isFunction(beforeInput) && beforeInput(event, state2) === false) {
return;
}
state2.value = field.value;
......@@ -9120,7 +9120,7 @@ function useMovableAreaState(props2, rootRef) {
}
const addListenerToElement = function(element, type, callback, capture) {
element.addEventListener(type, ($event) => {
if (typeof callback === "function") {
if (isFunction(callback)) {
if (callback($event) === false) {
if (typeof $event.cancelable !== "undefined" ? $event.cancelable : true) {
$event.preventDefault();
......@@ -10903,7 +10903,7 @@ class Scroller {
this._position = c;
this.updatePosition();
}
if (typeof this._options.onSnap === "function") {
if (isFunction(this._options.onSnap)) {
this._options.onSnap(Math.floor(Math.abs(this._position) / this._itemSize));
}
}
......@@ -10929,7 +10929,7 @@ class Scroller {
if (this._position !== i) {
this._snapping = true;
this.scrollTo(-i);
if (typeof this._options.onSnap === "function") {
if (isFunction(this._options.onSnap)) {
this._options.onSnap(Math.floor(Math.abs(this._position) / this._itemSize));
}
}
......@@ -10956,7 +10956,7 @@ class Scroller {
this._element.addEventListener("transitionend", this._onTransitionEnd);
}
dispatchScroll() {
if (typeof this._options.onScroll === "function" && Math.round(Number(this._lastPos)) !== Math.round(this._position)) {
if (isFunction(this._options.onScroll) && Math.round(Number(this._lastPos)) !== Math.round(this._position)) {
this._lastPos = this._position;
const event = {
target: {
......@@ -10995,7 +10995,7 @@ class Scroller {
this.updatePosition();
if (position !== this._position) {
this.dispatchScroll();
if (typeof this._options.onSnap === "function") {
if (isFunction(this._options.onSnap)) {
this._options.onSnap(Math.floor(Math.abs(this._position) / this._itemSize));
}
}
......@@ -15808,7 +15808,7 @@ var MapMarker = /* @__PURE__ */ defineSystemComponent({
callout.setPosition(b);
}
const cb = data.animationEnd;
if (typeof cb === "function") {
if (isFunction(cb)) {
cb();
}
});
......@@ -16162,7 +16162,7 @@ var MapControl = /* @__PURE__ */ defineSystemComponent({
const initInnerAudioContextEventOnce = /* @__PURE__ */ once(() => {
innerAudioContextEventNames.forEach((eventName) => {
InnerAudioContext.prototype[eventName] = function(callback) {
if (typeof callback === "function") {
if (isFunction(callback)) {
this._events[eventName].push(callback);
}
};
......@@ -16380,7 +16380,7 @@ function getBrowserInfo() {
model = "iPad";
osname = "iOS";
deviceType = "pad";
osversion = typeof window.BigInt === "function" ? "14.0" : "13.0";
osversion = isFunction(window.BigInt) ? "14.0" : "13.0";
} else if (isWindows || isMac || isLinux) {
model = "PC";
osname = "PC";
......@@ -17773,7 +17773,7 @@ class DownloadTask {
this._xhr = xhr;
}
onProgressUpdate(callback) {
if (typeof callback !== "function") {
if (!isFunction(callback)) {
return;
}
this._callbacks.push(callback);
......@@ -17858,7 +17858,7 @@ class UploadTask {
this._xhr = xhr;
}
onProgressUpdate(callback) {
if (typeof callback !== "function") {
if (!isFunction(callback)) {
return;
}
this._callbacks.push(callback);
......@@ -18083,7 +18083,7 @@ const connectSocket = /* @__PURE__ */ defineTaskApi(API_CONNECT_SOCKET, ({ url,
}, ConnectSocketProtocol, ConnectSocketOptions);
function callSocketTask(socketTask, method, option, resolve, reject) {
const fn = socketTask[method];
if (typeof fn === "function") {
if (isFunction(fn)) {
fn.call(socketTask, extend({}, option, {
success() {
resolve();
......@@ -18133,19 +18133,19 @@ function getJSONP(url, options, success, error) {
js.remove();
}
window[callbackName] = (res) => {
if (typeof success === "function") {
if (isFunction(success)) {
success(res);
}
end();
};
js.onerror = () => {
if (typeof error === "function") {
if (isFunction(error)) {
error();
}
end();
};
timing = setTimeout(function() {
if (typeof error === "function") {
if (isFunction(error)) {
error();
}
end();
......
import { isFunction } from '@vue/shared'
interface Options {
callback?: string
timeout?: number
......@@ -20,19 +21,19 @@ export function getJSONP(
js.remove()
}
;(window as any)[callbackName] = (res: any) => {
if (typeof success === 'function') {
if (isFunction(success)) {
success(res)
}
end()
}
js.onerror = () => {
if (typeof error === 'function') {
if (isFunction(error)) {
error()
}
end()
}
timing = setTimeout(function () {
if (typeof error === 'function') {
if (isFunction(error)) {
error()
}
end()
......
import { isFunction } from '@vue/shared'
import {
ua,
isIOS,
......@@ -94,7 +95,7 @@ export function getBrowserInfo() {
model = 'iPad'
osname = 'iOS'
deviceType = 'pad'
osversion = typeof window.BigInt === 'function' ? '14.0' : '13.0'
osversion = isFunction(window.BigInt) ? '14.0' : '13.0'
} else if (isWindows || isMac || isLinux) {
model = 'PC'
osname = 'PC'
......
import { isFunction } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
import {
API_CREATE_INNER_AUDIO_CONTEXT,
......@@ -28,7 +29,7 @@ const initInnerAudioContextEventOnce = /*#__PURE__*/ once(() => {
// 批量设置音频上下文事件监听方法
innerAudioContextEventNames.forEach((eventName) => {
InnerAudioContext.prototype[eventName] = function (callback: Function) {
if (typeof callback === 'function') {
if (isFunction(callback)) {
this._events[eventName]!.push(callback)
}
}
......
import { fileToUrl, getFileName } from '../../../helpers/file'
import { isFunction } from '@vue/shared'
import {
defineTaskApi,
API_DOWNLOAD_FILE,
......@@ -6,6 +6,7 @@ import {
DownloadFileProtocol,
DownloadFileOptions,
} from '@dcloudio/uni-api'
import { fileToUrl, getFileName } from '../../../helpers/file'
/**
* 下载任务
*/
......@@ -21,7 +22,7 @@ class DownloadTask implements UniApp.DownloadTask {
* @param {Function} callback 回调
*/
onProgressUpdate(callback: (result: any) => void) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return
}
this._callbacks.push(callback)
......
import { extend, capitalize } from '@vue/shared'
import { extend, capitalize, isFunction } from '@vue/shared'
import {
defineTaskApi,
defineAsyncApi,
......@@ -185,7 +185,7 @@ function callSocketTask(
reject: Function
) {
const fn = socketTask[method]
if (typeof fn === 'function') {
if (isFunction(fn)) {
fn.call(
socketTask,
extend({}, option, {
......
import { isArray } from '@vue/shared'
import { isArray, isFunction } from '@vue/shared'
import {
defineTaskApi,
......@@ -24,7 +24,7 @@ class UploadTask implements UniApp.UploadTask {
* @param callback 回调
*/
onProgressUpdate(callback: (result: any) => void) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return
}
this._callbacks.push(callback)
......
import { onUnmounted, inject, watch } from 'vue'
import { isFunction } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
import { defineSystemComponent, useCustomEvent } from '@dcloudio/uni-components'
import { Maps, Map, LatLng, Callout, CalloutOptions } from './maps'
......@@ -400,7 +401,7 @@ export default /*#__PURE__*/ defineSystemComponent({
callout.setPosition(b)
}
const cb = data.animationEnd
if (typeof cb === 'function') {
if (isFunction(cb)) {
cb()
}
})
......
......@@ -379,16 +379,16 @@ function callOptions(options, data) {
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
if (shared.isFunction(options.success)) {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
if (shared.isFunction(options.fail)) {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
if (shared.isFunction(options.complete)) {
options.complete(data);
}
}
......@@ -724,7 +724,7 @@ function parseNVueDataset(attr) {
}
function plusReady(callback) {
if (typeof callback !== 'function') {
if (!shared.isFunction(callback)) {
return;
}
if (window.plus) {
......@@ -1203,10 +1203,6 @@ const ACTION_TYPE_EVENT = 20;
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
* @param fn
* @param delay
* @param timer
* @returns
*/
function debounce(fn, delay, { clearTimeout, setTimeout }) {
let timeout;
......
......@@ -131,10 +131,6 @@ export declare const DATA_RE: RegExp;
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
* @param fn
* @param delay
* @param timer
* @returns
*/
export declare function debounce(fn: Function, delay: number, { clearTimeout, setTimeout }: Timer): {
(this: any): void;
......
import { isHTMLTag, isSVGTag, hyphenate, camelize, isString, isPlainObject, extend, isArray, toTypeString, toRawType, capitalize } from '@vue/shared';
import { isHTMLTag, isSVGTag, hyphenate, camelize, isFunction, isString, isPlainObject, extend, isArray, toTypeString, toRawType, capitalize } from '@vue/shared';
const BUILT_IN_TAG_NAMES = [
'ad',
......@@ -375,16 +375,16 @@ function callOptions(options, data) {
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
if (isFunction(options.success)) {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
if (isFunction(options.fail)) {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
if (isFunction(options.complete)) {
options.complete(data);
}
}
......@@ -720,7 +720,7 @@ function parseNVueDataset(attr) {
}
function plusReady(callback) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return;
}
if (window.plus) {
......@@ -1199,10 +1199,6 @@ const ACTION_TYPE_EVENT = 20;
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
* @param fn
* @param delay
* @param timer
* @returns
*/
function debounce(fn, delay, { clearTimeout, setTimeout }) {
let timeout;
......
......@@ -4,10 +4,6 @@ interface Timer {
}
/**
* 需要手动传入 timer,主要是解决 App 平台的定制 timer
* @param fn
* @param delay
* @param timer
* @returns
*/
export function debounce(
fn: Function,
......
import { isFunction } from '@vue/shared'
export function plusReady(callback: () => void) {
if (typeof callback !== 'function') {
if (!isFunction(callback)) {
return
}
if ((window as any).plus) {
......
import { isPlainObject, isString } from '@vue/shared'
import { isFunction, isPlainObject, isString } from '@vue/shared'
export function cache<T>(fn: (str: string) => T) {
const cache: Record<string, T> = Object.create(null)
......@@ -101,15 +101,15 @@ export function callOptions(
}
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
if (isFunction(options.success)) {
options.success(data)
}
} else {
if (typeof options.fail === 'function') {
if (isFunction(options.fail)) {
options.fail(data)
}
}
if (typeof options.complete === 'function') {
if (isFunction(options.complete)) {
options.complete(data)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册