ref: Convert some reducers to TS (#11904)

This commit is contained in:
Robert Pintilii 2022-07-26 13:20:39 +03:00 committed by GitHub
parent 432d07c2ad
commit 44e5fa35af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 30 deletions

View File

@ -15,6 +15,10 @@ import { ILibJitsiMeetState } from '../base/lib-jitsi-meet/reducer';
import { ILoggingState } from '../base/logging/reducer';
import { IMediaState } from '../base/media/reducer';
import { INetInfoState } from '../base/net-info/reducer';
import { IResponsiveUIState } from '../base/responsive-ui/reducer';
import { ISettingsState } from '../base/settings/reducer';
import { ISoundsState } from '../base/sounds/reducer';
import { ITestingState } from '../base/testing/reducer';
import { INoiseSuppressionState } from '../noise-suppression/reducer';
export interface IStore {
@ -41,5 +45,9 @@ export interface IState {
'features/base/logging': ILoggingState,
'features/base/media': IMediaState,
'features/base/net-info': INetInfoState,
'features/noise-suppression': INoiseSuppressionState
'features/base/responsive-ui': IResponsiveUIState,
'features/base/settings': ISettingsState,
'features/base/sounds': ISoundsState,
'features/noise-suppression': INoiseSuppressionState,
'features/testing': ITestingState
}

View File

@ -1,6 +1,5 @@
// @flow
import { ReducerRegistry, set } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import { set } from '../redux/functions';
import {
CLIENT_RESIZED,
@ -27,7 +26,21 @@ const DEFAULT_STATE = {
contextMenuOpened: false
};
ReducerRegistry.register('features/base/responsive-ui', (state = DEFAULT_STATE, action) => {
export interface IResponsiveUIState {
aspectRatio: Symbol;
clientHeight: number;
clientWidth: number;
contextMenuOpened: boolean;
reducedUI: boolean;
safeAreaInsets?: {
bottom: number;
left: number;
right: number;
top: number;
}
}
ReducerRegistry.register('features/base/responsive-ui', (state: IResponsiveUIState = DEFAULT_STATE, action) => {
switch (action.type) {
case CLIENT_RESIZED: {
return {

View File

@ -1,10 +1,12 @@
// @flow
/* eslint-disable lines-around-comment */
// @ts-ignore
import { jitsiLocalStorage } from '@jitsi/js-utils';
import _ from 'lodash';
import { APP_WILL_MOUNT } from '../app/actionTypes';
import { PersistenceRegistry, ReducerRegistry } from '../redux';
import PersistenceRegistry from '../redux/PersistenceRegistry';
import ReducerRegistry from '../redux/ReducerRegistry';
// @ts-ignore
import { assignIfDefined } from '../util';
import { SETTINGS_UPDATED } from './actionTypes';
@ -14,7 +16,7 @@ import { SETTINGS_UPDATED } from './actionTypes';
*
* @type Object
*/
const DEFAULT_STATE = {
const DEFAULT_STATE: ISettingsState = {
audioOutputDeviceId: undefined,
avatarURL: undefined,
cameraDeviceId: undefined,
@ -49,16 +51,53 @@ const DEFAULT_STATE = {
userSelectedSkipPrejoin: undefined
};
export interface ISettingsState {
audioOutputDeviceId?: string|boolean;
avatarURL?: string|boolean;
cameraDeviceId?: string|boolean;
disableCallIntegration?: boolean;
disableCrashReporting?: boolean;
disableP2P?: boolean;
disableSelfView?: boolean;
displayName?: string|boolean;
email?: string|boolean;
hideShareAudioHelper?: boolean;
localFlipX?: boolean;
micDeviceId?: string|boolean;
serverURL?: string|boolean;
soundsIncomingMessage?: boolean;
soundsParticipantJoined?: boolean;
soundsParticipantKnocking?: boolean;
soundsParticipantLeft?: boolean;
soundsReactions?: boolean;
soundsTalkWhileMuted?: boolean;
startAudioOnly?: boolean;
startWithAudioMuted?: boolean;
startWithVideoMuted?: boolean;
userSelectedAudioOutputDeviceId?: string|boolean;
userSelectedAudioOutputDeviceLabel?: string|boolean;
userSelectedCameraDeviceId?: string|boolean;
userSelectedCameraDeviceLabel?: string|boolean;
userSelectedMicDeviceId?: string|boolean;
userSelectedMicDeviceLabel?: string|boolean;
userSelectedNotifications?: {
[key: string]: boolean;
}|boolean,
userSelectedSkipPrejoin?: boolean;
}
const STORE_NAME = 'features/base/settings';
/**
* Sets up the persistence of the feature {@code base/settings}.
*/
const filterSubtree = {};
const filterSubtree: ISettingsState = {};
// start with the default state
Object.keys(DEFAULT_STATE).forEach(key => {
filterSubtree[key] = true;
const key1 = key as keyof typeof filterSubtree;
filterSubtree[key1] = true;
});
// we want to filter these props, to not be stored as they represent
@ -69,7 +108,7 @@ filterSubtree.micDeviceId = false;
PersistenceRegistry.register(STORE_NAME, filterSubtree, DEFAULT_STATE);
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
ReducerRegistry.register(STORE_NAME, (state: ISettingsState = DEFAULT_STATE, action) => {
switch (action.type) {
case APP_WILL_MOUNT:
return _initSettings(state);
@ -90,10 +129,10 @@ ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
* - Old Settings.js style data.
*
* @private
* @param {Object} featureState - The current state of the feature.
* @param {ISettingsState} featureState - The current state of the feature.
* @returns {Object}
*/
function _initSettings(featureState) {
function _initSettings(featureState: ISettingsState) {
let settings = featureState;
// Old Settings.js values

View File

@ -1,7 +1,8 @@
// @flow
/* eslint-disable lines-around-comment */
// @ts-ignore
import type { AudioElement } from '../media';
import { assign, ReducerRegistry } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import { assign } from '../redux/functions';
import {
_ADD_AUDIO_ELEMENT,
@ -9,6 +10,7 @@ import {
REGISTER_SOUND,
UNREGISTER_SOUND
} from './actionTypes';
// @ts-ignore
import logger from './logger';
/**
@ -23,17 +25,17 @@ export type Sound = {
*/
audioElement?: AudioElement,
/**
* This field is container for all optional parameters related to the sound.
*/
options?: Object,
/**
* This field describes the source of the audio resource to be played. It
* can be either a path to the file or an object depending on the platform
* (native vs web).
*/
src: Object | string,
/**
* This field is container for all optional parameters related to the sound.
*/
options: Object
src?: Object | string
}
/**
@ -44,12 +46,14 @@ export type Sound = {
*/
const DEFAULT_STATE = new Map();
export type ISoundsState = Map<string, Sound>;
/**
* The base/sounds feature's reducer.
*/
ReducerRegistry.register(
'features/base/sounds',
(state = DEFAULT_STATE, action) => {
(state: ISoundsState = DEFAULT_STATE, action) => {
switch (action.type) {
case _ADD_AUDIO_ELEMENT:
case _REMOVE_AUDIO_ELEMENT:
@ -75,7 +79,7 @@ ReducerRegistry.register(
* @private
* @returns {Map<string, Sound>}
*/
function _addOrRemoveAudioElement(state, action) {
function _addOrRemoveAudioElement(state: ISoundsState, action: any) {
const isAddAction = action.type === _ADD_AUDIO_ELEMENT;
const nextState = new Map(state);
const { soundId } = action;
@ -112,7 +116,7 @@ function _addOrRemoveAudioElement(state, action) {
* @private
* @returns {Map<string, Sound>}
*/
function _registerSound(state, action) {
function _registerSound(state: ISoundsState, action: any) {
const nextState = new Map(state);
nextState.set(action.soundId, {
@ -133,7 +137,7 @@ function _registerSound(state, action) {
* @private
* @returns {Map<string, Sound>}
*/
function _unregisterSound(state, action) {
function _unregisterSound(state: ISoundsState, action: any) {
const nextState = new Map(state);
nextState.delete(action.soundId);

View File

@ -1,4 +1,5 @@
import { assign, ReducerRegistry } from '../redux';
import ReducerRegistry from '../redux/ReducerRegistry';
import { assign } from '../redux/functions';
import { SET_CONNECTION_STATE } from './actionTypes';
@ -13,9 +14,13 @@ const INITIAL_STATE = {
connectionState: ''
};
export interface ITestingState {
connectionState: string;
}
ReducerRegistry.register(
'features/testing',
(state = INITIAL_STATE, action) => {
(state: ITestingState = INITIAL_STATE, action) => {
switch (action.type) {
case SET_CONNECTION_STATE:
return _setConnectionState(state, action);
@ -35,6 +40,6 @@ ReducerRegistry.register(
* @returns {Object} The new state of the feature testing after the
* reduction of the specified action.
*/
function _setConnectionState(state, action) {
function _setConnectionState(state: ITestingState, action: any) {
return assign(state, { connectionState: action.connectionState });
}