瀏覽代碼

ref: Convert some reducers to TS (#11886)

factor2
Robert Pintilii 2 年之前
父節點
當前提交
c1e9724bba
No account linked to committer's email address

+ 7
- 2
react/features/app/types.ts 查看文件

@@ -12,9 +12,11 @@ import { IFlagsState } from '../base/flags/reducer';
12 12
 import { IJwtState } from '../base/jwt/reducer';
13 13
 import { ILastNState } from '../base/lastn/reducer';
14 14
 import { ILibJitsiMeetState } from '../base/lib-jitsi-meet/reducer';
15
+import { ILoggingState } from '../base/logging/reducer';
16
+import { IMediaState } from '../base/media/reducer';
17
+import { INetInfoState } from '../base/net-info/reducer';
15 18
 import { INoiseSuppressionState } from '../noise-suppression/reducer';
16 19
 
17
-
18 20
 export interface IStore {
19 21
     dispatch: Function,
20 22
     getState: Function
@@ -35,6 +37,9 @@ export interface IState {
35 37
     'features/base/jwt': IJwtState,
36 38
     'features/base/known-domains': Array<string>,
37 39
     'features/base/lastn': ILastNState,
38
-    'features/base/lib-jitsi-meet': ILibJitsiMeetState
40
+    'features/base/lib-jitsi-meet': ILibJitsiMeetState,
41
+    'features/base/logging': ILoggingState,
42
+    'features/base/media': IMediaState,
43
+    'features/base/net-info': INetInfoState,
39 44
     'features/noise-suppression': INoiseSuppressionState
40 45
 }

react/features/base/logging/reducer.js → react/features/base/logging/reducer.ts 查看文件

@@ -1,6 +1,5 @@
1
-// @flow
2
-
3
-import { equals, ReducerRegistry, set } from '../redux';
1
+import ReducerRegistry from '../redux/ReducerRegistry';
2
+import { equals, set } from '../redux/functions';
4 3
 
5 4
 import { SET_LOG_COLLECTOR, SET_LOGGING_CONFIG } from './actionTypes';
6 5
 
@@ -38,9 +37,23 @@ if (navigator.product === 'ReactNative') {
38 37
     };
39 38
 }
40 39
 
40
+type LogLevel = 'trace' | 'log' | 'info' | 'warn' | 'error';
41
+
42
+interface LoggingLevel {
43
+    [key: string]: LogLevel;
44
+}
45
+
46
+export interface ILoggingState {
47
+    config: LoggingLevel & {
48
+        defaultLogLevel: LogLevel;
49
+        disableLogCollector?: boolean;
50
+    };
51
+    logCollector?: Object;
52
+}
53
+
41 54
 ReducerRegistry.register(
42 55
     'features/base/logging',
43
-    (state = DEFAULT_STATE, action) => {
56
+    (state: ILoggingState = DEFAULT_STATE, action) => {
44 57
         switch (action.type) {
45 58
         case SET_LOGGING_CONFIG:
46 59
             return _setLoggingConfig(state, action);
@@ -63,7 +76,7 @@ ReducerRegistry.register(
63 76
  * @returns {Object} The new state of the feature base/logging after the
64 77
  * reduction of the specified action.
65 78
  */
66
-function _setLoggingConfig(state, action) {
79
+function _setLoggingConfig(state: ILoggingState, action: any) {
67 80
     const config = {
68 81
         // The config of DEFAULT_STATE is the default configuration of the
69 82
         // feature base/logging.
@@ -91,6 +104,6 @@ function _setLoggingConfig(state, action) {
91 104
  * @returns {Object} The new state of the feature base/logging after the
92 105
  * reduction of the specified action.
93 106
  */
94
-function _setLogCollector(state, action) {
107
+function _setLogCollector(state: ILoggingState, action: any) {
95 108
     return set(state, 'logCollector', action.logCollector);
96 109
 }

react/features/base/media/reducer.js → react/features/base/media/reducer.ts 查看文件

@@ -1,7 +1,7 @@
1 1
 import { combineReducers } from 'redux';
2 2
 
3 3
 import { CONFERENCE_FAILED, CONFERENCE_LEFT } from '../conference/actionTypes';
4
-import { ReducerRegistry } from '../redux';
4
+import ReducerRegistry from '../redux/ReducerRegistry';
5 5
 import { TRACK_REMOVED } from '../tracks/actionTypes';
6 6
 
7 7
 import {
@@ -49,7 +49,7 @@ export const _AUDIO_INITIAL_MEDIA_STATE = {
49 49
  * @private
50 50
  * @returns {AudioMediaState}
51 51
  */
52
-function _audio(state = _AUDIO_INITIAL_MEDIA_STATE, action) {
52
+function _audio(state: IAudioState = _AUDIO_INITIAL_MEDIA_STATE, action: any) {
53 53
     switch (action.type) {
54 54
     case SET_AUDIO_AVAILABLE:
55 55
         return {
@@ -103,7 +103,7 @@ export const _SCREENSHARE_INITIAL_MEDIA_STATE = {
103 103
  * @private
104 104
  * @returns {ScreenshareMediaState}
105 105
  */
106
-function _screenshare(state = _SCREENSHARE_INITIAL_MEDIA_STATE, action) {
106
+function _screenshare(state: IScreenshareState = _SCREENSHARE_INITIAL_MEDIA_STATE, action: any) {
107 107
     switch (action.type) {
108 108
     case SET_SCREENSHARE_MUTED:
109 109
         return {
@@ -161,7 +161,7 @@ export const _VIDEO_INITIAL_MEDIA_STATE = {
161 161
  * @private
162 162
  * @returns {VideoMediaState}
163 163
  */
164
-function _video(state = _VIDEO_INITIAL_MEDIA_STATE, action) {
164
+function _video(state: IVideoState = _VIDEO_INITIAL_MEDIA_STATE, action: any) {
165 165
     switch (action.type) {
166 166
     case CONFERENCE_FAILED:
167 167
     case CONFERENCE_LEFT:
@@ -216,6 +216,32 @@ function _video(state = _VIDEO_INITIAL_MEDIA_STATE, action) {
216 216
     }
217 217
 }
218 218
 
219
+interface IAudioState {
220
+    available: boolean;
221
+    muted: boolean;
222
+    unmuteBlocked: boolean;
223
+}
224
+
225
+interface IScreenshareState {
226
+    available: boolean;
227
+    muted: number;
228
+    unmuteBlocked: boolean;
229
+}
230
+
231
+interface IVideoState {
232
+    available: boolean;
233
+    facingMode: string;
234
+    muted: number;
235
+    transforms: Object;
236
+    unmuteBlocked: boolean;
237
+}
238
+
239
+export interface IMediaState {
240
+    audio: IAudioState;
241
+    screenshare: IScreenshareState;
242
+    video: IVideoState;
243
+}
244
+
219 245
 /**
220 246
  * Listen for various actions related to media devices.
221 247
  *
@@ -239,7 +265,7 @@ ReducerRegistry.register('features/base/media', combineReducers({
239 265
  * @private
240 266
  * @returns {Object}
241 267
  */
242
-function _clearAllVideoTransforms(state) {
268
+function _clearAllVideoTransforms(state: IVideoState) {
243 269
     return {
244 270
         ...state,
245 271
         transforms: _VIDEO_INITIAL_MEDIA_STATE.transforms
@@ -254,7 +280,7 @@ function _clearAllVideoTransforms(state) {
254 280
  * @private
255 281
  * @returns {Object}
256 282
  */
257
-function _storeVideoTransform(state, { streamId, transform }) {
283
+function _storeVideoTransform(state: IVideoState, { streamId, transform }: { streamId: string, transform: string }) {
258 284
     return {
259 285
         ...state,
260 286
         transforms: {
@@ -273,12 +299,12 @@ function _storeVideoTransform(state, { streamId, transform }) {
273 299
  * @private
274 300
  * @returns {Object}
275 301
  */
276
-function _trackRemoved(state, { track: { jitsiTrack } }) {
302
+function _trackRemoved(state: IVideoState, { track: { jitsiTrack } } : {track: {jitsiTrack: any}}) {
277 303
     if (jitsiTrack) {
278 304
         const streamId = jitsiTrack.getStreamId();
279 305
 
280 306
         if (streamId && streamId in state.transforms) {
281
-            const nextTransforms = {
307
+            const nextTransforms: any = {
282 308
                 ...state.transforms
283 309
             };
284 310
 

react/features/base/net-info/constants.js → react/features/base/net-info/constants.ts 查看文件


react/features/base/net-info/reducer.js → react/features/base/net-info/reducer.ts 查看文件

@@ -1,5 +1,7 @@
1
-// @flow
2
-import { assign, ReducerRegistry } from '../redux';
1
+import { NetInfoCellularGeneration, NetInfoStateType } from '@react-native-community/netinfo';
2
+
3
+import ReducerRegistry from '../redux/ReducerRegistry';
4
+import { assign } from '../redux/functions';
3 5
 
4 6
 import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes';
5 7
 import { STORE_NAME } from './constants';
@@ -8,10 +10,18 @@ const DEFAULT_STATE = {
8 10
     isOnline: true
9 11
 };
10 12
 
13
+export interface INetInfoState {
14
+    _cleanup?: Function;
15
+    cellularGeneration?: NetInfoCellularGeneration;
16
+    details?: Object;
17
+    isOnline?: boolean;
18
+    networkType?: NetInfoStateType;
19
+}
20
+
11 21
 /**
12 22
  * The base/net-info feature's reducer.
13 23
  */
14
-ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
24
+ReducerRegistry.register(STORE_NAME, (state: INetInfoState = DEFAULT_STATE, action) => {
15 25
     switch (action.type) {
16 26
     case SET_NETWORK_INFO:
17 27
         return assign(state, {

+ 1
- 2
react/features/noise-suppression/reducer.ts 查看文件

@@ -1,5 +1,4 @@
1
-// @ts-ignore
2
-import { ReducerRegistry } from '../base/redux';
1
+import ReducerRegistry from '../base/redux/ReducerRegistry';
3 2
 
4 3
 import {
5 4
     SET_NOISE_SUPPRESSION_ENABLED

Loading…
取消
儲存