Browse Source

Coding style

master
Lyubo Marinov 7 years ago
parent
commit
7954d5fd39

+ 6
- 4
react/features/app/components/AbstractApp.js View File

12
     localParticipantJoined,
12
     localParticipantJoined,
13
     localParticipantLeft
13
     localParticipantLeft
14
 } from '../../base/participants';
14
 } from '../../base/participants';
15
+import { getProfile } from '../../base/profile';
15
 import { Fragment, RouteRegistry } from '../../base/react';
16
 import { Fragment, RouteRegistry } from '../../base/react';
16
 import {
17
 import {
17
     MiddlewareRegistry,
18
     MiddlewareRegistry,
18
     PersistencyRegistry,
19
     PersistencyRegistry,
19
     ReducerRegistry
20
     ReducerRegistry
20
 } from '../../base/redux';
21
 } from '../../base/redux';
21
-import { getProfile } from '../../base/profile';
22
 import { toURLString } from '../../base/util';
22
 import { toURLString } from '../../base/util';
23
 import { OverlayContainer } from '../../overlay';
23
 import { OverlayContainer } from '../../overlay';
24
 import { BlankPage } from '../../welcome';
24
 import { BlankPage } from '../../welcome';
346
             middleware = compose(middleware, devToolsExtension());
346
             middleware = compose(middleware, devToolsExtension());
347
         }
347
         }
348
 
348
 
349
-        return createStore(
350
-            reducer, PersistencyRegistry.getPersistedState(), middleware
351
-        );
349
+        return (
350
+            createStore(
351
+                reducer,
352
+                PersistencyRegistry.getPersistedState(),
353
+                middleware));
352
     }
354
     }
353
 
355
 
354
     /**
356
     /**

+ 2
- 4
react/features/base/profile/reducer.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import {
4
-    PROFILE_UPDATED
5
-} from './actionTypes';
6
-
7
 import { PersistencyRegistry, ReducerRegistry } from '../redux';
3
 import { PersistencyRegistry, ReducerRegistry } from '../redux';
8
 
4
 
5
+import { PROFILE_UPDATED } from './actionTypes';
6
+
9
 const DEFAULT_STATE = {
7
 const DEFAULT_STATE = {
10
     profile: {}
8
     profile: {}
11
 };
9
 };

+ 2
- 0
react/features/base/react/prop-types-polyfill.js View File

2
 import PropTypes from 'prop-types';
2
 import PropTypes from 'prop-types';
3
 
3
 
4
 /* eslint-disable react/no-deprecated */
4
 /* eslint-disable react/no-deprecated */
5
+
5
 if (typeof React.PropTypes === 'undefined') {
6
 if (typeof React.PropTypes === 'undefined') {
6
     React.PropTypes = PropTypes;
7
     React.PropTypes = PropTypes;
7
 }
8
 }
9
+
8
 /* eslint-enable react/no-deprecated */
10
 /* eslint-enable react/no-deprecated */

+ 32
- 30
react/features/base/redux/PersistencyRegistry.js View File

1
 // @flow
1
 // @flow
2
+
2
 import Logger from 'jitsi-meet-logger';
3
 import Logger from 'jitsi-meet-logger';
3
 import md5 from 'js-md5';
4
 import md5 from 'js-md5';
4
 
5
 
15
 declare type PersistencyConfigMap = { [name: string]: Object };
16
 declare type PersistencyConfigMap = { [name: string]: Object };
16
 
17
 
17
 /**
18
 /**
18
- * A registry to allow features to register their redux store
19
- * subtree to be persisted and also handles the persistency calls too.
19
+ * A registry to allow features to register their redux store subtree to be
20
+ * persisted and also handles the persistency calls too.
20
  */
21
  */
21
 class PersistencyRegistry {
22
 class PersistencyRegistry {
22
     _checksum: string;
23
     _checksum: string;
24
+
23
     _elements: PersistencyConfigMap;
25
     _elements: PersistencyConfigMap;
24
 
26
 
25
     /**
27
     /**
26
-     * Initiates the PersistencyRegistry.
28
+     * Initializes a new {@ code PersistencyRegistry} instance.
27
      */
29
      */
28
     constructor() {
30
     constructor() {
29
         this._elements = {};
31
         this._elements = {};
30
     }
32
     }
31
 
33
 
32
     /**
34
     /**
33
-     * Returns the persisted redux state. This function takes
34
-     * the PersistencyRegistry._elements into account as we may have
35
-     * persisted something in the past that we don't want to retreive anymore.
36
-     * The next {@link #persistState} will remove those values.
35
+     * Returns the persisted redux state. This function takes the
36
+     * {@link #_elements} into account as we may have persisted something in the
37
+     * past that we don't want to retreive anymore. The next
38
+     * {@link #persistState} will remove those values.
37
      *
39
      *
38
      * @returns {Object}
40
      * @returns {Object}
39
      */
41
      */
46
                 persistedState = JSON.parse(persistedState);
48
                 persistedState = JSON.parse(persistedState);
47
             } catch (error) {
49
             } catch (error) {
48
                 logger.error(
50
                 logger.error(
49
-                    'Error parsing persisted state', persistedState, error
50
-                );
51
+                    'Error parsing persisted state',
52
+                    persistedState,
53
+                    error);
51
                 persistedState = {};
54
                 persistedState = {};
52
             }
55
             }
53
 
56
 
56
         }
59
         }
57
 
60
 
58
         this._checksum = this._calculateChecksum(filteredPersistedState);
61
         this._checksum = this._calculateChecksum(filteredPersistedState);
59
-        logger.info('Redux state rehydrated as', filteredPersistedState);
62
+        logger.info('redux state rehydrated as', filteredPersistedState);
60
 
63
 
61
         return filteredPersistedState;
64
         return filteredPersistedState;
62
     }
65
     }
63
 
66
 
64
     /**
67
     /**
65
-     * Initiates a persist operation, but its execution will depend on
66
-     * the current checksums (checks changes).
68
+     * Initiates a persist operation, but its execution will depend on the
69
+     * current checksums (checks changes).
67
      *
70
      *
68
      * @param {Object} state - The redux state.
71
      * @param {Object} state - The redux state.
69
      * @returns {void}
72
      * @returns {void}
76
             try {
79
             try {
77
                 window.localStorage.setItem(
80
                 window.localStorage.setItem(
78
                     PERSISTED_STATE_NAME,
81
                     PERSISTED_STATE_NAME,
79
-                    JSON.stringify(filteredState)
80
-                );
82
+                    JSON.stringify(filteredState));
81
                 logger.info(
83
                 logger.info(
82
-                    `Redux state persisted. ${this._checksum} -> ${newCheckSum}`
83
-                );
84
+                    `redux state persisted. ${this._checksum} -> ${
85
+                        newCheckSum}`);
84
                 this._checksum = newCheckSum;
86
                 this._checksum = newCheckSum;
85
             } catch (error) {
87
             } catch (error) {
86
-                logger.error('Error persisting Redux state', error);
88
+                logger.error('Error persisting redux state', error);
87
             }
89
             }
88
         }
90
         }
89
     }
91
     }
103
      * Calculates the checksum of the current or the new values of the state.
105
      * Calculates the checksum of the current or the new values of the state.
104
      *
106
      *
105
      * @private
107
      * @private
106
-     * @param {Object} filteredState - The filtered/persisted Redux state.
108
+     * @param {Object} filteredState - The filtered/persisted redux state.
107
      * @returns {string}
109
      * @returns {string}
108
      */
110
      */
109
     _calculateChecksum(filteredState: Object) {
111
     _calculateChecksum(filteredState: Object) {
111
             return md5.hex(JSON.stringify(filteredState) || '');
113
             return md5.hex(JSON.stringify(filteredState) || '');
112
         } catch (error) {
114
         } catch (error) {
113
             logger.error(
115
             logger.error(
114
-                'Error calculating checksum for state', filteredState, error
115
-            );
116
+                'Error calculating checksum for state',
117
+                filteredState,
118
+                error);
116
 
119
 
117
             return '';
120
             return '';
118
         }
121
         }
119
     }
122
     }
120
 
123
 
121
     /**
124
     /**
122
-     * Prepares a filtered state from the actual or the
123
-     * persisted Redux state, based on this registry.
125
+     * Prepares a filtered state from the actual or the persisted redux state,
126
+     * based on this registry.
124
      *
127
      *
125
      * @private
128
      * @private
126
      * @param {Object} state - The actual or persisted redux state.
129
      * @param {Object} state - The actual or persisted redux state.
131
 
134
 
132
         for (const name of Object.keys(this._elements)) {
135
         for (const name of Object.keys(this._elements)) {
133
             if (state[name]) {
136
             if (state[name]) {
134
-                filteredState[name] = this._getFilteredSubtree(
135
-                    state[name],
136
-                    this._elements[name]
137
-                );
137
+                filteredState[name]
138
+                    = this._getFilteredSubtree(
139
+                        state[name],
140
+                        this._elements[name]);
138
             }
141
             }
139
         }
142
         }
140
 
143
 
142
     }
145
     }
143
 
146
 
144
     /**
147
     /**
145
-     * Prepares a filtered subtree based on the config for
146
-     * persisting or for retreival.
148
+     * Prepares a filtered subtree based on the config for persisting or for
149
+     * retrieval.
147
      *
150
      *
148
      * @private
151
      * @private
149
      * @param {Object} subtree - The redux state subtree.
152
      * @param {Object} subtree - The redux state subtree.
155
 
158
 
156
         for (const persistedKey of Object.keys(subtree)) {
159
         for (const persistedKey of Object.keys(subtree)) {
157
             if (subtreeConfig[persistedKey]) {
160
             if (subtreeConfig[persistedKey]) {
158
-                filteredSubtree[persistedKey]
159
-                    = subtree[persistedKey];
161
+                filteredSubtree[persistedKey] = subtree[persistedKey];
160
             }
162
             }
161
         }
163
         }
162
 
164
 

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

1
-/* @flow */
1
+// @flow
2
 
2
 
3
 import _ from 'lodash';
3
 import _ from 'lodash';
4
 
4
 

+ 13
- 12
react/features/base/redux/middleware.js View File

1
-/* @flow */
1
+// @flow
2
+
2
 import _ from 'lodash';
3
 import _ from 'lodash';
3
 
4
 
5
+import { toState } from './functions';
4
 import MiddlewareRegistry from './MiddlewareRegistry';
6
 import MiddlewareRegistry from './MiddlewareRegistry';
5
 import PersistencyRegistry from './PersistencyRegistry';
7
 import PersistencyRegistry from './PersistencyRegistry';
6
 
8
 
7
-import { toState } from '../redux';
8
-
9
 /**
9
 /**
10
- * The delay that passes between the last state change and the state to be
11
- * persisted in the storage.
10
+ * The delay that passes between the last state change and the persisting of
11
+ * that state in the storage.
12
  */
12
  */
13
-const PERSIST_DELAY = 2000;
13
+const PERSIST_STATE_DELAY = 2000;
14
 
14
 
15
 /**
15
 /**
16
  * A throttled function to avoid repetitive state persisting.
16
  * A throttled function to avoid repetitive state persisting.
17
  */
17
  */
18
-const throttledFunc = _.throttle(state => {
19
-    PersistencyRegistry.persistState(state);
20
-}, PERSIST_DELAY);
18
+const throttledPersistState
19
+    = _.throttle(
20
+        state => PersistencyRegistry.persistState(state),
21
+        PERSIST_STATE_DELAY);
21
 
22
 
22
 /**
23
 /**
23
  * A master MiddleWare to selectively persist state. Please use the
24
  * A master MiddleWare to selectively persist state. Please use the
24
- * {@link persisterconfig.json} to set which subtrees of the Redux state
25
- * should be persisted.
25
+ * {@link persisterconfig.json} to set which subtrees of the Redux state should
26
+ * be persisted.
26
  *
27
  *
27
  * @param {Store} store - The redux store.
28
  * @param {Store} store - The redux store.
28
  * @returns {Function}
29
  * @returns {Function}
30
 MiddlewareRegistry.register(store => next => action => {
31
 MiddlewareRegistry.register(store => next => action => {
31
     const result = next(action);
32
     const result = next(action);
32
 
33
 
33
-    throttledFunc(toState(store));
34
+    throttledPersistState(toState(store));
34
 
35
 
35
     return result;
36
     return result;
36
 });
37
 });

+ 4
- 4
react/features/recent-list/actions.js View File

10
  *
10
  *
11
  * @param {Object} locationURL - The current location URL.
11
  * @param {Object} locationURL - The current location URL.
12
  * @returns {{
12
  * @returns {{
13
- *      type: STORE_CURRENT_CONFERENCE,
14
- *      locationURL: Object
13
+ *     type: STORE_CURRENT_CONFERENCE,
14
+ *     locationURL: Object
15
  * }}
15
  * }}
16
  */
16
  */
17
 export function storeCurrentConference(locationURL: Object) {
17
 export function storeCurrentConference(locationURL: Object) {
26
  *
26
  *
27
  * @param {Object} locationURL - The current location URL.
27
  * @param {Object} locationURL - The current location URL.
28
  * @returns {{
28
  * @returns {{
29
- *      type: UPDATE_CONFERENCE_DURATION,
30
- *      locationURL: Object
29
+ *     type: UPDATE_CONFERENCE_DURATION,
30
+ *     locationURL: Object
31
  * }}
31
  * }}
32
  */
32
  */
33
 export function updateConferenceDuration(locationURL: Object) {
33
 export function updateConferenceDuration(locationURL: Object) {

+ 6
- 7
react/features/recent-list/components/RecentList.native.js View File

2
 import { ListView, Text, TouchableHighlight, View } from 'react-native';
2
 import { ListView, Text, TouchableHighlight, View } from 'react-native';
3
 import { connect } from 'react-redux';
3
 import { connect } from 'react-redux';
4
 
4
 
5
-import AbstractRecentList, { _mapStateToProps } from './AbstractRecentList';
6
-import styles, { UNDERLAY_COLOR } from './styles';
5
+import { Icon } from '../../base/font-icons';
7
 
6
 
7
+import AbstractRecentList, { _mapStateToProps } from './AbstractRecentList';
8
 import { getRecentRooms } from '../functions';
8
 import { getRecentRooms } from '../functions';
9
-
10
-import { Icon } from '../../base/font-icons';
9
+import styles, { UNDERLAY_COLOR } from './styles';
11
 
10
 
12
 /**
11
 /**
13
  * The native container rendering the list of the recently joined rooms.
12
  * The native container rendering the list of the recently joined rooms.
52
             return null;
51
             return null;
53
         }
52
         }
54
 
53
 
55
-        const listViewDataSource = this.dataSource.cloneWithRows(
56
-            getRecentRooms(this.props._recentList)
57
-        );
54
+        const listViewDataSource
55
+            = this.dataSource.cloneWithRows(
56
+                getRecentRooms(this.props._recentList));
58
 
57
 
59
         return (
58
         return (
60
             <View style = { styles.container }>
59
             <View style = { styles.container }>

+ 13
- 15
react/features/recent-list/functions.js View File

2
 
2
 
3
 import moment from 'moment';
3
 import moment from 'moment';
4
 
4
 
5
-import { i18next } from '../base/i18n';
6
-import { parseURIString } from '../base/util';
7
-
8
-/**
9
- * MomentJS uses static language bundle loading, so in order to support dynamic
10
- * language selection in the app we need to load all bundles that we support in
11
- * the app.
12
- * FIXME: If we decide to support MomentJS in other features as well we may need
13
- * to move this import and the lenient matcher to the i18n feature.
14
- */
5
+// MomentJS uses static language bundle loading, so in order to support dynamic
6
+// language selection in the app we need to load all bundles that we support in
7
+// the app.
8
+// FIXME: If we decide to support MomentJS in other features as well we may need
9
+// to move this import and the lenient matcher to the i18n feature.
15
 require('moment/locale/bg');
10
 require('moment/locale/bg');
16
 require('moment/locale/de');
11
 require('moment/locale/de');
17
 require('moment/locale/eo');
12
 require('moment/locale/eo');
33
 require('moment/locale/tr');
28
 require('moment/locale/tr');
34
 require('moment/locale/zh-cn');
29
 require('moment/locale/zh-cn');
35
 
30
 
31
+import { i18next } from '../base/i18n';
32
+import { parseURIString } from '../base/util';
33
+
36
 /**
34
 /**
37
  * Retrieves the recent room list and generates all the data needed to be
35
  * Retrieves the recent room list and generates all the data needed to be
38
  * displayed.
36
  * displayed.
122
 }
120
 }
123
 
121
 
124
 /**
122
 /**
125
- * Returns a localized date formatter initialized with the provided date
126
- * (@code Date) or duration (@code number).
123
+ * Returns a localized date formatter initialized with a specific {@code Date}
124
+ * or duration ({@code number}).
127
  *
125
  *
128
  * @private
126
  * @private
129
  * @param {Date | number} dateOrDuration - The date or duration to format.
127
  * @param {Date | number} dateOrDuration - The date or duration to format.
130
- * @param {string} locale - The locale to init the formatter with. Note: This
131
- * locale must be supported by the formatter so ensure this prerequisite before
132
- * invoking the function.
128
+ * @param {string} locale - The locale to init the formatter with. Note: The
129
+ * specified locale must be supported by the formatter so ensure the
130
+ * prerequisite is met before invoking the function.
133
  * @returns {Object}
131
  * @returns {Object}
134
  */
132
  */
135
 function _getLocalizedFormatter(dateOrDuration: Date | number, locale: string) {
133
 function _getLocalizedFormatter(dateOrDuration: Date | number, locale: string) {

+ 5
- 5
react/features/recent-list/reducer.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
+import { PersistencyRegistry, ReducerRegistry } from '../base/redux';
4
+
3
 import {
5
 import {
4
     STORE_CURRENT_CONFERENCE,
6
     STORE_CURRENT_CONFERENCE,
5
     UPDATE_CONFERENCE_DURATION
7
     UPDATE_CONFERENCE_DURATION
6
 } from './actionTypes';
8
 } from './actionTypes';
7
 import { LIST_SIZE } from './constants';
9
 import { LIST_SIZE } from './constants';
8
 
10
 
9
-import { PersistencyRegistry, ReducerRegistry } from '../base/redux';
10
-
11
 /**
11
 /**
12
  * The initial state of this feature.
12
  * The initial state of this feature.
13
  */
13
  */
34
     switch (action.type) {
34
     switch (action.type) {
35
     case STORE_CURRENT_CONFERENCE:
35
     case STORE_CURRENT_CONFERENCE:
36
         return _storeCurrentConference(state, action);
36
         return _storeCurrentConference(state, action);
37
+
37
     case UPDATE_CONFERENCE_DURATION:
38
     case UPDATE_CONFERENCE_DURATION:
38
         return _updateConferenceDuration(state, action);
39
         return _updateConferenceDuration(state, action);
40
+
39
     default:
41
     default:
40
         return state;
42
         return state;
41
     }
43
     }
54
 
56
 
55
     // If the current conference is already in the list, we remove it to re-add
57
     // If the current conference is already in the list, we remove it to re-add
56
     // it to the top.
58
     // it to the top.
57
-    const list
58
-        = state.list
59
-            .filter(e => e.conference !== conference);
59
+    const list = state.list.filter(e => e.conference !== conference);
60
 
60
 
61
     // This is a reverse sorted array (i.e. newer elements at the end).
61
     // This is a reverse sorted array (i.e. newer elements at the end).
62
     list.push({
62
     list.push({

Loading…
Cancel
Save