ref(reducers) Convert some reducers to TS (#11768)

This commit is contained in:
Robert Pintilii 2022-07-01 12:32:39 +03:00 committed by GitHub
parent 0913cf2c4f
commit a39d9f283d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 111 additions and 50 deletions

View File

@ -1,6 +1,4 @@
// @flow
import { ReducerRegistry } from '../base/redux';
import ReducerRegistry from '../base/redux/ReducerRegistry';
import { UPDATE_LOCAL_TRACKS_DURATION } from './actionTypes';
@ -30,6 +28,22 @@ const DEFAULT_STATE = {
}
};
interface Value {
startedTime: number,
value: number
}
export interface IAnalyticsState {
localTracksDuration: {
audio: Value,
video: {
camera: Value,
desktop: Value
},
conference: Value
}
}
/**
* Listen for actions which changes the state of the analytics feature.
*
@ -38,7 +52,7 @@ const DEFAULT_STATE = {
* @param {string} action.type - Type of action.
* @returns {Object}
*/
ReducerRegistry.register('features/analytics', (state = DEFAULT_STATE, action) => {
ReducerRegistry.register('features/analytics', (state: IAnalyticsState = DEFAULT_STATE, action: any) => {
switch (action.type) {
case UPDATE_LOCAL_TRACKS_DURATION:
return {

View File

@ -1,4 +1,20 @@
import { IAnalyticsState } from "../analytics/reducer"
import { IAuthenticationState } from "../authentication/reducer"
import { IAVModerationState } from "../av-moderation/reducer"
import { IAppState } from "../base/app/reducer"
import { IAudioOnlyState } from "../base/audio-only/reducer"
import { IConferenceState } from "../base/conference/reducer"
export interface IStore {
getState: Function,
dispatch: Function
}
export interface IState {
'features/analytics': IAnalyticsState,
'features/authentication': IAuthenticationState,
'features/av-moderation': IAVModerationState,
'features/base/app': IAppState,
'features/base/audio-only': IAudioOnlyState,
'features/base/conference': IConferenceState
}

View File

@ -1,6 +1,6 @@
// @flow
import { assign, ReducerRegistry } from '../base/redux';
// @ts-ignore
import { assign } from '../base/redux/functions';
import ReducerRegistry from '../base/redux/ReducerRegistry';
import {
CANCEL_LOGIN,
@ -10,6 +10,13 @@ import {
WAIT_FOR_OWNER
} from './actionTypes';
export interface IAuthenticationState {
error?: Object|undefined;
progress?: number|undefined;
thenableWithCancel?: Object|undefined;
waitForOwnerTimeoutID?: number;
}
/**
* Listens for actions which change the state of the authentication feature.
*
@ -18,7 +25,7 @@ import {
* @param {string} action.type - Type of action.
* @returns {Object}
*/
ReducerRegistry.register('features/authentication', (state = {}, action) => {
ReducerRegistry.register('features/authentication', (state: IAuthenticationState = {}, action: any) => {
switch (action.type) {
case CANCEL_LOGIN:
return assign(state, {

View File

@ -1,11 +1,9 @@
// @flow
import { MEDIA_TYPE, type MediaType } from '../base/media/constants';
/**
* Mapping between a media type and the witelist reducer key.
*/
export const MEDIA_TYPE_TO_WHITELIST_STORE_KEY: {[key: MediaType]: string} = {
export const MEDIA_TYPE_TO_WHITELIST_STORE_KEY: { [key: string]: string } = {
[MEDIA_TYPE.AUDIO]: 'audioWhitelist',
[MEDIA_TYPE.VIDEO]: 'videoWhitelist'
};
@ -13,7 +11,7 @@ export const MEDIA_TYPE_TO_WHITELIST_STORE_KEY: {[key: MediaType]: string} = {
/**
* Mapping between a media type and the pending reducer key.
*/
export const MEDIA_TYPE_TO_PENDING_STORE_KEY: {[key: MediaType]: string} = {
export const MEDIA_TYPE_TO_PENDING_STORE_KEY: {[key: string]: string} = {
[MEDIA_TYPE.AUDIO]: 'pendingAudio',
[MEDIA_TYPE.VIDEO]: 'pendingVideo'
};

View File

@ -1,12 +1,11 @@
/* @flow */
import { MEDIA_TYPE } from '../base/media/constants';
import type { MediaType } from '../base/media/constants';
import {
PARTICIPANT_LEFT,
PARTICIPANT_UPDATED
// @ts-ignore
} from '../base/participants';
import { ReducerRegistry } from '../base/redux';
import ReducerRegistry from '../base/redux/ReducerRegistry';
import {
DISABLE_MODERATION,
@ -29,8 +28,19 @@ const initialState = {
pendingVideo: []
};
export interface IAVModerationState {
audioModerationEnabled: boolean;
videoModerationEnabled: boolean;
audioWhitelist: { [id: string]: boolean };
videoWhitelist: { [id: string]: boolean };
pendingAudio: Array<{ id: string }>;
pendingVideo: Array<{ id: string }>;
audioUnmuteApproved?: boolean|undefined;
videoUnmuteApproved?: boolean|undefined;
}
/**
Updates a participant in the state for the specified media type.
* Updates a participant in the state for the specified media type.
*
* @param {MediaType} mediaType - The media type.
* @param {Object} participant - Information about participant to be modified.
@ -38,11 +48,11 @@ const initialState = {
* @private
* @returns {boolean} - Whether state instance was modified.
*/
function _updatePendingParticipant(mediaType: MediaType, participant, state: Object = {}) {
function _updatePendingParticipant(mediaType: MediaType, participant: any, state: any = {}) {
let arrayItemChanged = false;
const storeKey = MEDIA_TYPE_TO_PENDING_STORE_KEY[mediaType];
const arr = state[storeKey];
const newArr = arr.map(pending => {
const newArr = arr.map((pending: { id: string} ) => {
if (pending.id === participant.id) {
arrayItemChanged = true;
@ -64,7 +74,7 @@ function _updatePendingParticipant(mediaType: MediaType, participant, state: Obj
return false;
}
ReducerRegistry.register('features/av-moderation', (state = initialState, action) => {
ReducerRegistry.register('features/av-moderation', (state: IAVModerationState = initialState, action: any) => {
switch (action.type) {
case DISABLE_MODERATION: {

View File

@ -1,10 +1,12 @@
// @flow
import { ReducerRegistry } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
ReducerRegistry.register('features/base/app', (state = {}, action) => {
export interface IAppState {
app?: Object|undefined;
}
ReducerRegistry.register('features/base/app', (state: IAppState = {}, action) => {
switch (action.type) {
case APP_WILL_MOUNT: {
const { app } = action;

View File

@ -1,16 +1,17 @@
// @flow
import { ReducerRegistry } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import { SET_AUDIO_ONLY } from './actionTypes';
export interface IAudioOnlyState {
enabled: boolean
}
const DEFAULT_STATE = {
enabled: false
};
ReducerRegistry.register('features/base/audio-only', (state = DEFAULT_STATE, action) => {
ReducerRegistry.register('features/base/audio-only', (state: IAudioOnlyState = DEFAULT_STATE, action) => {
switch (action.type) {
case SET_AUDIO_ONLY:
return {

View File

@ -1,9 +1,12 @@
// @flow
// @ts-ignore
import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
// @ts-ignore
import { CONNECTION_WILL_CONNECT, SET_LOCATION_URL } from '../connection';
// @ts-ignore
import { JitsiConferenceErrors } from '../lib-jitsi-meet';
import { assign, ReducerRegistry, set } from '../redux';
// @ts-ignore
import { assign, set } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import {
AUTH_STATUS_CHANGED,
@ -25,6 +28,7 @@ import {
SET_START_MUTED_POLICY,
SET_START_REACTIONS_MUTED
} from './actionTypes';
// @ts-ignore
import { isRoomValid } from './functions';
const DEFAULT_STATE = {
@ -38,13 +42,26 @@ const DEFAULT_STATE = {
passwordRequired: undefined
};
export interface IConferenceState {
conference: Object|undefined;
e2eeSupported: boolean|undefined;
joining: Object|undefined;
leaving: Object|undefined;
locked: string|undefined;
membersOnly: boolean|undefined;
password: string|undefined;
passwordRequired: boolean|undefined;
authEnabled?: boolean|undefined;
authLogin?: string|undefined;
}
/**
* Listen for actions that contain the conference object, so that it can be
* stored for use by other action creators.
*/
ReducerRegistry.register(
'features/base/conference',
(state = DEFAULT_STATE, action) => {
(state: IConferenceState = DEFAULT_STATE, action: any) => {
switch (action.type) {
case AUTH_STATUS_CHANGED:
return _authStatusChanged(state, action);
@ -125,7 +142,7 @@ ReducerRegistry.register(
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _authStatusChanged(state, { authEnabled, authLogin }) {
function _authStatusChanged(state: any, { authEnabled, authLogin }: {authEnabled: boolean, authLogin: string}) {
return assign(state, {
authEnabled,
authLogin
@ -142,7 +159,7 @@ function _authStatusChanged(state, { authEnabled, authLogin }) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _conferenceFailed(state, { conference, error }) {
function _conferenceFailed(state: any, { conference, error }: {conference: Object, error: any}) {
// The current (similar to getCurrentConference in
// base/conference/functions.any.js) conference which is joining or joined:
const conference_ = state.conference || state.joining;
@ -208,7 +225,7 @@ function _conferenceFailed(state, { conference, error }) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _conferenceJoined(state, { conference }) {
function _conferenceJoined(state: any, { conference }: {conference: any}) {
// FIXME The indicator which determines whether a JitsiConference is locked
// i.e. password-protected is private to lib-jitsi-meet. However, the
// library does not fire LOCK_STATE_CHANGED upon joining a JitsiConference
@ -254,7 +271,7 @@ function _conferenceJoined(state, { conference }) {
* @returns {Object} The next/new state of the feature base/conference after the
* reduction of the specified action.
*/
function _conferenceLeftOrWillLeave(state, { conference, type }) {
function _conferenceLeftOrWillLeave(state: any, { conference, type }: {conference: Object, type: string}) {
const nextState = { ...state };
// The redux action CONFERENCE_LEFT is the last time that we should be
@ -308,7 +325,7 @@ function _conferenceLeftOrWillLeave(state, { conference, type }) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _conferenceWillJoin(state, { conference }) {
function _conferenceWillJoin(state: any, { conference }: {conference: Object}) {
return assign(state, {
error: undefined,
joining: conference
@ -325,7 +342,7 @@ function _conferenceWillJoin(state, { conference }) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _lockStateChanged(state, { conference, locked }) {
function _lockStateChanged(state: any, { conference, locked }: {conference: Object, locked: boolean}) {
if (state.conference !== conference) {
return state;
}
@ -346,7 +363,7 @@ function _lockStateChanged(state, { conference, locked }) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _p2pStatusChanged(state, action) {
function _p2pStatusChanged(state: any, action: any) {
return set(state, 'p2p', action.p2p);
}
@ -359,7 +376,7 @@ function _p2pStatusChanged(state, action) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _setPassword(state, { conference, method, password }) {
function _setPassword(state: any, { conference, method, password }: {conference: any, method: Object, password: string}) {
switch (method) {
case conference.join:
return assign(state, {
@ -406,7 +423,7 @@ function _setPassword(state, { conference, method, password }) {
* @returns {Object} The new state of the feature base/conference after the
* reduction of the specified action.
*/
function _setRoom(state, action) {
function _setRoom(state: any, action: any) {
let { room } = action;
if (!isRoomValid(room)) {

View File

@ -1,5 +1,3 @@
// @flow
/**
* The set of facing modes for camera.
*
@ -17,7 +15,7 @@ export type MediaType = 'audio' | 'video' | 'presenter' | 'screenshare';
*
* @enum {string}
*/
export const MEDIA_TYPE = {
export const MEDIA_TYPE: {[key: string]: MediaType} = {
AUDIO: 'audio',
PRESENTER: 'presenter',
SCREENSHARE: 'screenshare',

View File

@ -1,20 +1,18 @@
/* @flow */
import { combineReducers } from 'redux';
import { Action, combineReducers } from 'redux';
import type { Reducer } from 'redux';
/**
* The type of the dictionary/map which associates a reducer (function) with the
* name of he Redux state property managed by the reducer.
*/
declare type NameReducerMap<S, A> = { [name: string]: Reducer<S, A> };
declare type NameReducerMap<S, A> = { [name: string]: Reducer<S, Action<any>> };
/**
* A registry for Redux reducers, allowing features to register themselves
* without needing to create additional inter-feature dependencies.
*/
class ReducerRegistry {
_elements: NameReducerMap<*, *>;
_elements: NameReducerMap<any, any>;
/**
* Creates a ReducerRegistry instance.
@ -37,7 +35,7 @@ class ReducerRegistry {
* included (such as reducers from third-party modules).
* @returns {Function}
*/
combineReducers(additional: NameReducerMap<*, *> = {}) {
combineReducers(additional: NameReducerMap<any, any> = {}) {
// $FlowExpectedError
return combineReducers({
...this._elements,
@ -55,7 +53,7 @@ class ReducerRegistry {
* @param {Reducer} reducer - A Redux reducer.
* @returns {void}
*/
register(name: string, reducer: Reducer<*, *>) {
register(name: string, reducer: Reducer<any, any>) {
this._elements[name] = reducer;
}
}