Browse Source

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

factor2
Saúl Ibarra Corretgé 11 months ago
parent
commit
5bb3ba71d0

+ 1423
- 508
package-lock.json
File diff suppressed because it is too large
View File


+ 1
- 0
package.json View File

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

+ 2
- 4
react/features/app/components/AbstractApp.ts View File

27
  */
27
  */
28
 export class AbstractApp<P extends IProps = IProps> extends BaseApp<P> {
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
      * Initializes the app.
35
      * Initializes the app.

+ 2
- 5
react/features/base/app/components/BaseApp.tsx View File

14
 import ReducerRegistry from '../../redux/ReducerRegistry';
14
 import ReducerRegistry from '../../redux/ReducerRegistry';
15
 import StateListenerRegistry from '../../redux/StateListenerRegistry';
15
 import StateListenerRegistry from '../../redux/StateListenerRegistry';
16
 import SoundCollection from '../../sounds/components/SoundCollection';
16
 import SoundCollection from '../../sounds/components/SoundCollection';
17
-import { createDeferred } from '../../util/helpers';
18
 import { appWillMount, appWillUnmount } from '../actions';
17
 import { appWillMount, appWillUnmount } from '../actions';
19
 import logger from '../logger';
18
 import logger from '../logger';
20
 
19
 
46
     /**
45
     /**
47
      * The deferred for the initialisation {{promise, resolve, reject}}.
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
      * Initializes a new {@code BaseApp} instance.
51
      * Initializes a new {@code BaseApp} instance.
79
          * @see {@link #_initStorage}
76
          * @see {@link #_initStorage}
80
          * @type {Promise}
77
          * @type {Promise}
81
          */
78
          */
82
-        this._init = createDeferred<void>();
79
+        this._init = Promise.withResolvers();
83
 
80
 
84
         try {
81
         try {
85
             await this._initStorage();
82
             await this._initStorage();

+ 3
- 4
react/features/base/media/reducer.ts View File

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

+ 1
- 2
react/features/base/participants/functions.ts View File

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

+ 0
- 21
react/features/base/util/helpers.ts View File

22
     return to;
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
 const MATCH_OPERATOR_REGEXP = /[|\\{}()[\]^$+*?.-]/g;
26
 const MATCH_OPERATOR_REGEXP = /[|\\{}()[\]^$+*?.-]/g;
48
 
27
 

+ 2
- 5
react/features/calendar-sync/web/microsoftCalendar.ts View File

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

+ 1
- 0
react/features/mobile/polyfills/browser.js View File

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

+ 1
- 1
tsconfig.native.json View File

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

+ 1
- 1
tsconfig.web.json View File

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

Loading…
Cancel
Save