瀏覽代碼

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
  */
11
 const PERSISTED_STATE_NAME = 'jitsi-state';
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
  * The type of the name-config pairs stored in this reducer.
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
  * A registry to allow features to register their redux store subtree to be
27
  * A registry to allow features to register their redux store subtree to be
94
      * Registers a new subtree config to be used for the persistency.
102
      * Registers a new subtree config to be used for the persistency.
95
      *
103
      *
96
      * @param {string} name - The name of the subtree the config belongs to.
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
      * @returns {void}
107
      * @returns {void}
99
      */
108
      */
100
-    register(name: string, config: Object) {
109
+    register(name: string, config?: ElementConfig = true) {
101
         this._elements[name] = config;
110
         this._elements[name] = config;
102
     }
111
     }
103
 
112
 
134
 
143
 
135
         for (const name of Object.keys(this._elements)) {
144
         for (const name of Object.keys(this._elements)) {
136
             if (state[name]) {
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
      *
158
      *
151
      * @private
159
      * @private
152
      * @param {Object} subtree - The redux state subtree.
160
      * @param {Object} subtree - The redux state subtree.
153
-     * @param {Object} subtreeConfig - The related config.
161
+     * @param {ElementConfig} subtreeConfig - The related config.
154
      * @returns {Object}
162
      * @returns {Object}
155
      */
163
      */
156
     _getFilteredSubtree(subtree, subtreeConfig) {
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…
取消
儲存