Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,853 changes: 2,614 additions & 1,239 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 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 Expand Up @@ -161,8 +162,8 @@
"@types/w3c-image-capture": "1.0.6",
"@types/w3c-web-hid": "1.0.3",
"@types/zxcvbn": "4.4.1",
"@typescript-eslint/eslint-plugin": "5.59.5",
"@typescript-eslint/parser": "5.59.5",
"@typescript-eslint/eslint-plugin": "8.19.1",
"@typescript-eslint/parser": "8.19.1",
"@wdio/allure-reporter": "9.4.3",
"@wdio/cli": "9.4.3",
"@wdio/globals": "9.4.3",
Expand All @@ -174,12 +175,12 @@
"circular-dependency-plugin": "5.2.0",
"clean-css-cli": "4.3.0",
"css-loader": "6.8.1",
"eslint": "8.40.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "46.2.6",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-native": "4.0.0",
"eslint-plugin-typescript-sort-keys": "2.3.0",
"eslint": "8.57.0",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jsdoc": "50.6.1",
"eslint-plugin-react": "7.37.3",
"eslint-plugin-react-native": "5.0.0",
"eslint-plugin-typescript-sort-keys": "3.3.0",
"jetifier": "1.6.4",
"jsonwebtoken": "9.0.2",
"metro-react-native-babel-preset": "0.77.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
Loading