ソースを参照

chore(helpers) drop custom createDeferred() for Promise.withResolvers()

factor2
Saúl Ibarra Corretgé 11ヶ月前
コミット
5bb3ba71d0

+ 1423
- 508
package-lock.json
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 1
- 0
package.json ファイルの表示

@@ -76,6 +76,7 @@
76 76
     "optional-require": "1.0.3",
77 77
     "pixelmatch": "5.3.0",
78 78
     "promise.allsettled": "1.0.4",
79
+    "promise.withresolvers": "1.0.3",
79 80
     "punycode": "2.3.0",
80 81
     "react": "18.2.0",
81 82
     "react-dom": "18.2.0",

+ 2
- 4
react/features/app/components/AbstractApp.ts ファイルの表示

@@ -27,11 +27,9 @@ export interface IProps {
27 27
  */
28 28
 export class AbstractApp<P extends IProps = IProps> extends BaseApp<P> {
29 29
     /**
30
-     * The deferred for the initialisation {{promise, resolve, reject}}.
30
+     * The deferred for the initialization {{promise, resolve, reject}}.
31 31
      */
32
-    _init: {
33
-        promise: Promise<any>;
34
-    };
32
+    _init: PromiseWithResolvers<any>;
35 33
 
36 34
     /**
37 35
      * Initializes the app.

+ 2
- 5
react/features/base/app/components/BaseApp.tsx ファイルの表示

@@ -14,7 +14,6 @@ import PersistenceRegistry from '../../redux/PersistenceRegistry';
14 14
 import ReducerRegistry from '../../redux/ReducerRegistry';
15 15
 import StateListenerRegistry from '../../redux/StateListenerRegistry';
16 16
 import SoundCollection from '../../sounds/components/SoundCollection';
17
-import { createDeferred } from '../../util/helpers';
18 17
 import { appWillMount, appWillUnmount } from '../actions';
19 18
 import logger from '../logger';
20 19
 
@@ -46,9 +45,7 @@ export default class BaseApp<P> extends Component<P, IState> {
46 45
     /**
47 46
      * The deferred for the initialisation {{promise, resolve, reject}}.
48 47
      */
49
-    _init: {
50
-        promise: Promise<any>;
51
-    };
48
+    _init: PromiseWithResolvers<any>
52 49
 
53 50
     /**
54 51
      * Initializes a new {@code BaseApp} instance.
@@ -79,7 +76,7 @@ export default class BaseApp<P> extends Component<P, IState> {
79 76
          * @see {@link #_initStorage}
80 77
          * @type {Promise}
81 78
          */
82
-        this._init = createDeferred<void>();
79
+        this._init = Promise.withResolvers();
83 80
 
84 81
         try {
85 82
             await this._initStorage();

+ 3
- 4
react/features/base/media/reducer.ts ファイルの表示

@@ -3,7 +3,6 @@ import { AnyAction, combineReducers } from 'redux';
3 3
 import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../conference/actionTypes';
4 4
 import ReducerRegistry from '../redux/ReducerRegistry';
5 5
 import { TRACK_REMOVED } from '../tracks/actionTypes';
6
-import { DefferedPromise, createDeferred } from '../util/helpers';
7 6
 
8 7
 import {
9 8
     GUM_PENDING,
@@ -93,7 +92,7 @@ function _audio(state: IAudioState = _AUDIO_INITIAL_MEDIA_STATE, action: AnyActi
93 92
 // initial track creation haven't been started we would wait for it to finish before starting to join the room.
94 93
 // NOTE: The previous implementation was using the GUM promise from conference.init. But it turned out that connect
95 94
 // may finish even before conference.init is executed.
96
-const DEFAULT_INITIAL_PROMISE_STATE = createDeferred<IInitialGUMPromiseResult>();
95
+const DEFAULT_INITIAL_PROMISE_STATE = Promise.withResolvers<IInitialGUMPromiseResult>();
97 96
 
98 97
 /**
99 98
  * Reducer for the common properties in media state.
@@ -103,7 +102,7 @@ const DEFAULT_INITIAL_PROMISE_STATE = createDeferred<IInitialGUMPromiseResult>()
103 102
  * @param {string} action.type - Type of action.
104 103
  * @returns {ICommonState}
105 104
  */
106
-function _initialGUMPromise(state: DefferedPromise<IInitialGUMPromiseResult> | null = DEFAULT_INITIAL_PROMISE_STATE,
105
+function _initialGUMPromise(state: PromiseWithResolvers<IInitialGUMPromiseResult> | null = DEFAULT_INITIAL_PROMISE_STATE,
107 106
         action: AnyAction) {
108 107
     if (action.type === SET_INITIAL_GUM_PROMISE) {
109 108
         return action.promise ?? null;
@@ -294,7 +293,7 @@ interface IVideoState {
294 293
 
295 294
 export interface IMediaState {
296 295
     audio: IAudioState;
297
-    initialGUMPromise: DefferedPromise<IInitialGUMPromiseResult> | null;
296
+    initialGUMPromise: PromiseWithResolvers<IInitialGUMPromiseResult> | null;
298 297
     screenshare: IScreenshareState;
299 298
     video: IVideoState;
300 299
 }

+ 1
- 2
react/features/base/participants/functions.ts ファイルの表示

@@ -15,7 +15,6 @@ import i18next from '../i18n/i18next';
15 15
 import { MEDIA_TYPE, MediaType, VIDEO_TYPE } from '../media/constants';
16 16
 import { toState } from '../redux/functions';
17 17
 import { getScreenShareTrack, isLocalTrackMuted } from '../tracks/functions.any';
18
-import { createDeferred } from '../util/helpers';
19 18
 
20 19
 import {
21 20
     JIGASI_PARTICIPANT_ICON,
@@ -127,7 +126,7 @@ export function getActiveSpeakersToBeDisplayed(stateful: IStateful) {
127 126
  * @returns {Promise}
128 127
  */
129 128
 export function getFirstLoadableAvatarUrl(participant: IParticipant, store: IStore) {
130
-    const deferred: any = createDeferred();
129
+    const deferred: any = Promise.withResolvers();
131 130
     const fullPromise = deferred.promise
132 131
         .then(() => _getFirstLoadableAvatarUrl(participant, store))
133 132
         .then((result: any) => {

+ 0
- 21
react/features/base/util/helpers.ts ファイルの表示

@@ -22,27 +22,6 @@ export function assignIfDefined(target: Object, source: Object) {
22 22
     return to;
23 23
 }
24 24
 
25
-export type DefferedPromise<T> = {
26
-    promise: Promise<T>;
27
-    reject: (reason?: any) => void;
28
-    resolve: (value: T) => void;
29
-};
30
-
31
-/**
32
- * Creates a deferred object.
33
- *
34
- * @returns {{promise, resolve, reject}}
35
- */
36
-export function createDeferred<T>() {
37
-    const deferred = {} as DefferedPromise<T>;
38
-
39
-    deferred.promise = new Promise<T>((resolve, reject) => {
40
-        deferred.resolve = resolve;
41
-        deferred.reject = reject;
42
-    });
43
-
44
-    return deferred;
45
-}
46 25
 
47 26
 const MATCH_OPERATOR_REGEXP = /[|\\{}()[\]^$+*?.-]/g;
48 27
 

+ 2
- 5
react/features/calendar-sync/web/microsoftCalendar.ts ファイルの表示

@@ -5,8 +5,6 @@ import { v4 as uuidV4 } from 'uuid';
5 5
 import { findWindows } from 'windows-iana';
6 6
 import { IanaName } from 'windows-iana/dist/enums';
7 7
 
8
-// @ts-expect-error
9
-import { createDeferred } from '../../../../modules/util/helpers';
10 8
 import { IStore } from '../../app/types';
11 9
 import { parseURLParams } from '../../base/util/parseURLParams';
12 10
 import { parseStandardURIString } from '../../base/util/uri';
@@ -153,8 +151,7 @@ export const microsoftCalendarApi = {
153 151
                 return Promise.reject('Sign in already in progress.');
154 152
             }
155 153
 
156
-            const signInDeferred = createDeferred();
157
-
154
+            const signInDeferred = Promise.withResolvers();
158 155
             const guids = {
159 156
                 authState: uuidV4(),
160 157
                 authNonce: uuidV4()
@@ -229,7 +226,7 @@ export const microsoftCalendarApi = {
229 226
                     userSigninName: tokenParts.userSigninName
230 227
                 }));
231 228
 
232
-                signInDeferred.resolve();
229
+                signInDeferred.resolve(undefined);
233 230
             }
234 231
 
235 232
             window.addEventListener('message', handleAuth);

+ 1
- 0
react/features/mobile/polyfills/browser.js ファイルの表示

@@ -5,6 +5,7 @@ import BackgroundTimer from 'react-native-background-timer';
5 5
 import { TextDecoder, TextEncoder } from 'text-encoding';
6 6
 
7 7
 import 'promise.allsettled/auto'; // Promise.allSettled.
8
+import 'promise.withresolvers/auto'; // Promise.withResolvers.
8 9
 import 'react-native-url-polyfill/auto'; // Complete URL polyfill.
9 10
 
10 11
 import Storage from './Storage';

+ 1
- 1
tsconfig.native.json ファイルの表示

@@ -4,7 +4,7 @@
4 4
         "allowSyntheticDefaultImports": true,
5 5
         "target": "es2020",
6 6
         "jsx": "react-native",
7
-        "lib": [ "es2020"],
7
+        "lib": [ "ES2020", "ES2024.Promise" ],
8 8
         "types": [ "react-native" ],
9 9
         "skipLibCheck": true,
10 10
         "moduleResolution": "Node",

+ 1
- 1
tsconfig.web.json ファイルの表示

@@ -5,7 +5,7 @@
5 5
         "module": "es2020",
6 6
         "target": "es2020",
7 7
         "jsx": "react",
8
-        "lib": [ "ES2020", "DOM" ],
8
+        "lib": [ "ES2020", "ES2024.Promise", "DOM" ],
9 9
         "skipLibCheck": true,
10 10
         "moduleResolution": "Node",
11 11
         "strict": true,

読み込み中…
キャンセル
保存