Переглянути джерело

Fix thumbnail reordering

Don't use Array.prototype.sort() because (1) it operates in place and,
thus, mutes the Redux state and (2) it is not necessarily stable and,
thus, unnecessarily shuffles the thumbnails.
master
Lyubomir Marinov 9 роки тому
джерело
коміт
3fa62c3757
1 змінених файлів з 35 додано та 12 видалено
  1. 35
    12
      react/features/filmStrip/components/FilmStrip.js

+ 35
- 12
react/features/filmStrip/components/FilmStrip.js Переглянути файл

@@ -33,18 +33,7 @@ class FilmStrip extends Component {
33 33
                     showsHorizontalScrollIndicator = { false }
34 34
                     showsVerticalScrollIndicator = { false }>
35 35
                     {
36
-                        this.props.participants
37
-
38
-                            // Group the remote participants so that the local
39
-                            // participant does not appear in between remote
40
-                            // participants.
41
-                            .sort((a, b) => b.local - a.local)
42
-
43
-                            // Have the local participant at the rightmost side.
44
-                            // Then have the remote participants from right to
45
-                            // left with the newest added/joined to the leftmost
46
-                            // side.
47
-                            .reverse()
36
+                        this._sort(this.props.participants)
48 37
                             .map(p =>
49 38
                                 <Thumbnail
50 39
                                     key = { p.id }
@@ -54,6 +43,40 @@ class FilmStrip extends Component {
54 43
             </Container>
55 44
         );
56 45
     }
46
+
47
+    /**
48
+     * Sorts a specific array of <tt>Participant</tt>s in display order.
49
+     *
50
+     * @param {Participant[]} participants - The array of <tt>Participant</tt>s
51
+     * to sort in display order.
52
+     * @private
53
+     * @returns {Participant[]} A new array containing the elements of the
54
+     * specified <tt>participants</tt> array sorted in display order.
55
+     */
56
+    _sort(participants) {
57
+        // XXX Array.prototype.sort() is not appropriate because (1) it operates
58
+        // in place and (2) it is not necessarily stable.
59
+
60
+        const sortedParticipants = [];
61
+
62
+        // Group the remote participants so that the local participant does not
63
+        // appear in between remote participants. Have the remote participants
64
+        // from right to left with the newest added/joined to the leftmost side.
65
+        for (let i = participants.length - 1; i >= 0; --i) {
66
+            const p = participants[i];
67
+
68
+            p.local || sortedParticipants.push(p);
69
+        }
70
+
71
+        // Have the local participant at the rightmost side.
72
+        for (let i = participants.length - 1; i >= 0; --i) {
73
+            const p = participants[i];
74
+
75
+            p.local && sortedParticipants.push(p);
76
+        }
77
+
78
+        return sortedParticipants;
79
+    }
57 80
 }
58 81
 
59 82
 /**

Завантаження…
Відмінити
Зберегти