Skip to content

Commit 4409667

Browse files
authored
fix: promise type (#361)
1 parent b6d476b commit 4409667

File tree

17 files changed

+73
-67
lines changed

17 files changed

+73
-67
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"beforeEach": false
3636
},
3737
"rules": {
38+
"arco-mobile/promise-with-polyfill": 0,
3839
"linebreak-style": ["error", "unix"],
3940
"no-console": ["error", { "allow": ["warn", "error"] }],
4041
"no-case-declarations": 0,

packages/arcodesign/components/action-sheet/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Ref, ReactNode, CSSProperties } from 'react';
22
import React, { useRef, forwardRef, useImperativeHandle } from 'react';
33
import { cls, componentWrapper } from '@arco-design/mobile-utils';
4-
import type { Promise } from 'es6-promise';
54
import { ContextLayout, CompWithGlobalContext } from '../context-provider';
65
import type { PopupProps, PopupRef } from '../popup';
76
import Popup from '../popup';

packages/arcodesign/components/dialog/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Ref, ReactNode } from 'react';
22
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
33
import type { ILocale } from '@arco-design/mobile-utils';
44
import { cls, componentWrapper } from '@arco-design/mobile-utils';
5-
import type { Promise } from 'es6-promise';
65
import { ContextLayout, CompWithGlobalContext } from '../context-provider';
76
import type { MaskingCommonProps, MaskingRef, OpenBaseProps } from '../masking';
87
import Masking from '../masking';

packages/arcodesign/components/form/form-item.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,34 @@
22
import React, {
33
forwardRef,
44
PureComponent,
5-
ReactNode,
6-
Ref,
75
useContext,
86
useImperativeHandle,
97
useRef,
108
useState,
119
} from 'react';
12-
import { cls, Validator, ValidatorType, ValidatorError } from '@arco-design/mobile-utils';
13-
import { Promise } from 'es6-promise';
10+
import type { ReactNode, Ref } from 'react';
11+
import { cls, Validator, ValidatorType } from '@arco-design/mobile-utils';
12+
import type { ValidatorError } from '@arco-design/mobile-utils';
13+
import { Promise as ES6Promise } from 'es6-promise';
1414
import { FormItemContext } from './form-item-context';
1515
import { GlobalContext } from '../context-provider';
16-
import {
16+
import type {
1717
IFieldError,
1818
FieldValue,
1919
IFormItemInnerProps,
2020
FormItemProps,
2121
ValidateStatus,
2222
FormItemRef,
23-
FormInternalComponentType,
24-
ValueChangeType,
2523
IFormItemContext,
2624
} from './type';
25+
import { ValueChangeType, FormInternalComponentType } from './type';
2726
import { getDefaultValueForInterComponent, getErrorAndWarnings, isFieldRequired } from './utils';
2827
import { DefaultDatePickerLinkedContainer, DefaultPickerLinkedContainer } from './linked-container';
29-
import { BasicInputProps } from '../input/props';
30-
import { DatePickerProps } from '../date-picker/type';
31-
import { PickerProps } from '../picker/type';
32-
import { SwitchProps } from '../switch';
33-
import { ImagePickerProps } from '../image-picker/type';
28+
import type { BasicInputProps } from '../input/props';
29+
import type { DatePickerProps } from '../date-picker/type';
30+
import type { PickerProps } from '../picker/type';
31+
import type { SwitchProps } from '../switch';
32+
import type { ImagePickerProps } from '../image-picker/type';
3433

3534
interface IFormItemInnerState {
3635
validateStatus: ValidateStatus;
@@ -133,7 +132,7 @@ class FormItemInner extends PureComponent<IFormItemInnerProps, IFormItemInnerSta
133132
if (curRules?.length && field) {
134133
const fieldDom = this.props.getFormItemRef();
135134
const fieldValidator = new Validator({ [field]: curRules }, { validateMessages });
136-
return new Promise(resolve => {
135+
return new ES6Promise<IFieldError>(resolve => {
137136
fieldValidator.validate(
138137
{ [field]: value },
139138
(errorsMap: Record<string, ValidatorError[]>) => {
@@ -146,7 +145,7 @@ class FormItemInner extends PureComponent<IFormItemInnerProps, IFormItemInnerSta
146145
warnings,
147146
errorTypes,
148147
});
149-
return resolve({
148+
resolve({
150149
errors: this._errors,
151150
warnings,
152151
value,
@@ -155,9 +154,15 @@ class FormItemInner extends PureComponent<IFormItemInnerProps, IFormItemInnerSta
155154
});
156155
},
157156
);
158-
});
157+
}) as Promise<IFieldError>;
159158
}
160-
return Promise.resolve({ errors: [], warnings: [], value, field, dom: null });
159+
return ES6Promise.resolve<IFieldError>({
160+
errors: [],
161+
warnings: [],
162+
value,
163+
field,
164+
dom: null,
165+
}) as Promise<IFieldError>;
161166
};
162167

163168
setFieldData = (value: FieldValue) => {

packages/arcodesign/components/form/type.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { IRules } from '@arco-design/mobile-utils';
2-
import { ReactElement, ReactNode } from 'react';
3-
import { Promise } from 'es6-promise';
1+
import type { IRules } from '@arco-design/mobile-utils';
2+
import type { ReactElement, ReactNode } from 'react';
43

54
export type FieldValue = any;
65
export type FieldItem = Record<string, FieldValue>;

packages/arcodesign/components/form/useForm.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/* eslint-disable no-console */
2-
import { ReactNode, useRef } from 'react';
3-
import { Promise } from 'es6-promise';
4-
import {
2+
import type { ReactNode } from 'react';
3+
import { useRef } from 'react';
4+
import { Promise as ES6Promise } from 'es6-promise';
5+
import type {
56
Callbacks,
67
IFieldError,
78
FieldItem,
89
IFormInstance,
910
FieldValue,
1011
InternalFormInstance,
11-
ValueChangeType,
1212
} from './type';
13+
import { ValueChangeType } from './type';
1314
import { deepClone } from './utils';
1415

1516
const defaultFunc: any = () => {};
@@ -239,8 +240,8 @@ class FormData {
239240
const promise = entity.validateField();
240241
promiseList.push(promise.then(errors => errors));
241242
});
242-
const summaryPromise: Promise<IFieldError[]> = new Promise((resolve, reject) => {
243-
Promise.all(promiseList).then(res => {
243+
const summaryPromise = new ES6Promise<IFieldError[]>((resolve, reject) => {
244+
ES6Promise.all<IFieldError>(promiseList).then((res: IFieldError[]) => {
244245
const errorResults = res.filter(item => item?.errors?.length);
245246

246247
if (errorResults.length) {
@@ -249,7 +250,7 @@ class FormData {
249250
resolve(res);
250251
}
251252
});
252-
});
253+
}) as Promise<IFieldError[]>;
253254
return summaryPromise;
254255
};
255256

packages/arcodesign/components/pull-refresh/android-pull-refresh.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React, {
22
useRef,
33
forwardRef,
4-
Ref,
54
useCallback,
65
useMemo,
76
useContext,
87
useEffect,
98
useImperativeHandle,
109
} from 'react';
10+
import type { Ref } from 'react';
1111
import { cls, nextTick, defaultLocale } from '@arco-design/mobile-utils';
12-
import { Promise } from 'es6-promise';
12+
import { Promise as ES6Promise } from 'es6-promise';
1313
import Loading from '../loading';
1414
import { GlobalContext } from '../context-provider';
15-
import { PullRefreshRef, PullRefreshStatus, PullRefreshBasicProps } from './model';
15+
import type { PullRefreshRef, PullRefreshBasicProps } from './model';
16+
import { PullRefreshStatus } from './model';
1617
import { useCommonState, useAddScrollEvents, useCheckAsStart } from './hooks';
1718
import { setStyleWithVendor } from '../_helpers';
1819

@@ -139,7 +140,7 @@ export const PullRefresh = forwardRef((props: PullRefreshBasicProps, ref: Ref<Pu
139140
);
140141

141142
const refresh = () =>
142-
new Promise<void>(resolve => {
143+
new ES6Promise<void>(resolve => {
143144
setStatus(PullRefreshStatus.Loading);
144145
nextTick(() => {
145146
scroll(tipsHeight, 300);
@@ -154,7 +155,7 @@ export const PullRefresh = forwardRef((props: PullRefreshBasicProps, ref: Ref<Pu
154155
}
155156
});
156157
});
157-
});
158+
}) as Promise<void>;
158159
const handleTouchEnd = useCallback(() => {
159160
if (currentTranslateYRef.current === 0 && !ifShouldHandle()) {
160161
return;

packages/arcodesign/components/pull-refresh/hooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useRef, useMemo, useEffect, useCallback } from 'react';
22
import type { RefObject } from 'react';
3-
import { Promise } from 'es6-promise';
3+
import { Promise as ES6Promise } from 'es6-promise';
44
import { PullRefreshStatus } from './model';
55

66
export const useCommonState = ({
@@ -30,9 +30,9 @@ export const useCommonState = ({
3030
loadingRef.current = true;
3131
// 避免动画过快,最短加载时间
3232
// @en Minimum load time, avoid animation too fast
33-
return Promise.all([
33+
return ES6Promise.all([
3434
onRefresh?.(),
35-
new Promise(resolve => {
35+
new ES6Promise(resolve => {
3636
// 最少加载一秒
3737
// @en Load at least one second
3838
setTimeout(() => {

packages/arcodesign/components/pull-refresh/ios-pull-refresh.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import React, {
22
useState,
33
useRef,
44
forwardRef,
5-
Ref,
65
useCallback,
76
useContext,
87
useEffect,
98
useMemo,
109
useImperativeHandle,
1110
} from 'react';
12-
import type { CSSProperties } from 'react';
11+
import type { CSSProperties, Ref } from 'react';
1312
import { cls, defaultLocale } from '@arco-design/mobile-utils';
13+
import { Promise as ES6Promise } from 'es6-promise';
1414
import Loading from '../loading';
1515
import { GlobalContext } from '../context-provider';
16-
import { PullRefreshRef, PullRefreshStatus, PullRefreshBasicProps } from './model';
16+
import type { PullRefreshRef, PullRefreshBasicProps } from './model';
17+
import { PullRefreshStatus } from './model';
1718
import { useCommonState, useAddScrollEvents, useCheckAsStart } from './hooks';
1819
import { useListenResize } from '../_helpers';
1920

@@ -125,7 +126,7 @@ export const PullRefresh = forwardRef((props: PullRefreshBasicProps, ref: Ref<Pu
125126
}, [disabled, ifShouldHandle]);
126127

127128
const refresh = () =>
128-
new Promise<void>(resolve => {
129+
new ES6Promise<void>(resolve => {
129130
if (domRef.current) {
130131
domRef.current.style.overflow = 'hidden';
131132
const animationKey = new Date().getTime();
@@ -148,7 +149,7 @@ export const PullRefresh = forwardRef((props: PullRefreshBasicProps, ref: Ref<Pu
148149
}
149150
});
150151
}
151-
});
152+
}) as Promise<void>;
152153

153154
const handleTouchEnd = useCallback(() => {
154155
if (disabled || loadingRef.current || !domRef.current) return;

packages/arcodesign/components/pull-refresh/model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { CSSProperties, ReactNode } from 'react';
2-
import { Promise } from 'es6-promise';
32

43
export interface PullRefreshRef {
54
/**

0 commit comments

Comments
 (0)