From 35260e024aded69c1df992af8be6f255f9278147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Wed, 12 Feb 2020 10:22:37 +0800 Subject: [PATCH] chore: add isPromise utils --- src/uploader/index.js | 6 +++--- src/utils/index.ts | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uploader/index.js b/src/uploader/index.js index 410a2c75e..eeaf7fce4 100644 --- a/src/uploader/index.js +++ b/src/uploader/index.js @@ -1,5 +1,5 @@ // Utils -import { createNamespace, addUnit, noop } from '../utils'; +import { createNamespace, addUnit, noop, isPromise } from '../utils'; import { toArray, readFile, isOversize, isImageFile } from './utils'; // Mixins @@ -107,7 +107,7 @@ export default createComponent({ return; } - if (response.then) { + if (isPromise(response)) { response .then(() => { this.readFile(files); @@ -182,7 +182,7 @@ export default createComponent({ return; } - if (response.then) { + if (isPromise(response)) { response .then(() => { this.deleteFile(file, index); diff --git a/src/utils/index.ts b/src/utils/index.ts index c78525d6a..0186eda41 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -19,6 +19,10 @@ export function isObject(val: any): val is Record { return val !== null && typeof val === 'object'; } +export function isPromise(val: unknown): val is Promise { + return isObject(val) && isFunction(val.then) && isFunction(val.catch); +} + export function get(object: any, path: string): any { const keys = path.split('.'); let result = object;