1
0
mirror of https://gitee.com/vant-contrib/vant.git synced 2025-04-06 03:57:59 +08:00

chore: add isPromise utils

This commit is contained in:
陈嘉涵 2020-02-12 10:22:37 +08:00
parent 0ed7aaac88
commit 35260e024a
2 changed files with 7 additions and 3 deletions
src
uploader
utils

@ -1,5 +1,5 @@
// Utils // Utils
import { createNamespace, addUnit, noop } from '../utils'; import { createNamespace, addUnit, noop, isPromise } from '../utils';
import { toArray, readFile, isOversize, isImageFile } from './utils'; import { toArray, readFile, isOversize, isImageFile } from './utils';
// Mixins // Mixins
@ -107,7 +107,7 @@ export default createComponent({
return; return;
} }
if (response.then) { if (isPromise(response)) {
response response
.then(() => { .then(() => {
this.readFile(files); this.readFile(files);
@ -182,7 +182,7 @@ export default createComponent({
return; return;
} }
if (response.then) { if (isPromise(response)) {
response response
.then(() => { .then(() => {
this.deleteFile(file, index); this.deleteFile(file, index);

@ -19,6 +19,10 @@ export function isObject(val: any): val is Record<any, any> {
return val !== null && typeof val === 'object'; return val !== null && typeof val === 'object';
} }
export function isPromise<T = any>(val: unknown): val is Promise<T> {
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
}
export function get(object: any, path: string): any { export function get(object: any, path: string): any {
const keys = path.split('.'); const keys = path.split('.');
let result = object; let result = object;