ref: Convert some reducers to TS (#11875)
This commit is contained in:
parent
5a4ffea9aa
commit
449d52f26b
|
@ -8,6 +8,10 @@ import { IConfig } from '../base/config/configType';
|
|||
import { IConnectionState } from '../base/connection/reducer';
|
||||
import { IDevicesState } from '../base/devices/reducer';
|
||||
import { IDialogState } from '../base/dialog/reducer';
|
||||
import { IFlagsState } from '../base/flags/reducer';
|
||||
import { IJwtState } from '../base/jwt/reducer';
|
||||
import { ILastNState } from '../base/lastn/reducer';
|
||||
import { ILibJitsiMeetState } from '../base/lib-jitsi-meet/reducer';
|
||||
|
||||
export interface IStore {
|
||||
getState: Function,
|
||||
|
@ -24,5 +28,10 @@ export interface IState {
|
|||
'features/base/config': IConfig,
|
||||
'features/base/connection': IConnectionState,
|
||||
'features/base/devices': IDevicesState,
|
||||
'features/base/dialog': IDialogState
|
||||
'features/base/dialog': IDialogState,
|
||||
'features/base/flags': IFlagsState,
|
||||
'features/base/jwt': IJwtState,
|
||||
'features/base/known-domains': Array<string>,
|
||||
'features/base/lastn': ILastNState,
|
||||
'features/base/lib-jitsi-meet': ILibJitsiMeetState
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// @flow
|
||||
|
||||
import _ from 'lodash';
|
||||
|
||||
import { ReducerRegistry } from '../redux';
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
|
||||
import { UPDATE_FLAGS } from './actionTypes';
|
||||
|
||||
|
@ -11,6 +9,10 @@ import { UPDATE_FLAGS } from './actionTypes';
|
|||
*/
|
||||
const DEFAULT_STATE = {};
|
||||
|
||||
export interface IFlagsState {
|
||||
flags?: Object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces redux actions which handle feature flags.
|
||||
*
|
||||
|
@ -20,7 +22,7 @@ const DEFAULT_STATE = {};
|
|||
* @returns {State} The next redux state that is the result of reducing the
|
||||
* specified action.
|
||||
*/
|
||||
ReducerRegistry.register('features/base/flags', (state = DEFAULT_STATE, action) => {
|
||||
ReducerRegistry.register('features/base/flags', (state: IFlagsState = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case UPDATE_FLAGS: {
|
||||
const newState = _.merge({}, state, action.flags);
|
|
@ -1,9 +1,12 @@
|
|||
// @flow
|
||||
|
||||
import { equals, ReducerRegistry } from '../redux';
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
import { equals } from '../redux/functions';
|
||||
|
||||
import { SET_JWT } from './actionTypes';
|
||||
|
||||
export interface IJwtState {
|
||||
jwt?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces redux actions which affect the JSON Web Token (JWT) stored in the
|
||||
* redux store.
|
||||
|
@ -15,10 +18,10 @@ import { SET_JWT } from './actionTypes';
|
|||
*/
|
||||
ReducerRegistry.register(
|
||||
'features/base/jwt',
|
||||
(state = {}, action) => {
|
||||
(state: IJwtState = {}, action) => {
|
||||
switch (action.type) {
|
||||
case SET_JWT: {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { type, ...payload } = action;
|
||||
const nextState = {
|
||||
...payload
|
|
@ -1,7 +1,6 @@
|
|||
// @flow
|
||||
|
||||
import { APP_WILL_MOUNT } from '../app/actionTypes';
|
||||
import { PersistenceRegistry, ReducerRegistry } from '../redux';
|
||||
import PersistenceRegistry from '../redux/PersistenceRegistry';
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
|
||||
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
||||
|
||||
|
@ -26,7 +25,7 @@ const STORE_NAME = 'features/base/known-domains';
|
|||
|
||||
PersistenceRegistry.register(STORE_NAME);
|
||||
|
||||
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
||||
ReducerRegistry.register(STORE_NAME, (state: Array<string> = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ADD_KNOWN_DOMAINS:
|
||||
return _addKnownDomains(state, action.knownDomains);
|
||||
|
@ -50,7 +49,7 @@ ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
|||
* @private
|
||||
* @returns {Object} The next redux state.
|
||||
*/
|
||||
function _addKnownDomains(state, knownDomains) {
|
||||
function _addKnownDomains(state: Array<string>, knownDomains: Array<string>) {
|
||||
// In case persistence has deserialized a weird redux state:
|
||||
let nextState = Array.isArray(state) ? state : [];
|
||||
|
|
@ -1,12 +1,23 @@
|
|||
/* eslint-disable lines-around-comment */
|
||||
import {
|
||||
SET_CONFIG
|
||||
} from '../config';
|
||||
import { ReducerRegistry, set } from '../redux';
|
||||
} from '../config/actionTypes';
|
||||
import { IConfig } from '../config/configType';
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
import { set } from '../redux/functions';
|
||||
|
||||
import { SET_LAST_N } from './actionTypes';
|
||||
// @ts-ignore
|
||||
import { validateLastNLimits } from './functions';
|
||||
|
||||
ReducerRegistry.register('features/base/lastn', (state = { }, action) => {
|
||||
export interface ILastNState {
|
||||
lastNLimits?: {
|
||||
[key: number]: number;
|
||||
};
|
||||
lastN?: number;
|
||||
}
|
||||
|
||||
ReducerRegistry.register('features/base/lastn', (state: ILastNState = { }, action) => {
|
||||
switch (action.type) {
|
||||
case SET_CONFIG:
|
||||
return _setConfig(state, action);
|
||||
|
@ -31,6 +42,6 @@ ReducerRegistry.register('features/base/lastn', (state = { }, action) => {
|
|||
* @private
|
||||
* @returns {Object} The new state after the reduction of the specified action.
|
||||
*/
|
||||
function _setConfig(state, { config }) {
|
||||
function _setConfig(state: ILastNState, { config }: {config: IConfig}) {
|
||||
return set(state, 'lastNLimits', validateLastNLimits(config.lastNLimits));
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
// @flow
|
||||
|
||||
import { ReducerRegistry } from '../redux';
|
||||
import ReducerRegistry from '../redux/ReducerRegistry';
|
||||
|
||||
import {
|
||||
LIB_DID_DISPOSE,
|
||||
|
@ -15,9 +13,14 @@ import {
|
|||
*/
|
||||
const DEFAULT_STATE = {};
|
||||
|
||||
export interface ILibJitsiMeetState {
|
||||
initError?: Error;
|
||||
initialized?: boolean;
|
||||
}
|
||||
|
||||
ReducerRegistry.register(
|
||||
'features/base/lib-jitsi-meet',
|
||||
(state = DEFAULT_STATE, action) => {
|
||||
(state: ILibJitsiMeetState = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case LIB_DID_DISPOSE:
|
||||
return DEFAULT_STATE;
|
Loading…
Reference in New Issue