ref: Convert some reducers to TS (#11862)

This commit is contained in:
Robert Pintilii 2022-07-14 12:38:09 +03:00 committed by GitHub
parent c7f96de787
commit defd0d2aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 8 deletions

View File

@ -6,6 +6,8 @@ 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'; import { IConnectionState } from '../base/connection/reducer';
import { IDevicesState } from '../base/devices/reducer';
import { IDialogState } from '../base/dialog/reducer';
export interface IStore { export interface IStore {
getState: Function, getState: Function,
@ -20,5 +22,7 @@ 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 'features/base/connection': IConnectionState,
'features/base/devices': IDevicesState,
'features/base/dialog': IDialogState
} }

View File

@ -1,4 +1,5 @@
import { ReducerRegistry } from '../redux'; /* eslint-disable import/order */
import ReducerRegistry from '../redux/ReducerRegistry';
import { import {
ADD_PENDING_DEVICE_REQUEST, ADD_PENDING_DEVICE_REQUEST,
@ -8,10 +9,15 @@ import {
SET_VIDEO_INPUT_DEVICE, SET_VIDEO_INPUT_DEVICE,
UPDATE_DEVICE_LIST UPDATE_DEVICE_LIST
} from './actionTypes'; } from './actionTypes';
// @ts-ignore
import { groupDevicesByKind } from './functions'; import { groupDevicesByKind } from './functions';
// @ts-ignore
import logger from './logger'; import logger from './logger';
const DEFAULT_STATE = {
const DEFAULT_STATE: IDevicesState = {
availableDevices: { availableDevices: {
audioInput: [], audioInput: [],
audioOutput: [], audioOutput: [],
@ -24,10 +30,23 @@ const DEFAULT_STATE = {
} }
}; };
export interface IDevicesState {
availableDevices: {
audioInput: MediaDeviceInfo[];
audioOutput: MediaDeviceInfo[];
videoInput: MediaDeviceInfo[];
};
pendingRequests: Object[];
permissions: {
audio: boolean;
video: boolean;
}
}
/** /**
* Listen for actions which changes the state of known and used devices. * Listen for actions which changes the state of known and used devices.
* *
* @param {Object} state - The Redux state of the feature features/base/devices. * @param {IDevicesState} state - The Redux state of the feature features/base/devices.
* @param {Object} action - Action object. * @param {Object} action - Action object.
* @param {string} action.type - Type of action. * @param {string} action.type - Type of action.
* @param {Array<MediaDeviceInfo>} action.devices - All available audio and * @param {Array<MediaDeviceInfo>} action.devices - All available audio and
@ -36,7 +55,7 @@ const DEFAULT_STATE = {
*/ */
ReducerRegistry.register( ReducerRegistry.register(
'features/base/devices', 'features/base/devices',
(state = DEFAULT_STATE, action) => { (state: IDevicesState = DEFAULT_STATE, action) => {
switch (action.type) { switch (action.type) {
case UPDATE_DEVICE_LIST: { case UPDATE_DEVICE_LIST: {
const deviceList = groupDevicesByKind(action.devices); const deviceList = groupDevicesByKind(action.devices);

View File

@ -1,4 +1,5 @@
import { assign, ReducerRegistry } from '../redux'; import ReducerRegistry from '../redux/ReducerRegistry';
import { assign } from '../redux/functions';
import { import {
HIDE_DIALOG, HIDE_DIALOG,
@ -7,16 +8,23 @@ import {
OPEN_SHEET OPEN_SHEET
} from './actionTypes'; } from './actionTypes';
export interface IDialogState {
component?: Object;
componentProps?: Object;
sheet?: Object;
sheetProps?: Object;
}
/** /**
* Reduces redux actions which show or hide dialogs. * Reduces redux actions which show or hide dialogs.
* *
* @param {State} state - The current redux state. * @param {IDialogState} state - The current redux state.
* @param {Action} action - The redux action to reduce. * @param {Action} action - The redux action to reduce.
* @param {string} action.type - The type of the redux action to reduce.. * @param {string} action.type - The type of the redux action to reduce..
* @returns {State} The next redux state that is the result of reducing the * @returns {State} The next redux state that is the result of reducing the
* specified action. * specified action.
*/ */
ReducerRegistry.register('features/base/dialog', (state = {}, action) => { ReducerRegistry.register('features/base/dialog', (state: IDialogState = {}, action) => {
switch (action.type) { switch (action.type) {
case HIDE_DIALOG: { case HIDE_DIALOG: {
const { component } = action; const { component } = action;