Pārlūkot izejas kodu

[RN] Clarify, simplify the source code

master
Lyubomir Marinov 8 gadus atpakaļ
vecāks
revīzija
51a1a7ed22

+ 9
- 15
react/features/app/reducer.js Parādīt failu

@@ -2,25 +2,19 @@ import { ReducerRegistry } from '../base/redux';
2 2
 
3 3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
4 4
 
5
-/**
6
- * The initial Redux state of features/app.
7
- */
8
-const INITIAL_STATE = {
9
-    /**
10
-     * The one and only (i.e. singleton) App instance which is currently
11
-     * mounted.
12
-     *
13
-     * @type {App}
14
-     */
15
-    app: undefined
16
-};
17
-
18
-ReducerRegistry.register('features/app', (state = INITIAL_STATE, action) => {
5
+ReducerRegistry.register('features/app', (state = {}, action) => {
19 6
     switch (action.type) {
20 7
     case APP_WILL_MOUNT:
21 8
         if (state.app !== action.app) {
22 9
             return {
23 10
                 ...state,
11
+
12
+                /**
13
+                 * The one and only (i.e. singleton) App instance which is
14
+                 * currently mounted.
15
+                 *
16
+                 * @type {App}
17
+                 */
24 18
                 app: action.app
25 19
             };
26 20
         }
@@ -30,7 +24,7 @@ ReducerRegistry.register('features/app', (state = INITIAL_STATE, action) => {
30 24
         if (state.app === action.app) {
31 25
             return {
32 26
                 ...state,
33
-                app: INITIAL_STATE.app
27
+                app: undefined
34 28
             };
35 29
         }
36 30
         break;

+ 6
- 8
react/features/base/lib-jitsi-meet/functions.js Parādīt failu

@@ -4,11 +4,11 @@ import { loadScript } from '../../base/util';
4 4
  * Loads config.js file from remote server.
5 5
  *
6 6
  * @param {string} host - Host where config.js is hosted.
7
- * @param {string} configLocation='/config.js' - Relative pah to config.js file.
7
+ * @param {string} path='/config.js' - Relative pah to config.js file.
8 8
  * @returns {Promise<Object>}
9 9
  */
10
-export function loadConfig(host, configLocation = '/config.js') {
11
-    return loadScript(new URL(configLocation, host).toString())
10
+export function loadConfig(host, path = '/config.js') {
11
+    return loadScript(new URL(path, host).toString())
12 12
         .then(() => {
13 13
             const config = window.config;
14 14
 
@@ -21,11 +21,9 @@ export function loadConfig(host, configLocation = '/config.js') {
21 21
 
22 22
             return config;
23 23
         })
24
-        .catch(error => {
25
-            console.error(
26
-                    `Failed to load ${configLocation} from ${host}`,
27
-                    error);
24
+        .catch(err => {
25
+            console.error(`Failed to load ${path} from ${host}`, err);
28 26
 
29
-            throw error;
27
+            throw err;
30 28
         });
31 29
 }

+ 23
- 7
react/features/base/lib-jitsi-meet/reducer.js Parādīt failu

@@ -59,15 +59,31 @@ ReducerRegistry.register(
59 59
             };
60 60
 
61 61
         case SET_CONFIG:
62
-            return {
63
-                ...state,
64
-                config: {
65
-                    ...action.config,
66
-                    ...state.config
67
-                }
68
-            };
62
+            return _setConfig(state, action);
69 63
 
70 64
         default:
71 65
             return state;
72 66
         }
73 67
     });
68
+
69
+/**
70
+ * Reduces a specific Redux action SET_CONFIG of the feature
71
+ * base/lib-jitsi-meet.
72
+ *
73
+ * @param {Object} state - The Redux state of the feature base/lib-jitsi-meet.
74
+ * @param {Action} action - The Redux action SET_CONFIG to reduce.
75
+ * @private
76
+ * @returns {Object} The new state of the feature base/lib-jitsi-meet after the
77
+ * reduction of the specified action.
78
+ */
79
+function _setConfig(state, action) {
80
+    return {
81
+        ...state,
82
+        config: {
83
+            // The final config is the result of augmenting the default config
84
+            // with whatever the deployment has chosen to override/overwrite.
85
+            ...INITIAL_STATE.config,
86
+            ...action.config
87
+        }
88
+    };
89
+}

Notiek ielāde…
Atcelt
Saglabāt