ref: Convert files to TS (#11840)

This commit is contained in:
Robert Pintilii 2022-07-12 14:41:26 +03:00 committed by GitHub
parent df887d24a2
commit f31a7f31e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 49 deletions

View File

@ -5,6 +5,7 @@ import { IAppState } from '../base/app/reducer';
import { IAudioOnlyState } from '../base/audio-only/reducer'; import { IAudioOnlyState } from '../base/audio-only/reducer';
import { IConferenceState } from '../base/conference/reducer'; import { IConferenceState } from '../base/conference/reducer';
import { IConfig } from '../base/config/configType'; import { IConfig } from '../base/config/configType';
import { IConnectionState } from '../base/connection/reducer';
export interface IStore { export interface IStore {
getState: Function, getState: Function,
@ -19,4 +20,5 @@ export interface IState {
'features/base/audio-only': IAudioOnlyState, 'features/base/audio-only': IAudioOnlyState,
'features/base/conference': IConferenceState, 'features/base/conference': IConferenceState,
'features/base/config': IConfig, 'features/base/config': IConfig,
'features/base/connection': IConnectionState
} }

View File

@ -1,7 +1,4 @@
/* eslint-disable import/order */
import ReducerRegistry from '../base/redux/ReducerRegistry'; import ReducerRegistry from '../base/redux/ReducerRegistry';
// @ts-ignore
import { assign } from '../base/redux/functions'; import { assign } from '../base/redux/functions';
import { import {

View File

@ -8,8 +8,7 @@ import { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection';
// @ts-ignore // @ts-ignore
import { JitsiConferenceErrors } from '../lib-jitsi-meet'; import { JitsiConferenceErrors } from '../lib-jitsi-meet';
// @ts-ignore import { assign, set } from '../redux/functions';
import { assign, set } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry'; import ReducerRegistry from '../redux/ReducerRegistry';
import { import {
@ -58,6 +57,14 @@ export interface IConferenceState {
passwordRequired: boolean|undefined; passwordRequired: boolean|undefined;
authEnabled?: boolean|undefined; authEnabled?: boolean|undefined;
authLogin?: string|undefined; authLogin?: string|undefined;
subject?: string;
localSubject?: string;
conferenceTimestamp?: number;
authRequired?: Object;
followMeEnabled?: boolean;
startReactionsMuted?: boolean;
room?: Object;
pendingSubjectChange?: string;
} }
/** /**

View File

@ -3,8 +3,7 @@ import _ from 'lodash';
import { CONFERENCE_INFO } from '../../conference/components/constants'; import { CONFERENCE_INFO } from '../../conference/components/constants';
// @ts-ignore import { equals } from '../redux/functions';
import { equals } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry'; import ReducerRegistry from '../redux/ReducerRegistry';
import { import {

View File

@ -1,8 +1,11 @@
/* @flow */ /* eslint-disable import/order */
import { SET_ROOM } from '../conference'; import { SET_ROOM } from '../conference/actionTypes';
// @ts-ignore
import { JitsiConnectionErrors } from '../lib-jitsi-meet'; import { JitsiConnectionErrors } from '../lib-jitsi-meet';
import { assign, set, ReducerRegistry } from '../redux'; import { assign, set } from '../redux/functions';
import ReducerRegistry from '../redux/ReducerRegistry';
import { import {
CONNECTION_DISCONNECTED, CONNECTION_DISCONNECTED,
@ -12,14 +15,26 @@ import {
SET_LOCATION_URL, SET_LOCATION_URL,
SHOW_CONNECTION_INFO SHOW_CONNECTION_INFO
} from './actionTypes'; } from './actionTypes';
import type { ConnectionFailedError } from './actions.native';
// @ts-ignore
import { ConnectionFailedError } from './actions.native';
export interface IConnectionState {
connection?: Object;
connecting?: Object;
timeEstablished?: number;
error?: ConnectionFailedError;
passwordRequired?: Object;
locationURL?: URL;
showConnectionInfo?: boolean;
}
/** /**
* Reduces the Redux actions of the feature base/connection. * Reduces the Redux actions of the feature base/connection.
*/ */
ReducerRegistry.register( ReducerRegistry.register(
'features/base/connection', 'features/base/connection',
(state: Object = {}, action: Object) => { (state: IConnectionState = {}, action: any) => {
switch (action.type) { switch (action.type) {
case CONNECTION_DISCONNECTED: case CONNECTION_DISCONNECTED:
return _connectionDisconnected(state, action); return _connectionDisconnected(state, action);
@ -50,14 +65,14 @@ ReducerRegistry.register(
* Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature * Reduces a specific Redux action CONNECTION_DISCONNECTED of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The Redux state of the feature base/connection. * @param {IConnectionState} state - The Redux state of the feature base/connection.
* @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce. * @param {Action} action - The Redux action CONNECTION_DISCONNECTED to reduce.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _connectionDisconnected( function _connectionDisconnected(
state: Object, state: IConnectionState,
{ connection }: { connection: Object }) { { connection }: { connection: Object }) {
const connection_ = _getCurrentConnection(state); const connection_ = _getCurrentConnection(state);
@ -76,14 +91,14 @@ function _connectionDisconnected(
* Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The Redux state of the feature base/connection. * @param {IConnectionState} state - The Redux state of the feature base/connection.
* @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce. * @param {Action} action - The Redux action CONNECTION_ESTABLISHED to reduce.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _connectionEstablished( function _connectionEstablished(
state: Object, state: IConnectionState,
{ connection, timeEstablished }: { { connection, timeEstablished }: {
connection: Object, connection: Object,
timeEstablished: number timeEstablished: number
@ -101,14 +116,14 @@ function _connectionEstablished(
* Reduces a specific Redux action CONNECTION_FAILED of the feature * Reduces a specific Redux action CONNECTION_FAILED of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The Redux state of the feature base/connection. * @param {IConnectionState} state - The Redux state of the feature base/connection.
* @param {Action} action - The Redux action CONNECTION_FAILED to reduce. * @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _connectionFailed( function _connectionFailed(
state: Object, state: IConnectionState,
{ connection, error }: { { connection, error }: {
connection: Object, connection: Object,
error: ConnectionFailedError error: ConnectionFailedError
@ -133,14 +148,14 @@ function _connectionFailed(
* Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature * Reduces a specific Redux action CONNECTION_WILL_CONNECT of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The Redux state of the feature base/connection. * @param {IConnectionState} state - The Redux state of the feature base/connection.
* @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce. * @param {Action} action - The Redux action CONNECTION_WILL_CONNECT to reduce.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _connectionWillConnect( function _connectionWillConnect(
state: Object, state: IConnectionState,
{ connection }: { connection: Object }) { { connection }: { connection: Object }) {
return assign(state, { return assign(state, {
connecting: connection, connecting: connection,
@ -159,12 +174,12 @@ function _connectionWillConnect(
* The current (similar to getCurrentConference in base/conference/functions.any.js) * The current (similar to getCurrentConference in base/conference/functions.any.js)
* connection which is {@code connection} or {@code connecting}. * connection which is {@code connection} or {@code connecting}.
* *
* @param {Object} baseConnectionState - The current state of the * @param {IConnectionState} baseConnectionState - The current state of the
* {@code 'base/connection'} feature. * {@code 'base/connection'} feature.
* @returns {JitsiConnection} - The current {@code JitsiConnection} if any. * @returns {JitsiConnection} - The current {@code JitsiConnection} if any.
* @private * @private
*/ */
function _getCurrentConnection(baseConnectionState: Object): ?Object { function _getCurrentConnection(baseConnectionState: IConnectionState): IConnectionState|undefined {
return baseConnectionState.connection || baseConnectionState.connecting; return baseConnectionState.connection || baseConnectionState.connecting;
} }
@ -172,15 +187,15 @@ function _getCurrentConnection(baseConnectionState: Object): ?Object {
* Reduces a specific redux action {@link SET_LOCATION_URL} of the feature * Reduces a specific redux action {@link SET_LOCATION_URL} of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The redux state of the feature base/connection. * @param {IConnectionState} state - The redux state of the feature base/connection.
* @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce. * @param {Action} action - The redux action {@code SET_LOCATION_URL} to reduce.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _setLocationURL( function _setLocationURL(
state: Object, state: IConnectionState,
{ locationURL }: { locationURL: ?URL }) { { locationURL }: { locationURL?: URL }) {
return set(state, 'locationURL', locationURL); return set(state, 'locationURL', locationURL);
} }
@ -188,12 +203,12 @@ function _setLocationURL(
* Reduces a specific redux action {@link SET_ROOM} of the feature * Reduces a specific redux action {@link SET_ROOM} of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The redux state of the feature base/connection. * @param {IConnectionState} state - The redux state of the feature base/connection.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _setRoom(state: Object) { function _setRoom(state: IConnectionState) {
return assign(state, { return assign(state, {
error: undefined, error: undefined,
passwordRequired: undefined passwordRequired: undefined
@ -204,14 +219,14 @@ function _setRoom(state: Object) {
* Reduces a specific redux action {@link SHOW_CONNECTION_INFO} of the feature * Reduces a specific redux action {@link SHOW_CONNECTION_INFO} of the feature
* base/connection. * base/connection.
* *
* @param {Object} state - The redux state of the feature base/connection. * @param {IConnectionState} state - The redux state of the feature base/connection.
* @param {Action} action - The redux action {@code SHOW_CONNECTION_INFO} to reduce. * @param {Action} action - The redux action {@code SHOW_CONNECTION_INFO} to reduce.
* @private * @private
* @returns {Object} The new state of the feature base/connection after the * @returns {Object} The new state of the feature base/connection after the
* reduction of the specified action. * reduction of the specified action.
*/ */
function _setShowConnectionInfo( function _setShowConnectionInfo(
state: Object, state: IConnectionState,
{ showConnectionInfo }: { showConnectionInfo: boolean }) { { showConnectionInfo }: { showConnectionInfo: boolean }) {
return set(state, 'showConnectionInfo', showConnectionInfo); return set(state, 'showConnectionInfo', showConnectionInfo);
} }

View File

@ -1,22 +1,22 @@
// @flow
import _ from 'lodash'; import _ from 'lodash';
import { connect as reduxConnect } from 'react-redux'; import { connect as reduxConnect } from 'react-redux';
import { IStore } from '../../app/types';
/** /**
* Sets specific properties of a specific state to specific values and prevents * Sets specific properties of a specific state to specific values and prevents
* unnecessary state changes. * unnecessary state changes.
* *
* @param {Object} target - The state on which the specified properties are to * @param {T} target - The state on which the specified properties are to
* be set. * be set.
* @param {Object} source - The map of properties to values which are to be set * @param {T} source - The map of properties to values which are to be set
* on the specified target. * on the specified target.
* @returns {Object} The specified target if the values of the specified * @returns {T} The specified target if the values of the specified
* properties equal the specified values; otherwise, a new state constructed * properties equal the specified values; otherwise, a new state constructed
* from the specified target by setting the specified properties to the * from the specified target by setting the specified properties to the
* specified values. * specified values.
*/ */
export function assign(target: Object, source: Object) { export function assign<T extends Object>(target: T, source: T): T {
let t = target; let t = target;
for (const property in source) { // eslint-disable-line guard-for-in for (const property in source) { // eslint-disable-line guard-for-in
@ -30,13 +30,13 @@ export function assign(target: Object, source: Object) {
* Wrapper function for the react-redux connect function to avoid having to * Wrapper function for the react-redux connect function to avoid having to
* declare function types for flow, but still let flow warn for other errors. * declare function types for flow, but still let flow warn for other errors.
* *
* @param {Function?} mapStateToProps - Redux mapStateToProps function. * @param {any} mapStateToProps - Redux mapStateToProps function.
* @param {Function?} mapDispatchToProps - Redux mapDispatchToProps function. * @param {Function?} mapDispatchToProps - Redux mapDispatchToProps function.
* @returns {Connector} * @returns {Connector}
*/ */
export function connect( export function connect(
mapStateToProps?: Function, mapDispatchToProps?: Function) { mapStateToProps?: any, mapDispatchToProps?: Function) {
return reduxConnect<*, *, *, *, *, *>(mapStateToProps, mapDispatchToProps); return reduxConnect(mapStateToProps, mapDispatchToProps);
} }
/** /**
@ -57,18 +57,18 @@ export function equals(a: any, b: any) {
* unnecessary state changes (when the specified {@code value} is equal to the * unnecessary state changes (when the specified {@code value} is equal to the
* value of the specified {@code property} of the specified {@code state}). * value of the specified {@code property} of the specified {@code state}).
* *
* @param {Object} state - The (Redux) state from which a new state is to be * @param {T} state - The (Redux) state from which a new state is to be
* constructed by setting the specified {@code property} to the specified * constructed by setting the specified {@code property} to the specified
* {@code value}. * {@code value}.
* @param {string} property - The property of {@code state} which is to be * @param {string} property - The property of {@code state} which is to be
* assigned the specified {@code value} (in the new state). * assigned the specified {@code value} (in the new state).
* @param {*} value - The value to assign to the specified {@code property}. * @param {*} value - The value to assign to the specified {@code property}.
* @returns {Object} The specified {@code state} if the value of the specified * @returns {T} The specified {@code state} if the value of the specified
* {@code property} equals the specified <tt>value/tt>; otherwise, a new state * {@code property} equals the specified <tt>value/tt>; otherwise, a new state
* constructed from the specified {@code state} by setting the specified * constructed from the specified {@code state} by setting the specified
* {@code property} to the specified {@code value}. * {@code property} to the specified {@code value}.
*/ */
export function set(state: Object, property: string, value: any) { export function set<T extends Object>(state: T, property: keyof T, value: any): T {
return _set(state, property, value, /* copyOnWrite */ true); return _set(state, property, value, /* copyOnWrite */ true);
} }
@ -79,7 +79,7 @@ export function set(state: Object, property: string, value: any) {
* unnecessary state changes (when the specified {@code value} is equal to the * unnecessary state changes (when the specified {@code value} is equal to the
* value of the specified {@code property} of the specified {@code state}). * value of the specified {@code property} of the specified {@code state}).
* *
* @param {Object} state - The (Redux) state from which a state is to be * @param {T} state - The (Redux) state from which a state is to be
* constructed by setting the specified {@code property} to the specified * constructed by setting the specified {@code property} to the specified
* {@code value}. * {@code value}.
* @param {string} property - The property of {@code state} which is to be * @param {string} property - The property of {@code state} which is to be
@ -87,17 +87,17 @@ export function set(state: Object, property: string, value: any) {
* @param {*} value - The value to assign to the specified {@code property}. * @param {*} value - The value to assign to the specified {@code property}.
* @param {boolean} copyOnWrite - If the specified {@code state} is to not be * @param {boolean} copyOnWrite - If the specified {@code state} is to not be
* modified, {@code true}; otherwise, {@code false}. * modified, {@code true}; otherwise, {@code false}.
* @returns {Object} The specified {@code state} if the value of the specified * @returns {T} The specified {@code state} if the value of the specified
* {@code property} equals the specified <tt>value/tt> or {@code copyOnWrite} * {@code property} equals the specified <tt>value/tt> or {@code copyOnWrite}
* is truthy; otherwise, a new state constructed from the specified * is truthy; otherwise, a new state constructed from the specified
* {@code state} by setting the specified {@code property} to the specified * {@code state} by setting the specified {@code property} to the specified
* {@code value}. * {@code value}.
*/ */
function _set( function _set<T extends Object>(
state: Object, state: T,
property: string, property: keyof T,
value: any, value: any,
copyOnWrite: boolean) { copyOnWrite: boolean): T {
// Delete state properties that are to be set to undefined. (It is a matter // Delete state properties that are to be set to undefined. (It is a matter
// of personal preference, mostly.) // of personal preference, mostly.)
if (typeof value === 'undefined' if (typeof value === 'undefined'
@ -130,12 +130,12 @@ function _set(
* be related to the redux state (e.g. The redux store, the redux * be related to the redux state (e.g. The redux store, the redux
* {@code getState} function). * {@code getState} function).
* *
* @param {Function|Object} stateful - The entity such as the redux store or the * @param {Function|IStore} stateful - The entity such as the redux store or the
* redux {@code getState} function from which the redux state is to be * redux {@code getState} function from which the redux state is to be
* returned. * returned.
* @returns {Object} The redux state. * @returns {Object} The redux state.
*/ */
export function toState(stateful: Function | Object) { export function toState(stateful: Function | IStore) {
if (stateful) { if (stateful) {
if (typeof stateful === 'function') { if (typeof stateful === 'function') {
return stateful(); return stateful();