Преглед изворни кода

fix(optimise): mapStateToProps for some components (#5085)

j8
Hristo Terezov пре 5 година
родитељ
комит
bd8a7edbd2
No account linked to committer's email address

+ 4
- 1
react/features/chrome-extension-banner/components/ChromeExtensionBanner.web.js Прегледај датотеку

@@ -17,6 +17,8 @@ import {
17 17
 
18 18
 declare var interfaceConfig: Object;
19 19
 
20
+const emptyObject = {};
21
+
20 22
 /**
21 23
  * Local storage key name for flag telling if user checked 'Don't show again' checkbox on the banner
22 24
  * If the user checks this before closing the banner, next time he will access a jitsi domain
@@ -271,7 +273,8 @@ class ChromeExtensionBanner extends PureComponent<Props, State> {
271 273
  */
272 274
 const _mapStateToProps = state => {
273 275
     return {
274
-        bannerCfg: state['features/base/config'].chromeExtensionBanner || {},
276
+        // Using emptyObject so that we don't change the reference every time when _mapStateToProps is called.
277
+        bannerCfg: state['features/base/config'].chromeExtensionBanner || emptyObject,
275 278
         conference: getCurrentConference(state),
276 279
         iAmRecorder: state['features/base/config'].iAmRecorder
277 280
     };

+ 5
- 1
react/features/filmstrip/components/web/Toolbar.js Прегледај датотеку

@@ -12,6 +12,10 @@ import {
12 12
 
13 13
 declare var interfaceConfig: Object;
14 14
 
15
+// XXX: We are not currently using state here, but in the future, when
16
+// interfaceConfig is part of redux we will. This has to be retrieved from the store.
17
+const visibleButtons = new Set(interfaceConfig.TOOLBAR_BUTTONS);
18
+
15 19
 /**
16 20
  * The type of the React {@code Component} props of {@link Toolbar}.
17 21
  */
@@ -86,7 +90,7 @@ function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
86 90
     // interfaceConfig is part of redux we will.
87 91
 
88 92
     return {
89
-        _visibleButtons: new Set(interfaceConfig.TOOLBAR_BUTTONS)
93
+        _visibleButtons: visibleButtons
90 94
     };
91 95
 }
92 96
 

+ 7
- 5
react/features/invite/components/info-dialog/web/InfoDialog.js Прегледај датотеку

@@ -59,7 +59,7 @@ type Props = {
59 59
     /**
60 60
      * The redux representation of the local participant.
61 61
      */
62
-    _localParticipant: Object,
62
+    _localParticipantName: ?string,
63 63
 
64 64
     /**
65 65
      * The current location url of the conference.
@@ -316,11 +316,11 @@ class InfoDialog extends Component<Props, State> {
316 316
      * @returns {string}
317 317
      */
318 318
     _getTextToCopy() {
319
-        const { _localParticipant, liveStreamViewURL, t } = this.props;
319
+        const { _localParticipantName, liveStreamViewURL, t } = this.props;
320 320
         const _inviteURL = _decodeRoomURI(this.props._inviteURL);
321 321
 
322
-        let invite = _localParticipant && _localParticipant.name
323
-            ? t('info.inviteURLFirstPartPersonal', { name: _localParticipant.name })
322
+        let invite = _localParticipantName
323
+            ? t('info.inviteURLFirstPartPersonal', { name: _localParticipantName })
324 324
             : t('info.inviteURLFirstPartGeneral');
325 325
 
326 326
         invite += t('info.inviteURLSecondPart', {
@@ -613,6 +613,7 @@ class InfoDialog extends Component<Props, State> {
613 613
  *     _conference: Object,
614 614
  *     _conferenceName: string,
615 615
  *     _inviteURL: string,
616
+ *     _localParticipantName: ?string,
616 617
  *     _locationURL: string,
617 618
  *     _locked: string,
618 619
  *     _password: string
@@ -625,6 +626,7 @@ function _mapStateToProps(state) {
625 626
         password,
626 627
         room
627 628
     } = state['features/base/conference'];
629
+    const localParticipant = getLocalParticipant(state);
628 630
 
629 631
     return {
630 632
         _canEditPassword: isLocalParticipantModerator(state, state['features/base/config'].lockRoomGuestEnabled),
@@ -632,7 +634,7 @@ function _mapStateToProps(state) {
632 634
         _conferenceName: room,
633 635
         _passwordNumberOfDigits: state['features/base/config'].roomPasswordNumberOfDigits,
634 636
         _inviteURL: getInviteURL(state),
635
-        _localParticipant: getLocalParticipant(state),
637
+        _localParticipantName: localParticipant?.name,
636 638
         _locationURL: state['features/base/connection'].locationURL,
637 639
         _locked: locked,
638 640
         _password: password

+ 5
- 5
react/features/invite/components/info-dialog/web/InfoDialogButton.js Прегледај датотеку

@@ -47,10 +47,10 @@ type Props = {
47 47
     _liveStreamViewURL: ?string,
48 48
 
49 49
     /**
50
-     * The number of real participants in the call. If in a lonely call, the
50
+     * True if the number of real participants in the call is less than 2. If in a lonely call, the
51 51
      * {@code InfoDialog} will be automatically shown.
52 52
      */
53
-    _participantCount: number,
53
+    _isLonelyCall: boolean,
54 54
 
55 55
     /**
56 56
      * Whether or not the toolbox, in which this component exists, is visible.
@@ -108,7 +108,7 @@ class InfoDialogButton extends Component<Props, State> {
108 108
             showDialog: (props._toolboxVisible && state.showDialog)
109 109
                 || (!state.hasConnectedToConference
110 110
                     && props._isConferenceJoined
111
-                    && props._participantCount < 2
111
+                    && props._isLonelyCall
112 112
                     && props._toolboxVisible
113 113
                     && !props._disableAutoShow)
114 114
         };
@@ -243,7 +243,7 @@ class InfoDialogButton extends Component<Props, State> {
243 243
  *     _disableAutoShow: boolean,
244 244
  *     _isConferenceIsJoined: boolean,
245 245
  *     _liveStreamViewURL: string,
246
- *     _participantCount: number,
246
+ *     _isLonelyCall: boolean,
247 247
  *     _toolboxVisible: boolean
248 248
  * }}
249 249
  */
@@ -260,7 +260,7 @@ function _mapStateToProps(state) {
260 260
         _liveStreamViewURL:
261 261
             currentLiveStreamingSession
262 262
                 && currentLiveStreamingSession.liveStreamViewURL,
263
-        _participantCount: getParticipantCount(state),
263
+        _isLonelyCall: getParticipantCount(state) < 2,
264 264
         _toolboxVisible: state['features/toolbox'].visible
265 265
     };
266 266
 }

+ 6
- 3
react/features/subtitles/components/AbstractCaptions.js Прегледај датотеку

@@ -17,7 +17,7 @@ export type AbstractCaptionsProps = {
17 17
      * Mapped by id just to have the keys for convenience during the rendering
18 18
      * process.
19 19
      */
20
-    _transcripts: Map<string, string>
20
+    _transcripts: ?Map<string, string>
21 21
 };
22 22
 
23 23
 /**
@@ -36,7 +36,7 @@ export class AbstractCaptions<P: AbstractCaptionsProps>
36 36
     render() {
37 37
         const { _requestingSubtitles, _transcripts } = this.props;
38 38
 
39
-        if (!_requestingSubtitles || !_transcripts.size) {
39
+        if (!_requestingSubtitles || !_transcripts || !_transcripts.size) {
40 40
             return null;
41 41
         }
42 42
 
@@ -120,9 +120,12 @@ function _constructTranscripts(state: Object): Map<string, string> {
120 120
  */
121 121
 export function _abstractMapStateToProps(state: Object) {
122 122
     const { _requestingSubtitles } = state['features/subtitles'];
123
+    const transcripts = _constructTranscripts(state);
123 124
 
124 125
     return {
125 126
         _requestingSubtitles,
126
-        _transcripts: _constructTranscripts(state)
127
+
128
+        // avoid rerenders by setting to props new empty Map instances.
129
+        _transcripts: transcripts.size === 0 ? undefined : transcripts
127 130
     };
128 131
 }

+ 5
- 4
react/features/toolbox/components/web/Toolbox.js Прегледај датотеку

@@ -206,6 +206,10 @@ type State = {
206 206
 declare var APP: Object;
207 207
 declare var interfaceConfig: Object;
208 208
 
209
+// XXX: We are not currently using state here, but in the future, when
210
+// interfaceConfig is part of redux we will. This will have to be retrieved from the store.
211
+const visibleButtons = new Set(interfaceConfig.TOOLBAR_BUTTONS);
212
+
209 213
 /**
210 214
  * Implements the conference toolbox on React/Web.
211 215
  *
@@ -1347,10 +1351,7 @@ function _mapStateToProps(state) {
1347 1351
             || sharedVideoStatus === 'start'
1348 1352
             || sharedVideoStatus === 'pause',
1349 1353
         _visible: isToolboxVisible(state),
1350
-
1351
-        // XXX: We are not currently using state here, but in the future, when
1352
-        // interfaceConfig is part of redux we will.
1353
-        _visibleButtons: new Set(interfaceConfig.TOOLBAR_BUTTONS)
1354
+        _visibleButtons: visibleButtons
1354 1355
     };
1355 1356
 }
1356 1357
 

Loading…
Откажи
Сачувај