소스 검색

Remove duplication

master
Lyubo Marinov 7 년 전
부모
커밋
6545a7a1bb

+ 2
- 2
react/features/app/components/AbstractApp.js 파일 보기

93
      * @inheritdoc
93
      * @inheritdoc
94
      */
94
      */
95
     componentWillMount() {
95
     componentWillMount() {
96
-        const dispatch = this._getStore().dispatch;
96
+        const { dispatch } = this._getStore();
97
 
97
 
98
         dispatch(appWillMount(this));
98
         dispatch(appWillMount(this));
99
 
99
 
163
      * @inheritdoc
163
      * @inheritdoc
164
      */
164
      */
165
     componentWillUnmount() {
165
     componentWillUnmount() {
166
-        const dispatch = this._getStore().dispatch;
166
+        const { dispatch } = this._getStore();
167
 
167
 
168
         dispatch(localParticipantLeft());
168
         dispatch(localParticipantLeft());
169
 
169
 

+ 3
- 6
react/features/app/functions.native.js 파일 보기

2
 
2
 
3
 import { isRoomValid } from '../base/conference';
3
 import { isRoomValid } from '../base/conference';
4
 import { RouteRegistry } from '../base/react';
4
 import { RouteRegistry } from '../base/react';
5
+import { toState } from '../base/redux';
5
 import { Conference } from '../conference';
6
 import { Conference } from '../conference';
6
 import { Entryway } from '../welcome';
7
 import { Entryway } from '../welcome';
7
 
8
 
14
  * @returns {Route}
15
  * @returns {Route}
15
  */
16
  */
16
 export function _getRouteToRender(stateOrGetState: Object | Function) {
17
 export function _getRouteToRender(stateOrGetState: Object | Function) {
17
-    const state
18
-        = typeof stateOrGetState === 'function'
19
-            ? stateOrGetState()
20
-            : stateOrGetState;
21
-    const { room } = state['features/base/conference'];
22
-    const component = isRoomValid(room) ? Conference : Entryway;
18
+    const { room } = toState(stateOrGetState)['features/base/conference'];
19
+    const component = isRoomValid(room) ? Conference : WelcomePage;
23
 
20
 
24
     return RouteRegistry.getRouteByComponent(component);
21
     return RouteRegistry.getRouteByComponent(component);
25
 }
22
 }

+ 10
- 12
react/features/app/functions.web.js 파일 보기

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
 import { Platform } from '../base/react';
3
 import { Platform } from '../base/react';
4
+import { toState } from '../base/redux';
4
 import {
5
 import {
5
     NoMobileApp,
6
     NoMobileApp,
6
     PluginRequiredBrowser,
7
     PluginRequiredBrowser,
22
  * render.
23
  * render.
23
  *
24
  *
24
  * @private
25
  * @private
25
- * @param {Object} state - Object containing current Redux state.
26
+ * @param {Object} state - Object containing current redux state.
26
  * @returns {ReactElement|void}
27
  * @returns {ReactElement|void}
27
  * @type {Function[]}
28
  * @type {Function[]}
28
  */
29
  */
34
      * app even if the browser supports the app (e.g. Google Chrome with
35
      * app even if the browser supports the app (e.g. Google Chrome with
35
      * WebRTC support on Android).
36
      * WebRTC support on Android).
36
      *
37
      *
37
-     * @param {Object} state - Redux state of the app.
38
+     * @param {Object} state - The redux state of the app.
38
      * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
39
      * @returns {UnsupportedMobileBrowser|void} If the rule is satisfied then
39
      * we should intercept existing component by UnsupportedMobileBrowser.
40
      * we should intercept existing component by UnsupportedMobileBrowser.
40
      */
41
      */
73
 ];
74
 ];
74
 
75
 
75
 /**
76
 /**
76
- * Determines which route is to be rendered in order to depict a specific Redux
77
+ * Determines which route is to be rendered in order to depict a specific redux
77
  * store.
78
  * store.
78
  *
79
  *
79
- * @param {(Object|Function)} stateOrGetState - Redux state or Regux getState()
80
- * method.
80
+ * @param {(Object|Function)} stateOrGetState - The redux state or
81
+ * {@link getState} function.
81
  * @returns {Route}
82
  * @returns {Route}
82
  */
83
  */
83
 export function _getRouteToRender(stateOrGetState: Object | Function) {
84
 export function _getRouteToRender(stateOrGetState: Object | Function) {
93
 /**
94
 /**
94
  * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
95
  * Intercepts route components based on a {@link _INTERCEPT_COMPONENT_RULES}.
95
  *
96
  *
96
- * @param {Object|Function} stateOrGetState - Either Redux state object or
97
- * getState() function.
97
+ * @param {Object|Function} stateOrGetState - The redux state or
98
+ * {@link getState} function.
98
  * @param {ReactElement} component - Current route component to render.
99
  * @param {ReactElement} component - Current route component to render.
99
  * @private
100
  * @private
100
  * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
101
  * @returns {ReactElement} If any of the pre-defined rules is satisfied, returns
101
  * intercepted component.
102
  * intercepted component.
102
  */
103
  */
103
 function _interceptComponent(
104
 function _interceptComponent(
104
-        stateOrGetState: Object,
105
+        stateOrGetState: Object | Function,
105
         component: ReactElement<*>) {
106
         component: ReactElement<*>) {
106
     let result;
107
     let result;
107
-    const state
108
-        = typeof stateOrGetState === 'function'
109
-            ? stateOrGetState()
110
-            : stateOrGetState;
108
+    const state = toState(stateOrGetState);
111
 
109
 
112
     for (const rule of _INTERCEPT_COMPONENT_RULES) {
110
     for (const rule of _INTERCEPT_COMPONENT_RULES) {
113
         result = rule(state);
111
         result = rule(state);

+ 4
- 10
react/features/base/connection/functions.js 파일 보기

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
+import { toState } from '../redux';
4
+
3
 /**
5
 /**
4
  * Retrieves a simplified version of the conference/location URL stripped of URL
6
  * Retrieves a simplified version of the conference/location URL stripped of URL
5
  * params (i.e. query/search and hash) which should be used for sending invites.
7
  * params (i.e. query/search and hash) which should be used for sending invites.
9
  * @returns {string|undefined}
11
  * @returns {string|undefined}
10
  */
12
  */
11
 export function getInviteURL(stateOrGetState: Function | Object): ?string {
13
 export function getInviteURL(stateOrGetState: Function | Object): ?string {
12
-    const state
13
-        = typeof stateOrGetState === 'function'
14
-            ? stateOrGetState()
15
-            : stateOrGetState;
14
+    const state = toState(stateOrGetState);
16
     const locationURL
15
     const locationURL
17
         = state instanceof URL
16
         = state instanceof URL
18
             ? state
17
             ? state
19
             : state['features/base/connection'].locationURL;
18
             : state['features/base/connection'].locationURL;
20
-    let inviteURL;
21
-
22
-    if (locationURL) {
23
-        inviteURL = getURLWithoutParams(locationURL).href;
24
-    }
25
 
19
 
26
-    return inviteURL;
20
+    return locationURL ? getURLWithoutParams(locationURL).href : undefined;
27
 }
21
 }
28
 
22
 
29
 /**
23
 /**

+ 1
- 1
react/features/base/lib-jitsi-meet/native/polyfills-browser.js 파일 보기

219
                 // then it doesn't sound like what expected.
219
                 // then it doesn't sound like what expected.
220
                 && nodePrototype !== Object.getPrototypeOf({})) {
220
                 && nodePrototype !== Object.getPrototypeOf({})) {
221
             // Override console.log.
221
             // Override console.log.
222
-            const console = global.console;
222
+            const { console } = global;
223
 
223
 
224
             if (console) {
224
             if (console) {
225
                 const loggerLevels = require('jitsi-meet-logger').levels;
225
                 const loggerLevels = require('jitsi-meet-logger').levels;

+ 21
- 19
react/features/base/participants/functions.js 파일 보기

1
+/* @flow */
2
+
3
+import { toState } from '../redux';
4
+
1
 import { DEFAULT_AVATAR_RELATIVE_PATH } from './constants';
5
 import { DEFAULT_AVATAR_RELATIVE_PATH } from './constants';
2
 
6
 
3
 declare var config: Object;
7
 declare var config: Object;
13
  * @param {string} [participant.avatarURL] - Participant's avatar URL.
17
  * @param {string} [participant.avatarURL] - Participant's avatar URL.
14
  * @param {string} [participant.email] - Participant's e-mail address.
18
  * @param {string} [participant.email] - Participant's e-mail address.
15
  * @param {string} [participant.id] - Participant's ID.
19
  * @param {string} [participant.id] - Participant's ID.
20
+ * @public
16
  * @returns {string} The URL of the image for the avatar of the specified
21
  * @returns {string} The URL of the image for the avatar of the specified
17
  * participant.
22
  * participant.
18
- *
19
- * @public
20
  */
23
  */
21
-export function getAvatarURL(participant) {
24
+export function getAvatarURL({ avatarID, avatarURL, email, id }: {
25
+        avatarID: string,
26
+        avatarURL: string,
27
+        email: string,
28
+        id: string
29
+}) {
22
     // If disableThirdPartyRequests disables third-party avatar services, we are
30
     // If disableThirdPartyRequests disables third-party avatar services, we are
23
     // restricted to a stock image of ours.
31
     // restricted to a stock image of ours.
24
     if (typeof config === 'object' && config.disableThirdPartyRequests) {
32
     if (typeof config === 'object' && config.disableThirdPartyRequests) {
25
         return DEFAULT_AVATAR_RELATIVE_PATH;
33
         return DEFAULT_AVATAR_RELATIVE_PATH;
26
     }
34
     }
27
 
35
 
28
-    const { avatarID, avatarURL, email, id } = participant;
29
-
30
     // If an avatarURL is specified, then obviously there's nothing to generate.
36
     // If an avatarURL is specified, then obviously there's nothing to generate.
31
     if (avatarURL) {
37
     if (avatarURL) {
32
         return avatarURL;
38
         return avatarURL;
77
  * features/base/participants state.
83
  * features/base/participants state.
78
  * @returns {(Participant|undefined)}
84
  * @returns {(Participant|undefined)}
79
  */
85
  */
80
-export function getLocalParticipant(stateOrGetState) {
86
+export function getLocalParticipant(stateOrGetState: Object | Function) {
81
     const participants = _getParticipants(stateOrGetState);
87
     const participants = _getParticipants(stateOrGetState);
82
 
88
 
83
     return participants.find(p => p.local);
89
     return participants.find(p => p.local);
94
  * @private
100
  * @private
95
  * @returns {(Participant|undefined)}
101
  * @returns {(Participant|undefined)}
96
  */
102
  */
97
-export function getParticipantById(stateOrGetState, id) {
103
+export function getParticipantById(
104
+        stateOrGetState: Object | Function,
105
+        id: string) {
98
     const participants = _getParticipants(stateOrGetState);
106
     const participants = _getParticipants(stateOrGetState);
99
 
107
 
100
     return participants.find(p => p.id === id);
108
     return participants.find(p => p.id === id);
110
  * features/base/participants state.
118
  * features/base/participants state.
111
  * @returns {number}
119
  * @returns {number}
112
  */
120
  */
113
-export function getParticipantCount(stateOrGetState) {
121
+export function getParticipantCount(stateOrGetState: Object | Function) {
114
     const participants = _getParticipants(stateOrGetState);
122
     const participants = _getParticipants(stateOrGetState);
115
     const realParticipants = participants.filter(p => !p.isBot);
123
     const realParticipants = participants.filter(p => !p.isBot);
116
 
124
 
126
  * features/base/participants state.
134
  * features/base/participants state.
127
  * @returns {(Participant|undefined)}
135
  * @returns {(Participant|undefined)}
128
  */
136
  */
129
-export function getPinnedParticipant(stateOrGetState) {
137
+export function getPinnedParticipant(stateOrGetState: Object | Function) {
130
     const participants = _getParticipants(stateOrGetState);
138
     const participants = _getParticipants(stateOrGetState);
131
 
139
 
132
     return participants.find(p => p.pinned);
140
     return participants.find(p => p.pinned);
143
  * @returns {Participant[]}
151
  * @returns {Participant[]}
144
  */
152
  */
145
 function _getParticipants(stateOrGetState) {
153
 function _getParticipants(stateOrGetState) {
146
-    if (Array.isArray(stateOrGetState)) {
147
-        return stateOrGetState;
148
-    }
149
-
150
-    const state
151
-        = typeof stateOrGetState === 'function'
152
-            ? stateOrGetState()
153
-            : stateOrGetState;
154
-
155
-    return state['features/base/participants'] || [];
154
+    return (
155
+        Array.isArray(stateOrGetState)
156
+            ? stateOrGetState
157
+            : toState(stateOrGetState)['features/base/participants'] || []);
156
 }
158
 }

+ 27
- 4
react/features/base/redux/functions.js 파일 보기

1
+/* @flow */
2
+
1
 import _ from 'lodash';
3
 import _ from 'lodash';
2
 
4
 
3
 /**
5
 /**
13
  * from the specified target by setting the specified properties to the
15
  * from the specified target by setting the specified properties to the
14
  * specified values.
16
  * specified values.
15
  */
17
  */
16
-export function assign(target, source) {
18
+export function assign(target: Object, source: Object) {
17
     let t = target;
19
     let t = target;
18
 
20
 
19
     for (const property in source) { // eslint-disable-line guard-for-in
21
     for (const property in source) { // eslint-disable-line guard-for-in
32
  * @returns {boolean} True if {@code a} equals {@code b} (according to deep
34
  * @returns {boolean} True if {@code a} equals {@code b} (according to deep
33
  * comparison); false, otherwise.
35
  * comparison); false, otherwise.
34
  */
36
  */
35
-export function equals(a, b) {
37
+export function equals(a: any, b: any) {
36
     return _.isEqual(a, b);
38
     return _.isEqual(a, b);
37
 }
39
 }
38
 
40
 
52
  * constructed from the specified <tt>state</tt> by setting the specified
54
  * constructed from the specified <tt>state</tt> by setting the specified
53
  * <tt>property</tt> to the specified <tt>value</tt>.
55
  * <tt>property</tt> to the specified <tt>value</tt>.
54
  */
56
  */
55
-export function set(state, property, value) {
57
+export function set(state: Object, property: string, value: any) {
56
     return _set(state, property, value, /* copyOnWrite */ true);
58
     return _set(state, property, value, /* copyOnWrite */ true);
57
 }
59
 }
58
 
60
 
77
  * <tt>state</tt> by setting the specified <tt>property</tt> to the specified
79
  * <tt>state</tt> by setting the specified <tt>property</tt> to the specified
78
  * <tt>value</tt>.
80
  * <tt>value</tt>.
79
  */
81
  */
80
-function _set(state, property, value, copyOnWrite) {
82
+function _set(
83
+        state: Object,
84
+        property: string,
85
+        value: any,
86
+        copyOnWrite: boolean) {
81
     // Delete state properties that are to be set to undefined. (It is a matter
87
     // Delete state properties that are to be set to undefined. (It is a matter
82
     // of personal preference, mostly.)
88
     // of personal preference, mostly.)
83
     if (typeof value === 'undefined'
89
     if (typeof value === 'undefined'
104
 }
110
 }
105
 
111
 
106
 /* eslint-enable max-params */
112
 /* eslint-enable max-params */
113
+
114
+/**
115
+ * If the specified <tt>stateOrGetState</tt> is a function, it is presumed to be
116
+ * the redux {@link getState} function, it is invoked, and its return value is
117
+ * returned; otherwise, <tt>stateOrGetState</tt> is presumed to be the redux
118
+ * state and is returned.
119
+ *
120
+ * @param {Object|Function} stateOrGetState - The redux state or
121
+ * {@link getState} function.
122
+ * @returns {Object} The redux state.
123
+ */
124
+export function toState(stateOrGetState: Object | Function) {
125
+    return (
126
+        typeof stateOrGetState === 'function'
127
+            ? stateOrGetState()
128
+            : stateOrGetState);
129
+}

+ 1
- 3
react/index.native.js 파일 보기

90
      * @inheritdoc
90
      * @inheritdoc
91
      */
91
      */
92
     componentWillReceiveProps({ url }) {
92
     componentWillReceiveProps({ url }) {
93
-        if (!equals(this.props.url, url)) {
94
-            this.setState({ url: url || null });
95
-        }
93
+        equals(this.props.url, url) || this.setState({ url: url || null });
96
     }
94
     }
97
 
95
 
98
     /**
96
     /**

Loading…
취소
저장