Browse Source

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 years ago
parent
commit
bce1610794

+ 11
- 15
react/features/base/conference/reducer.js View File

1
 import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
1
 import { LOCKED_LOCALLY, LOCKED_REMOTELY } from '../../room-lock';
2
 
2
 
3
 import { JitsiConferenceErrors } from '../lib-jitsi-meet';
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
 import {
6
 import {
11
     CONFERENCE_FAILED,
7
     CONFERENCE_FAILED,
80
             : undefined;
76
             : undefined;
81
 
77
 
82
     return (
78
     return (
83
-        setStateProperties(state, {
79
+        assign(state, {
84
             audioOnly: undefined,
80
             audioOnly: undefined,
85
             audioOnlyVideoMuted: undefined,
81
             audioOnlyVideoMuted: undefined,
86
             conference: undefined,
82
             conference: undefined,
125
     const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
121
     const locked = conference.room.locked ? LOCKED_REMOTELY : undefined;
126
 
122
 
127
     return (
123
     return (
128
-        setStateProperties(state, {
124
+        assign(state, {
129
             /**
125
             /**
130
              * The JitsiConference instance represented by the Redux state of
126
              * The JitsiConference instance represented by the Redux state of
131
              * the feature base/conference.
127
              * the feature base/conference.
163
     }
159
     }
164
 
160
 
165
     return (
161
     return (
166
-        setStateProperties(state, {
162
+        assign(state, {
167
             audioOnly: undefined,
163
             audioOnly: undefined,
168
             audioOnlyVideoMuted: undefined,
164
             audioOnlyVideoMuted: undefined,
169
             conference: undefined,
165
             conference: undefined,
192
     }
188
     }
193
 
189
 
194
     return (
190
     return (
195
-        setStateProperties(state, {
191
+        assign(state, {
196
             /**
192
             /**
197
              * The JitsiConference instance which is currently in the process of
193
              * The JitsiConference instance which is currently in the process of
198
              * being left.
194
              * being left.
225
         locked = state.locked || LOCKED_REMOTELY;
221
         locked = state.locked || LOCKED_REMOTELY;
226
     }
222
     }
227
 
223
 
228
-    return setStateProperties(state, {
224
+    return assign(state, {
229
         locked,
225
         locked,
230
         password: action.locked ? state.password : null
226
         password: action.locked ? state.password : null
231
     });
227
     });
242
  * reduction of the specified action.
238
  * reduction of the specified action.
243
  */
239
  */
244
 function _setAudioOnly(state, action) {
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
  * reduction of the specified action.
253
  * reduction of the specified action.
258
  */
254
  */
259
 function _setAudioOnlyVideoMuted(state, action) {
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
     case conference.join:
272
     case conference.join:
277
         if (state.passwordRequired === conference) {
273
         if (state.passwordRequired === conference) {
278
             return (
274
             return (
279
-                setStateProperties(state, {
275
+                assign(state, {
280
                     locked: LOCKED_REMOTELY,
276
                     locked: LOCKED_REMOTELY,
281
 
277
 
282
                     /**
278
                     /**
291
         break;
287
         break;
292
 
288
 
293
     case conference.lock:
289
     case conference.lock:
294
-        return setStateProperties(state, {
290
+        return assign(state, {
295
             locked: action.password ? LOCKED_LOCALLY : undefined,
291
             locked: action.password ? LOCKED_LOCALLY : undefined,
296
             password: action.password
292
             password: action.password
297
         });
293
         });
324
      *
320
      *
325
      * @type {string}
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 View File

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

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
 ReducerRegistry.register('features/base/dialog', (state = {}, action) => {
14
 ReducerRegistry.register('features/base/dialog', (state = {}, action) => {
17
     switch (action.type) {
15
     switch (action.type) {
18
     case HIDE_DIALOG:
16
     case HIDE_DIALOG:
19
-        return setStateProperties(state, {
17
+        return assign(state, {
20
             component: undefined,
18
             component: undefined,
21
             componentProps: undefined
19
             componentProps: undefined
22
         });
20
         });
21
+
23
     case OPEN_DIALOG:
22
     case OPEN_DIALOG:
24
-        return setStateProperties(state, {
23
+        return assign(state, {
25
             component: action.component,
24
             component: action.component,
26
             componentProps: action.componentProps
25
             componentProps: action.componentProps
27
         });
26
         });

+ 9
- 9
react/features/base/lib-jitsi-meet/functions.js View File

70
  * @returns {Promise<JitsiLocalTrack>}
70
  * @returns {Promise<JitsiLocalTrack>}
71
  */
71
  */
72
 export function createLocalTrack(type, deviceId) {
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 View File

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

+ 3
- 10
react/features/base/participants/reducer.js View File

1
-import { ReducerRegistry, setStateProperty } from '../redux';
1
+import { ReducerRegistry, set } from '../redux';
2
 import { randomHexString } from '../util';
2
 import { randomHexString } from '../util';
3
 
3
 
4
 import {
4
 import {
55
     case DOMINANT_SPEAKER_CHANGED:
55
     case DOMINANT_SPEAKER_CHANGED:
56
         // Only one dominant speaker is allowed.
56
         // Only one dominant speaker is allowed.
57
         return (
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
     case PARTICIPANT_ID_CHANGED:
60
     case PARTICIPANT_ID_CHANGED:
64
         if (state.id === action.oldValue) {
61
         if (state.id === action.oldValue) {
145
 
142
 
146
     case PIN_PARTICIPANT:
143
     case PIN_PARTICIPANT:
147
         // Currently, only one pinned participant is allowed.
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
     return state;
148
     return state;

+ 5
- 5
react/features/base/redux/functions.js View File

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

+ 7
- 15
react/features/overlay/reducer.js View File

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

Loading…
Cancel
Save