瀏覽代碼

Prepare PersistenceRegistry for flat subtrees

master
zbettenbuk 7 年之前
父節點
當前提交
e0deb6d64b
共有 1 個文件被更改,包括 29 次插入13 次删除
  1. 29
    13
      react/features/base/storage/PersistenceRegistry.js

+ 29
- 13
react/features/base/storage/PersistenceRegistry.js 查看文件

@@ -10,10 +10,18 @@ const logger = Logger.getLogger(__filename);
10 10
  */
11 11
 const PERSISTED_STATE_NAME = 'jitsi-state';
12 12
 
13
+/**
14
+ * Mixed type of the element (subtree) config. If it's a boolean,
15
+ * (and is true) we persist the entire subtree. If it's an object,
16
+ * we perist a filtered subtree based on the properties in the
17
+ * config object.
18
+ */
19
+declare type ElementConfig = Object | boolean;
20
+
13 21
 /**
14 22
  * The type of the name-config pairs stored in this reducer.
15 23
  */
16
-declare type PersistencyConfigMap = { [name: string]: Object };
24
+declare type PersistencyConfigMap = { [name: string]: ElementConfig };
17 25
 
18 26
 /**
19 27
  * A registry to allow features to register their redux store subtree to be
@@ -94,10 +102,11 @@ class PersistenceRegistry {
94 102
      * Registers a new subtree config to be used for the persistency.
95 103
      *
96 104
      * @param {string} name - The name of the subtree the config belongs to.
97
-     * @param {Object} config - The config object.
105
+     * @param {ElementConfig} config - The config object, or boolean
106
+     * if the entire subtree needs to be persisted.
98 107
      * @returns {void}
99 108
      */
100
-    register(name: string, config: Object) {
109
+    register(name: string, config?: ElementConfig = true) {
101 110
         this._elements[name] = config;
102 111
     }
103 112
 
@@ -134,10 +143,9 @@ class PersistenceRegistry {
134 143
 
135 144
         for (const name of Object.keys(this._elements)) {
136 145
             if (state[name]) {
137
-                filteredState[name]
138
-                    = this._getFilteredSubtree(
139
-                        state[name],
140
-                        this._elements[name]);
146
+                filteredState[name] = this._getFilteredSubtree(
147
+                    state[name],
148
+                    this._elements[name]);
141 149
             }
142 150
         }
143 151
 
@@ -150,15 +158,23 @@ class PersistenceRegistry {
150 158
      *
151 159
      * @private
152 160
      * @param {Object} subtree - The redux state subtree.
153
-     * @param {Object} subtreeConfig - The related config.
161
+     * @param {ElementConfig} subtreeConfig - The related config.
154 162
      * @returns {Object}
155 163
      */
156 164
     _getFilteredSubtree(subtree, subtreeConfig) {
157
-        const filteredSubtree = {};
158
-
159
-        for (const persistedKey of Object.keys(subtree)) {
160
-            if (subtreeConfig[persistedKey]) {
161
-                filteredSubtree[persistedKey] = subtree[persistedKey];
165
+        let filteredSubtree;
166
+
167
+        if (subtreeConfig === true) {
168
+            // we persist the entire subtree
169
+            filteredSubtree = subtree;
170
+        } else if (typeof subtreeConfig === 'object') {
171
+            // only a filtered subtree gets persisted, based on the
172
+            // subtreeConfig object.
173
+            filteredSubtree = {};
174
+            for (const persistedKey of Object.keys(subtree)) {
175
+                if (subtreeConfig[persistedKey]) {
176
+                    filteredSubtree[persistedKey] = subtree[persistedKey];
177
+                }
162 178
             }
163 179
         }
164 180
 

Loading…
取消
儲存