Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

ref: Convert some reducers to TS (#11875)

Robert Pintilii449d52f26bef
diff --git a/react/features/app/types.ts b/react/features/app/types.ts
index 41ffe3bcba..e256eb3e3a 100644
--- a/react/features/app/types.ts
+++ b/react/features/app/types.ts
@@ -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
}
diff --git a/react/features/base/flags/reducer.js b/react/features/base/flags/reducer.ts
similarity index 77%
rename from react/features/base/flags/reducer.js
rename to react/features/base/flags/reducer.ts
index bbe8b1fc62..c683dd827b 100644
--- a/react/features/base/flags/reducer.js
+++ b/react/features/base/flags/reducer.ts
@@ -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);
diff --git a/react/features/base/jwt/reducer.js b/react/features/base/jwt/reducer.ts
similarity index 72%
rename from react/features/base/jwt/reducer.js
rename to react/features/base/jwt/reducer.ts
index 42b139ceb8..3d1eb2a427 100644
--- a/react/features/base/jwt/reducer.js
+++ b/react/features/base/jwt/reducer.ts
@@ -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
diff --git a/react/features/base/known-domains/reducer.js b/react/features/base/known-domains/reducer.ts
similarity index 87%
rename from react/features/base/known-domains/reducer.js
rename to react/features/base/known-domains/reducer.ts
index a4ccc86678..d20c51733f 100644
--- a/react/features/base/known-domains/reducer.js
+++ b/react/features/base/known-domains/reducer.ts
@@ -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 : [];
diff --git a/react/features/base/lastn/reducer.js b/react/features/base/lastn/reducer.ts
similarity index 59%
rename from react/features/base/lastn/reducer.js
rename to react/features/base/lastn/reducer.ts
index db76236d34..e4a63e478f 100644
--- a/react/features/base/lastn/reducer.js
+++ b/react/features/base/lastn/reducer.ts
@@ -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));
}
diff --git a/react/features/base/lib-jitsi-meet/reducer.js b/react/features/base/lib-jitsi-meet/reducer.ts
similarity index 78%
rename from react/features/base/lib-jitsi-meet/reducer.js
rename to react/features/base/lib-jitsi-meet/reducer.ts
index 3b17397aa9..a9645d8e7c 100644
--- a/react/features/base/lib-jitsi-meet/reducer.js
+++ b/react/features/base/lib-jitsi-meet/reducer.ts
@@ -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;