Sfoglia il codice sorgente

Flatten the store of the recent-list feature

master
zbettenbuk 7 anni fa
parent
commit
0e07020d09

+ 1
- 1
react/features/recent-list/components/AbstractRecentList.js Vedi File

@@ -64,6 +64,6 @@ export default class AbstractRecentList extends Component<Props> {
64 64
 export function _mapStateToProps(state: Object) {
65 65
     return {
66 66
         _homeServer: state['features/app'].app._getDefaultURL(),
67
-        _recentList: state['features/recent-list'].list
67
+        _recentList: state['features/recent-list']
68 68
     };
69 69
 }

+ 8
- 12
react/features/recent-list/reducer.js Vedi File

@@ -33,16 +33,14 @@ const STORE_NAME = 'features/recent-list';
33 33
 /**
34 34
  * Sets up the persistence of the feature recent-list.
35 35
  */
36
-PersistenceRegistry.register(STORE_NAME, {
37
-    list: true
38
-});
36
+PersistenceRegistry.register(STORE_NAME);
39 37
 
40 38
 /**
41 39
  * Reduces the redux actions of the feature recent-list.
42 40
  */
43 41
 ReducerRegistry.register(
44 42
     STORE_NAME,
45
-    (state = { list: _getLegacyRecentRoomList() }, action) => {
43
+    (state = _getLegacyRecentRoomList(), action) => {
46 44
         switch (action.type) {
47 45
         case STORE_CURRENT_CONFERENCE:
48 46
             return _storeCurrentConference(state, action);
@@ -88,7 +86,8 @@ function _storeCurrentConference(state, action) {
88 86
 
89 87
     // If the current conference is already in the list, we remove it to re-add
90 88
     // it to the top.
91
-    const list = state.list.filter(e => e.conference !== conference);
89
+    const list = (Array.isArray(state) ? state : [])
90
+        .filter(e => e.conference !== conference);
92 91
 
93 92
     // The list is a reverse-sorted (i.e. the newer elements are at the end).
94 93
     list.push({
@@ -100,9 +99,7 @@ function _storeCurrentConference(state, action) {
100 99
     // Ensure the list doesn't exceed a/the maximum size.
101 100
     list.splice(0, list.length - MAX_LIST_SIZE);
102 101
 
103
-    return {
104
-        list
105
-    };
102
+    return list;
106 103
 }
107 104
 
108 105
 /**
@@ -116,7 +113,8 @@ function _updateConferenceDuration(state, action) {
116 113
     const { locationURL } = action;
117 114
 
118 115
     if (locationURL && locationURL.href) {
119
-        const list = state.list;
116
+        // shallow copy to avoid in-place modification.
117
+        const list = (Array.isArray(state) ? state : []).slice();
120 118
 
121 119
         if (list.length > 0) {
122 120
             const mostRecentURL = list[list.length - 1];
@@ -127,9 +125,7 @@ function _updateConferenceDuration(state, action) {
127 125
                 mostRecentURL.conferenceDuration
128 126
                     = Date.now() - mostRecentURL.date;
129 127
 
130
-                return {
131
-                    list
132
-                };
128
+                return list;
133 129
             }
134 130
         }
135 131
     }

Loading…
Annulla
Salva