瀏覽代碼

Simplify, comply w/ coding style

Rename setStateProperties and setStateProperty to assign and set,
respectively. Inspired by Object.assign, _.assign, and _.set.
j8
Lyubo Marinov 8 年之前
父節點
當前提交
bce1610794

+ 11
- 15
react/features/base/conference/reducer.js 查看文件

@@ -1,11 +1,7 @@
1 1
 import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
2 2
 
3 3
 import { JitsiConferenceErrors } from '../lib-jitsi-meet';
4
-import {
5
-    ReducerRegistry,
6
-    setStateProperties,
7
-    setStateProperty
8
-} from '../redux';
4
+import { assign, ReducerRegistry, set } from '../redux';
9 5
 
10 6
 import {
11 7
     CONFERENCE_FAILED,
@@ -80,7 +76,7 @@ function _conferenceFailed(state, action) {
80 76
             : undefined;
81 77
 
82 78
     return (
83
-        setStateProperties(state, {
79
+        assign(state, {
84 80
             audioOnly: undefined,
85 81
             audioOnlyVideoMuted: undefined,
86 82
             conference: undefined,
@@ -125,7 +121,7 @@ function _conferenceJoined(state, action) {
125 121
     const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
126 122
 
127 123
     return (
128
-        setStateProperties(state, {
124
+        assign(state, {
129 125
             /**
130 126
              * The JitsiConference instance represented by the Redux state of
131 127
              * the feature base/conference.
@@ -163,7 +159,7 @@ function _conferenceLeft(state, action) {
163 159
     }
164 160
 
165 161
     return (
166
-        setStateProperties(state, {
162
+        assign(state, {
167 163
             audioOnly: undefined,
168 164
             audioOnlyVideoMuted: undefined,
169 165
             conference: undefined,
@@ -192,7 +188,7 @@ function _conferenceWillLeave(state, action) {
192 188
     }
193 189
 
194 190
     return (
195
-        setStateProperties(state, {
191
+        assign(state, {
196 192
             /**
197 193
              * The JitsiConference instance which is currently in the process of
198 194
              * being left.
@@ -225,7 +221,7 @@ function _lockStateChanged(state, action) {
225 221
         locked = state.locked || LOCKED_REMOTELY;
226 222
     }
227 223
 
228
-    return setStateProperties(state, {
224
+    return assign(state, {
229 225
         locked,
230 226
         password: action.locked ? state.password : null
231 227
     });
@@ -242,7 +238,7 @@ function _lockStateChanged(state, action) {
242 238
  * reduction of the specified action.
243 239
  */
244 240
 function _setAudioOnly(state, action) {
245
-    return setStateProperty(state, 'audioOnly', action.audioOnly);
241
+    return set(state, 'audioOnly', action.audioOnly);
246 242
 }
247 243
 
248 244
 /**
@@ -257,7 +253,7 @@ function _setAudioOnly(state, action) {
257 253
  * reduction of the specified action.
258 254
  */
259 255
 function _setAudioOnlyVideoMuted(state, action) {
260
-    return setStateProperty(state, 'audioOnlyVideoMuted', action.muted);
256
+    return set(state, 'audioOnlyVideoMuted', action.muted);
261 257
 }
262 258
 
263 259
 /**
@@ -276,7 +272,7 @@ function _setPassword(state, action) {
276 272
     case conference.join:
277 273
         if (state.passwordRequired === conference) {
278 274
             return (
279
-                setStateProperties(state, {
275
+                assign(state, {
280 276
                     locked: LOCKED_REMOTELY,
281 277
 
282 278
                     /**
@@ -291,7 +287,7 @@ function _setPassword(state, action) {
291 287
         break;
292 288
 
293 289
     case conference.lock:
294
-        return setStateProperties(state, {
290
+        return assign(state, {
295 291
             locked: action.password ? LOCKED_LOCALLY : undefined,
296 292
             password: action.password
297 293
         });
@@ -324,5 +320,5 @@ function _setRoom(state, action) {
324 320
      *
325 321
      * @type {string}
326 322
      */
327
-    return setStateProperty(state, 'room', room);
323
+    return set(state, 'room', room);
328 324
 }

+ 3
- 3
react/features/base/connection/reducer.js 查看文件

@@ -1,6 +1,6 @@
1 1
 /* @flow */
2 2
 
3
-import { ReducerRegistry, setStateProperty } from '../redux';
3
+import { ReducerRegistry, set } from '../redux';
4 4
 
5 5
 import {
6 6
     CONNECTION_DISCONNECTED,
@@ -40,7 +40,7 @@ ReducerRegistry.register(
40 40
  */
41 41
 function _connectionDisconnected(state: Object, action: Object) {
42 42
     if (state.connection === action.connection) {
43
-        return setStateProperty(state, 'connection', undefined);
43
+        return set(state, 'connection', undefined);
44 44
     }
45 45
 
46 46
     return state;
@@ -57,7 +57,7 @@ function _connectionDisconnected(state: Object, action: Object) {
57 57
  * reduction of the specified action.
58 58
  */
59 59
 function _connectionEstablished(state: Object, action: Object) {
60
-    return setStateProperty(state, 'connection', action.connection);
60
+    return set(state, 'connection', action.connection);
61 61
 }
62 62
 
63 63
 /**

+ 11
- 12
react/features/base/dialog/reducer.js 查看文件

@@ -1,27 +1,26 @@
1
-import { ReducerRegistry, setStateProperties } from '../redux';
1
+import { assign, ReducerRegistry } from '../redux';
2 2
 
3
-import {
4
-    HIDE_DIALOG,
5
-    OPEN_DIALOG
6
-} from './actionTypes';
3
+import { HIDE_DIALOG, OPEN_DIALOG } from './actionTypes';
7 4
 
8 5
 /**
9
- * Listen for actions which show or hide dialogs.
6
+ * Reduces redux actions which show or hide dialogs.
10 7
  *
11
- * @param {Object[]} state - Current state.
12
- * @param {Object} action - Action object.
13
- * @param {string} action.type - Type of action.
14
- * @returns {{}}
8
+ * @param {State} state - The current redux state.
9
+ * @param {Action} action - The redux action to reduce.
10
+ * @param {string} action.type - The type of the redux action to reduce..
11
+ * @returns {State} The next redux state that is the result of reducing the
12
+ * specified action.
15 13
  */
16 14
 ReducerRegistry.register('features/base/dialog', (state = {}, action) => {
17 15
     switch (action.type) {
18 16
     case HIDE_DIALOG:
19
-        return setStateProperties(state, {
17
+        return assign(state, {
20 18
             component: undefined,
21 19
             componentProps: undefined
22 20
         });
21
+
23 22
     case OPEN_DIALOG:
24
-        return setStateProperties(state, {
23
+        return assign(state, {
25 24
             component: action.component,
26 25
             componentProps: action.componentProps
27 26
         });

+ 9
- 9
react/features/base/lib-jitsi-meet/functions.js 查看文件

@@ -70,14 +70,14 @@ export function loadConfig(host: string, path: string = '/config.js') {
70 70
  * @returns {Promise<JitsiLocalTrack>}
71 71
  */
72 72
 export function createLocalTrack(type, deviceId) {
73
-    return JitsiMeetJS
74
-        .createLocalTracks({
75
-            devices: [ type ],
76
-            micDeviceId: deviceId,
77
-            cameraDeviceId: deviceId,
73
+    return JitsiMeetJS.createLocalTracks({
74
+        cameraDeviceId: deviceId,
75
+        devices: [ type ],
78 76
 
79
-            // eslint-disable-next-line camelcase
80
-            firefox_fake_device: window.config
81
-                && window.config.firefox_fake_device
82
-        }).then(([ jitsiLocalTrack ]) => jitsiLocalTrack);
77
+        // eslint-disable-next-line camelcase
78
+        firefox_fake_device:
79
+            window.config && window.config.firefox_fake_device,
80
+        micDeviceId: deviceId
81
+    })
82
+        .then(([ jitsiLocalTrack ]) => jitsiLocalTrack);
83 83
 }

+ 6
- 7
react/features/base/lib-jitsi-meet/middleware.js 查看文件

@@ -12,8 +12,8 @@ import { WEBRTC_NOT_READY, WEBRTC_NOT_SUPPORTED } from './constants';
12 12
  * lib-jitsi-meet, and initializes a new one with new config.
13 13
  *
14 14
  * @param {Store} store - Redux store.
15
- * @returns {Function}
16 15
  * @private
16
+ * @returns {Function}
17 17
  */
18 18
 MiddlewareRegistry.register(store => next => action => {
19 19
     switch (action.type) {
@@ -45,14 +45,14 @@ MiddlewareRegistry.register(store => next => action => {
45 45
  * specified action to the specified store.
46 46
  * @param {Action} action - The Redux action LIB_INIT_ERROR which is being
47 47
  * dispatched in the specified store.
48
+ * @private
48 49
  * @returns {Object} The new state that is the result of the reduction of the
49 50
  * specified action.
50
- * @private
51 51
  */
52 52
 function _libInitError(store, next, action) {
53 53
     const nextState = next(action);
54 54
 
55
-    const error = action.error;
55
+    const { error } = action;
56 56
 
57 57
     if (error) {
58 58
         let webRTCReady;
@@ -83,16 +83,15 @@ function _libInitError(store, next, action) {
83 83
  * specified action to the specified store.
84 84
  * @param {Action} action - The Redux action SET_CONFIG which is being
85 85
  * dispatched in the specified store.
86
+ * @private
86 87
  * @returns {Object} The new state that is the result of the reduction of the
87 88
  * specified action.
88
- * @private
89 89
  */
90
-function _setConfig(store, next, action) {
91
-    const { dispatch, getState } = store;
90
+function _setConfig({ dispatch, getState }, next, action) {
92 91
     const { initialized } = getState()['features/base/lib-jitsi-meet'];
93 92
 
94 93
     // XXX Since the config is changing, the library lib-jitsi-meet must be
95
-    // initialized again with the new config. Consequntly, it may need to be
94
+    // initialized again with the new config. Consequently, it may need to be
96 95
     // disposed of first.
97 96
     // TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet
98 97
     // because lib-jitsi-meet does not implement such functionality.

+ 3
- 10
react/features/base/participants/reducer.js 查看文件

@@ -1,4 +1,4 @@
1
-import { ReducerRegistry, setStateProperty } from '../redux';
1
+import { ReducerRegistry, set } from '../redux';
2 2
 import { randomHexString } from '../util';
3 3
 
4 4
 import {
@@ -55,10 +55,7 @@ function _participant(state, action) {
55 55
     case DOMINANT_SPEAKER_CHANGED:
56 56
         // Only one dominant speaker is allowed.
57 57
         return (
58
-            setStateProperty(
59
-                    state,
60
-                    'dominantSpeaker',
61
-                    state.id === action.participant.id));
58
+            set(state, 'dominantSpeaker', state.id === action.participant.id));
62 59
 
63 60
     case PARTICIPANT_ID_CHANGED:
64 61
         if (state.id === action.oldValue) {
@@ -145,11 +142,7 @@ function _participant(state, action) {
145 142
 
146 143
     case PIN_PARTICIPANT:
147 144
         // Currently, only one pinned participant is allowed.
148
-        return (
149
-            setStateProperty(
150
-                    state,
151
-                    'pinned',
152
-                    state.id === action.participant.id));
145
+        return set(state, 'pinned', state.id === action.participant.id);
153 146
     }
154 147
 
155 148
     return state;

+ 5
- 5
react/features/base/redux/functions.js 查看文件

@@ -11,11 +11,11 @@
11 11
  * from the specified target by setting the specified properties to the
12 12
  * specified values.
13 13
  */
14
-export function setStateProperties(target, source) {
14
+export function assign(target, source) {
15 15
     let t = target;
16 16
 
17 17
     for (const property in source) { // eslint-disable-line guard-for-in
18
-        t = setStateProperty(t, property, source[property], t === target);
18
+        t = set(t, property, source[property], t === target);
19 19
     }
20 20
 
21 21
     return t;
@@ -37,8 +37,8 @@ export function setStateProperties(target, source) {
37 37
  * constructed from the specified <tt>state</tt> by setting the specified
38 38
  * <tt>property</tt> to the specified <tt>value</tt>.
39 39
  */
40
-export function setStateProperty(state, property, value) {
41
-    return _setStateProperty(state, property, value, /* copyOnWrite */ true);
40
+export function set(state, property, value) {
41
+    return _set(state, property, value, /* copyOnWrite */ true);
42 42
 }
43 43
 
44 44
 /* eslint-disable max-params */
@@ -62,7 +62,7 @@ export function setStateProperty(state, property, value) {
62 62
  * <tt>state</tt> by setting the specified <tt>property</tt> to the specified
63 63
  * <tt>value</tt>.
64 64
  */
65
-function _setStateProperty(state, property, value, copyOnWrite) {
65
+function _set(state, property, value, copyOnWrite) {
66 66
     // Delete state properties that are to be set to undefined. (It is a matter
67 67
     // of personal preference, mostly.)
68 68
     if (typeof value === 'undefined'

+ 7
- 15
react/features/overlay/reducer.js 查看文件

@@ -1,18 +1,11 @@
1 1
 import { CONFERENCE_FAILED } from '../base/conference';
2
-import {
3
-    CONNECTION_ESTABLISHED,
4
-    CONNECTION_FAILED
5
-} from '../base/connection';
2
+import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection';
6 3
 import {
7 4
     isFatalJitsiConnectionError,
8 5
     JitsiConferenceErrors,
9 6
     JitsiConnectionErrors
10 7
 } from '../base/lib-jitsi-meet';
11
-import {
12
-    ReducerRegistry,
13
-    setStateProperties,
14
-    setStateProperty
15
-} from '../base/redux';
8
+import { assign, ReducerRegistry, set } from '../base/redux';
16 9
 
17 10
 import {
18 11
     MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
@@ -59,7 +52,7 @@ function _conferenceFailed(state, action) {
59 52
 
60 53
     if (error === JitsiConferenceErrors.FOCUS_LEFT
61 54
             || error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE) {
62
-        return setStateProperties(state, {
55
+        return assign(state, {
63 56
             haveToReload: true,
64 57
             isNetworkFailure: false,
65 58
             reason: action.errorMessage
@@ -79,7 +72,7 @@ function _conferenceFailed(state, action) {
79 72
  * @private
80 73
  */
81 74
 function _connectionEstablished(state) {
82
-    return setStateProperty(state, 'connectionEstablished', true);
75
+    return set(state, 'connectionEstablished', true);
83 76
 }
84 77
 
85 78
 /**
@@ -99,10 +92,9 @@ function _connectionFailed(state, action) {
99 92
 
100 93
         logger.error(`XMPP connection error: ${errorMessage}`);
101 94
 
102
-        return setStateProperties(state, {
95
+        return assign(state, {
103 96
             haveToReload: true,
104 97
 
105
-
106 98
             // From all of the cases above only CONNECTION_DROPPED_ERROR is
107 99
             // considered a network type of failure.
108 100
             isNetworkFailure:
@@ -125,7 +117,7 @@ function _connectionFailed(state, action) {
125 117
  * @private
126 118
  */
127 119
 function _mediaPermissionPromptVisibilityChanged(state, action) {
128
-    return setStateProperties(state, {
120
+    return assign(state, {
129 121
         browser: action.browser,
130 122
         isMediaPermissionPromptVisible: action.isVisible
131 123
     });
@@ -140,5 +132,5 @@ function _mediaPermissionPromptVisibilityChanged(state, action) {
140 132
  * @private
141 133
  */
142 134
 function _suspendDetected(state) {
143
-    return setStateProperty(state, 'suspendDetected', true);
135
+    return set(state, 'suspendDetected', true);
144 136
 }

Loading…
取消
儲存