ソースを参照

[RN] Clarify, simplify the source code

master
Lyubomir Marinov 8年前
コミット
51a1a7ed22

+ 9
- 15
react/features/app/reducer.js ファイルの表示

2
 
2
 
3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
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
     switch (action.type) {
6
     switch (action.type) {
20
     case APP_WILL_MOUNT:
7
     case APP_WILL_MOUNT:
21
         if (state.app !== action.app) {
8
         if (state.app !== action.app) {
22
             return {
9
             return {
23
                 ...state,
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
                 app: action.app
18
                 app: action.app
25
             };
19
             };
26
         }
20
         }
30
         if (state.app === action.app) {
24
         if (state.app === action.app) {
31
             return {
25
             return {
32
                 ...state,
26
                 ...state,
33
-                app: INITIAL_STATE.app
27
+                app: undefined
34
             };
28
             };
35
         }
29
         }
36
         break;
30
         break;

+ 6
- 8
react/features/base/lib-jitsi-meet/functions.js ファイルの表示

4
  * Loads config.js file from remote server.
4
  * Loads config.js file from remote server.
5
  *
5
  *
6
  * @param {string} host - Host where config.js is hosted.
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
  * @returns {Promise<Object>}
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
         .then(() => {
12
         .then(() => {
13
             const config = window.config;
13
             const config = window.config;
14
 
14
 
21
 
21
 
22
             return config;
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 ファイルの表示

59
             };
59
             };
60
 
60
 
61
         case SET_CONFIG:
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
         default:
64
         default:
71
             return state;
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
+}

読み込み中…
キャンセル
保存