Skip to content

Commit

Permalink
chore(helpers) drop custom createDeferred() for Promise.withResolvers()
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Jan 10, 2025
1 parent 62d1ee6 commit 7504766
Show file tree
Hide file tree
Showing 11 changed files with 1,437 additions and 551 deletions.
1,931 changes: 1,423 additions & 508 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"optional-require": "1.0.3",
"pixelmatch": "5.3.0",
"promise.allsettled": "1.0.4",
"promise.withresolvers": "1.0.3",
"punycode": "2.3.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
6 changes: 2 additions & 4 deletions react/features/app/components/AbstractApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ export interface IProps {
*/
export class AbstractApp<P extends IProps = IProps> extends BaseApp<P> {
/**
* The deferred for the initialisation {{promise, resolve, reject}}.
* The deferred for the initialization {{promise, resolve, reject}}.
*/
_init: {
promise: Promise<any>;
};
_init: PromiseWithResolvers<any>;

/**
* Initializes the app.
Expand Down
7 changes: 2 additions & 5 deletions react/features/base/app/components/BaseApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import PersistenceRegistry from '../../redux/PersistenceRegistry';
import ReducerRegistry from '../../redux/ReducerRegistry';
import StateListenerRegistry from '../../redux/StateListenerRegistry';
import SoundCollection from '../../sounds/components/SoundCollection';
import { createDeferred } from '../../util/helpers';
import { appWillMount, appWillUnmount } from '../actions';
import logger from '../logger';

Expand Down Expand Up @@ -46,9 +45,7 @@ export default class BaseApp<P> extends Component<P, IState> {
/**
* The deferred for the initialisation {{promise, resolve, reject}}.
*/
_init: {
promise: Promise<any>;
};
_init: PromiseWithResolvers<any>

/**
* Initializes a new {@code BaseApp} instance.
Expand Down Expand Up @@ -79,7 +76,7 @@ export default class BaseApp<P> extends Component<P, IState> {
* @see {@link #_initStorage}
* @type {Promise}
*/
this._init = createDeferred<void>();
this._init = Promise.withResolvers();

try {
await this._initStorage();
Expand Down
7 changes: 3 additions & 4 deletions react/features/base/media/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AnyAction, combineReducers } from 'redux';
import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../conference/actionTypes';
import ReducerRegistry from '../redux/ReducerRegistry';
import { TRACK_REMOVED } from '../tracks/actionTypes';
import { DefferedPromise, createDeferred } from '../util/helpers';

import {
GUM_PENDING,
Expand Down Expand Up @@ -93,7 +92,7 @@ function _audio(state: IAudioState = _AUDIO_INITIAL_MEDIA_STATE, action: AnyActi
// initial track creation haven't been started we would wait for it to finish before starting to join the room.
// NOTE: The previous implementation was using the GUM promise from conference.init. But it turned out that connect
// may finish even before conference.init is executed.
const DEFAULT_INITIAL_PROMISE_STATE = createDeferred<IInitialGUMPromiseResult>();
const DEFAULT_INITIAL_PROMISE_STATE = Promise.withResolvers<IInitialGUMPromiseResult>();

/**
* Reducer for the common properties in media state.
Expand All @@ -103,7 +102,7 @@ const DEFAULT_INITIAL_PROMISE_STATE = createDeferred<IInitialGUMPromiseResult>()
* @param {string} action.type - Type of action.
* @returns {ICommonState}
*/
function _initialGUMPromise(state: DefferedPromise<IInitialGUMPromiseResult> | null = DEFAULT_INITIAL_PROMISE_STATE,
function _initialGUMPromise(state: PromiseWithResolvers<IInitialGUMPromiseResult> | null = DEFAULT_INITIAL_PROMISE_STATE,
action: AnyAction) {
if (action.type === SET_INITIAL_GUM_PROMISE) {
return action.promise ?? null;
Expand Down Expand Up @@ -294,7 +293,7 @@ interface IVideoState {

export interface IMediaState {
audio: IAudioState;
initialGUMPromise: DefferedPromise<IInitialGUMPromiseResult> | null;
initialGUMPromise: PromiseWithResolvers<IInitialGUMPromiseResult> | null;
screenshare: IScreenshareState;
video: IVideoState;
}
Expand Down
3 changes: 1 addition & 2 deletions react/features/base/participants/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import i18next from '../i18n/i18next';
import { MEDIA_TYPE, MediaType, VIDEO_TYPE } from '../media/constants';
import { toState } from '../redux/functions';
import { getScreenShareTrack, isLocalTrackMuted } from '../tracks/functions.any';
import { createDeferred } from '../util/helpers';

import {
JIGASI_PARTICIPANT_ICON,
Expand Down Expand Up @@ -127,7 +126,7 @@ export function getActiveSpeakersToBeDisplayed(stateful: IStateful) {
* @returns {Promise}
*/
export function getFirstLoadableAvatarUrl(participant: IParticipant, store: IStore) {
const deferred: any = createDeferred();
const deferred: any = Promise.withResolvers();
const fullPromise = deferred.promise
.then(() => _getFirstLoadableAvatarUrl(participant, store))
.then((result: any) => {
Expand Down
21 changes: 0 additions & 21 deletions react/features/base/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,6 @@ export function assignIfDefined(target: Object, source: Object) {
return to;
}

export type DefferedPromise<T> = {
promise: Promise<T>;
reject: (reason?: any) => void;
resolve: (value: T) => void;
};

/**
* Creates a deferred object.
*
* @returns {{promise, resolve, reject}}
*/
export function createDeferred<T>() {
const deferred = {} as DefferedPromise<T>;

deferred.promise = new Promise<T>((resolve, reject) => {
deferred.resolve = resolve;
deferred.reject = reject;
});

return deferred;
}

const MATCH_OPERATOR_REGEXP = /[|\\{}()[\]^$+*?.-]/g;

Expand Down
7 changes: 2 additions & 5 deletions react/features/calendar-sync/web/microsoftCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { v4 as uuidV4 } from 'uuid';
import { findWindows } from 'windows-iana';
import { IanaName } from 'windows-iana/dist/enums';

// @ts-expect-error
import { createDeferred } from '../../../../modules/util/helpers';
import { IStore } from '../../app/types';
import { parseURLParams } from '../../base/util/parseURLParams';
import { parseStandardURIString } from '../../base/util/uri';
Expand Down Expand Up @@ -153,8 +151,7 @@ export const microsoftCalendarApi = {
return Promise.reject('Sign in already in progress.');
}

const signInDeferred = createDeferred();

const signInDeferred = Promise.withResolvers();
const guids = {
authState: uuidV4(),
authNonce: uuidV4()
Expand Down Expand Up @@ -229,7 +226,7 @@ export const microsoftCalendarApi = {
userSigninName: tokenParts.userSigninName
}));

signInDeferred.resolve();
signInDeferred.resolve(undefined);
}

window.addEventListener('message', handleAuth);
Expand Down
1 change: 1 addition & 0 deletions react/features/mobile/polyfills/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BackgroundTimer from 'react-native-background-timer';
import { TextDecoder, TextEncoder } from 'text-encoding';

import 'promise.allsettled/auto'; // Promise.allSettled.
import 'promise.withresolvers/auto'; // Promise.withResolvers.
import 'react-native-url-polyfill/auto'; // Complete URL polyfill.

import Storage from './Storage';
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.native.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"allowSyntheticDefaultImports": true,
"target": "es2020",
"jsx": "react-native",
"lib": [ "es2020"],
"lib": [ "ES2020", "ES2024.Promise" ],
"types": [ "react-native" ],
"skipLibCheck": true,
"moduleResolution": "Node",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"module": "es2020",
"target": "es2020",
"jsx": "react",
"lib": [ "ES2020", "DOM" ],
"lib": [ "ES2020", "ES2024.Promise", "DOM" ],
"skipLibCheck": true,
"moduleResolution": "Node",
"strict": true,
Expand Down

0 comments on commit 7504766

Please sign in to comment.