react-native-onyx 1.0.126 → 1.0.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/web.development.js +228 -108
- package/dist/web.development.js.map +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.min.js.map +1 -1
- package/lib/DevTools.js +71 -0
- package/lib/Onyx.d.ts +1 -0
- package/lib/Onyx.js +32 -4
- package/lib/utils.d.ts +8 -1
- package/lib/utils.js +5 -1
- package/package.json +1 -1
package/dist/web.development.js
CHANGED
|
@@ -122,6 +122,93 @@ function init() {
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
|
|
125
|
+
/***/ }),
|
|
126
|
+
|
|
127
|
+
/***/ "./lib/DevTools.js":
|
|
128
|
+
/*!*************************!*\
|
|
129
|
+
!*** ./lib/DevTools.js ***!
|
|
130
|
+
\*************************/
|
|
131
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
132
|
+
|
|
133
|
+
"use strict";
|
|
134
|
+
__webpack_require__.r(__webpack_exports__);
|
|
135
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
136
|
+
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
137
|
+
/* harmony export */ });
|
|
138
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! underscore */ "underscore");
|
|
139
|
+
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_0__);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
const ERROR_LABEL = 'Onyx DevTools - Error: ';
|
|
143
|
+
|
|
144
|
+
/* eslint-disable no-underscore-dangle */
|
|
145
|
+
class DevTools {
|
|
146
|
+
constructor() {
|
|
147
|
+
this.remoteDev = this.connectViaExtension();
|
|
148
|
+
this.state = {};
|
|
149
|
+
this.defaultState = {};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
connectViaExtension(options) {
|
|
153
|
+
try {
|
|
154
|
+
if (options && options.remote || typeof window === 'undefined' || !window.__REDUX_DEVTOOLS_EXTENSION__) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
return window.__REDUX_DEVTOOLS_EXTENSION__.connect(options);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error(ERROR_LABEL, e);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Registers an action that updated the current state of the storage
|
|
165
|
+
*
|
|
166
|
+
* @param {string} type - name of the action
|
|
167
|
+
* @param {any} payload - data written to the storage
|
|
168
|
+
* @param {object} stateChanges - partial state that got updated after the changes
|
|
169
|
+
*/
|
|
170
|
+
registerAction(type) {let payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;let stateChanges = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
171
|
+
try {
|
|
172
|
+
if (!this.remoteDev) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const newState = {
|
|
176
|
+
...this.state,
|
|
177
|
+
...stateChanges
|
|
178
|
+
};
|
|
179
|
+
this.remoteDev.send({ type, payload }, newState);
|
|
180
|
+
this.state = newState;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
console.error(ERROR_LABEL, e);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
initState() {let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
187
|
+
try {
|
|
188
|
+
if (!this.remoteDev) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
this.remoteDev.init(initialState);
|
|
192
|
+
this.state = initialState;
|
|
193
|
+
this.defaultState = initialState;
|
|
194
|
+
} catch (e) {
|
|
195
|
+
console.error(ERROR_LABEL, e);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
201
|
+
*
|
|
202
|
+
* @param {string[]} keysToPreserve
|
|
203
|
+
*/
|
|
204
|
+
clearState() {let keysToPreserve = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
205
|
+
const newState = underscore__WEBPACK_IMPORTED_MODULE_0___default().mapObject(this.state, (value, key) => keysToPreserve.includes(key) ? value : this.defaultState[key]);
|
|
206
|
+
this.registerAction('CLEAR', undefined, newState);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (new DevTools());
|
|
211
|
+
|
|
125
212
|
/***/ }),
|
|
126
213
|
|
|
127
214
|
/***/ "./lib/Logger.js":
|
|
@@ -186,16 +273,17 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
186
273
|
/* harmony import */ var fast_equals__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fast_equals__WEBPACK_IMPORTED_MODULE_0__);
|
|
187
274
|
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "underscore");
|
|
188
275
|
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
|
|
189
|
-
/* harmony import */ var
|
|
190
|
-
/* harmony import */ var
|
|
191
|
-
/* harmony import */ var
|
|
276
|
+
/* harmony import */ var _Logger__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./Logger */ "./lib/Logger.js");
|
|
277
|
+
/* harmony import */ var _OnyxCache__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./OnyxCache */ "./lib/OnyxCache.js");
|
|
278
|
+
/* harmony import */ var _Str__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./Str */ "./lib/Str.js");
|
|
192
279
|
/* harmony import */ var _createDeferredTask__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./createDeferredTask */ "./lib/createDeferredTask.js");
|
|
193
|
-
/* harmony import */ var
|
|
194
|
-
/* harmony import */ var
|
|
195
|
-
/* harmony import */ var
|
|
196
|
-
/* harmony import */ var
|
|
197
|
-
/* harmony import */ var
|
|
198
|
-
/* harmony import */ var
|
|
280
|
+
/* harmony import */ var _metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./metrics/PerformanceUtils */ "./lib/metrics/PerformanceUtils.js");
|
|
281
|
+
/* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./storage */ "./lib/storage/index.web.js");
|
|
282
|
+
/* harmony import */ var _broadcast__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./broadcast */ "./lib/broadcast/index.web.js");
|
|
283
|
+
/* harmony import */ var _ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./ActiveClientManager */ "./lib/ActiveClientManager/index.web.js");
|
|
284
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
|
285
|
+
/* harmony import */ var _batch__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./batch */ "./lib/batch.js");
|
|
286
|
+
/* harmony import */ var _DevTools__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./DevTools */ "./lib/DevTools.js");
|
|
199
287
|
/* eslint-disable no-continue */
|
|
200
288
|
|
|
201
289
|
|
|
@@ -210,6 +298,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
210
298
|
|
|
211
299
|
|
|
212
300
|
|
|
301
|
+
|
|
213
302
|
// Method constants
|
|
214
303
|
const METHOD = {
|
|
215
304
|
SET: 'set',
|
|
@@ -260,6 +349,18 @@ let onClearCallback = null;
|
|
|
260
349
|
let batchUpdatesPromise = null;
|
|
261
350
|
let batchUpdatesQueue = [];
|
|
262
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Sends an action to DevTools extension
|
|
354
|
+
*
|
|
355
|
+
* @param {string} method - Onyx method from METHOD
|
|
356
|
+
* @param {string} key - Onyx key that was changed
|
|
357
|
+
* @param {any} value - contains the change that was made by the method
|
|
358
|
+
* @param {any} mergedValue - (optional) value that was written in the storage after a merge method was executed.
|
|
359
|
+
*/
|
|
360
|
+
function sendActionToDevTools(method, key, value) {let mergedValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
361
|
+
_DevTools__WEBPACK_IMPORTED_MODULE_3__["default"].registerAction(_utils__WEBPACK_IMPORTED_MODULE_4__["default"].formatActionName(method, key), value, key ? { [key]: mergedValue || value } : value);
|
|
362
|
+
}
|
|
363
|
+
|
|
263
364
|
/**
|
|
264
365
|
* We are batching together onyx updates. This helps with use cases where we schedule onyx updates after each other.
|
|
265
366
|
* This happens for example in the Onyx.update function, where we process API responses that might contain a lot of
|
|
@@ -281,7 +382,7 @@ function maybeFlushBatchUpdates() {
|
|
|
281
382
|
const updatesCopy = batchUpdatesQueue;
|
|
282
383
|
batchUpdatesQueue = [];
|
|
283
384
|
batchUpdatesPromise = null;
|
|
284
|
-
(0,
|
|
385
|
+
(0,_batch__WEBPACK_IMPORTED_MODULE_5__["default"])(() => {
|
|
285
386
|
updatesCopy.forEach((applyUpdates) => {
|
|
286
387
|
applyUpdates();
|
|
287
388
|
});
|
|
@@ -337,26 +438,26 @@ collection,
|
|
|
337
438
|
*/
|
|
338
439
|
function get(key) {
|
|
339
440
|
// When we already have the value in cache - resolve right away
|
|
340
|
-
if (
|
|
341
|
-
return Promise.resolve(
|
|
441
|
+
if (_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].hasCacheForKey(key)) {
|
|
442
|
+
return Promise.resolve(_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getValue(key));
|
|
342
443
|
}
|
|
343
444
|
|
|
344
445
|
const taskName = `get:${key}`;
|
|
345
446
|
|
|
346
447
|
// When a value retrieving task for this key is still running hook to it
|
|
347
|
-
if (
|
|
348
|
-
return
|
|
448
|
+
if (_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].hasPendingTask(taskName)) {
|
|
449
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getTaskPromise(taskName);
|
|
349
450
|
}
|
|
350
451
|
|
|
351
452
|
// Otherwise retrieve the value from storage and capture a promise to aid concurrent usages
|
|
352
|
-
const promise =
|
|
453
|
+
const promise = _storage__WEBPACK_IMPORTED_MODULE_7__["default"].getItem(key).
|
|
353
454
|
then((val) => {
|
|
354
|
-
|
|
455
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].set(key, val);
|
|
355
456
|
return val;
|
|
356
457
|
}).
|
|
357
|
-
catch((err) =>
|
|
458
|
+
catch((err) => _Logger__WEBPACK_IMPORTED_MODULE_8__.logInfo(`Unable to get item from persistent storage. Key: ${key} Error: ${err}`));
|
|
358
459
|
|
|
359
|
-
return
|
|
460
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].captureTask(taskName, promise);
|
|
360
461
|
}
|
|
361
462
|
|
|
362
463
|
/**
|
|
@@ -366,7 +467,7 @@ function get(key) {
|
|
|
366
467
|
*/
|
|
367
468
|
function getAllKeys() {
|
|
368
469
|
// When we've already read stored keys, resolve right away
|
|
369
|
-
const storedKeys =
|
|
470
|
+
const storedKeys = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getAllKeys();
|
|
370
471
|
if (storedKeys.length > 0) {
|
|
371
472
|
return Promise.resolve(storedKeys);
|
|
372
473
|
}
|
|
@@ -374,17 +475,17 @@ function getAllKeys() {
|
|
|
374
475
|
const taskName = 'getAllKeys';
|
|
375
476
|
|
|
376
477
|
// When a value retrieving task for all keys is still running hook to it
|
|
377
|
-
if (
|
|
378
|
-
return
|
|
478
|
+
if (_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].hasPendingTask(taskName)) {
|
|
479
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getTaskPromise(taskName);
|
|
379
480
|
}
|
|
380
481
|
|
|
381
482
|
// Otherwise retrieve the keys from storage and capture a promise to aid concurrent usages
|
|
382
|
-
const promise =
|
|
383
|
-
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keys, (key) =>
|
|
483
|
+
const promise = _storage__WEBPACK_IMPORTED_MODULE_7__["default"].getAllKeys().then((keys) => {
|
|
484
|
+
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keys, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].addKey(key));
|
|
384
485
|
return keys;
|
|
385
486
|
});
|
|
386
487
|
|
|
387
|
-
return
|
|
488
|
+
return _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].captureTask(taskName, promise);
|
|
388
489
|
}
|
|
389
490
|
|
|
390
491
|
/**
|
|
@@ -405,7 +506,7 @@ function isCollectionKey(key) {
|
|
|
405
506
|
* @returns {Boolean}
|
|
406
507
|
*/
|
|
407
508
|
function isCollectionMemberKey(collectionKey, key) {
|
|
408
|
-
return
|
|
509
|
+
return _Str__WEBPACK_IMPORTED_MODULE_9__.startsWith(key, collectionKey) && key.length > collectionKey.length;
|
|
409
510
|
}
|
|
410
511
|
|
|
411
512
|
/**
|
|
@@ -418,7 +519,7 @@ function isCollectionMemberKey(collectionKey, key) {
|
|
|
418
519
|
* @return {Boolean}
|
|
419
520
|
*/
|
|
420
521
|
function isKeyMatch(configKey, key) {
|
|
421
|
-
return isCollectionKey(configKey) ?
|
|
522
|
+
return isCollectionKey(configKey) ? _Str__WEBPACK_IMPORTED_MODULE_9__.startsWith(key, configKey) : configKey === key;
|
|
422
523
|
}
|
|
423
524
|
|
|
424
525
|
/**
|
|
@@ -442,10 +543,10 @@ function isSafeEvictionKey(testKey) {
|
|
|
442
543
|
* @returns {Mixed}
|
|
443
544
|
*/
|
|
444
545
|
function tryGetCachedValue(key) {let mapping = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
445
|
-
let val =
|
|
546
|
+
let val = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getValue(key);
|
|
446
547
|
|
|
447
548
|
if (isCollectionKey(key)) {
|
|
448
|
-
const allCacheKeys =
|
|
549
|
+
const allCacheKeys = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getAllKeys();
|
|
449
550
|
|
|
450
551
|
// It is possible we haven't loaded all keys yet so we do not know if the
|
|
451
552
|
// collection actually exists.
|
|
@@ -456,7 +557,7 @@ function tryGetCachedValue(key) {let mapping = arguments.length > 1 && arguments
|
|
|
456
557
|
const values = underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
457
558
|
matchingKeys,
|
|
458
559
|
(finalObject, matchedKey) => {
|
|
459
|
-
const cachedValue =
|
|
560
|
+
const cachedValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getValue(matchedKey);
|
|
460
561
|
if (cachedValue) {
|
|
461
562
|
// This is permissible because we're in the process of constructing the final object in a reduce function.
|
|
462
563
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -571,12 +672,12 @@ function addAllSafeEvictionKeysToRecentlyAccessedList() {
|
|
|
571
672
|
* @returns {Object}
|
|
572
673
|
*/
|
|
573
674
|
function getCachedCollection(collectionKey) {
|
|
574
|
-
const collectionMemberKeys = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(
|
|
675
|
+
const collectionMemberKeys = underscore__WEBPACK_IMPORTED_MODULE_1___default().filter(_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getAllKeys(), (storedKey) => isCollectionMemberKey(collectionKey, storedKey));
|
|
575
676
|
|
|
576
677
|
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(
|
|
577
678
|
collectionMemberKeys,
|
|
578
679
|
(prev, curr) => {
|
|
579
|
-
const cachedValue =
|
|
680
|
+
const cachedValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getValue(curr);
|
|
580
681
|
if (!cachedValue) {
|
|
581
682
|
return prev;
|
|
582
683
|
}
|
|
@@ -610,7 +711,7 @@ function keysChanged(collectionKey, partialCollection) {let notifyRegularSubscib
|
|
|
610
711
|
}
|
|
611
712
|
|
|
612
713
|
// Skip iteration if we do not have a collection key or a collection member key on this subscriber
|
|
613
|
-
if (!
|
|
714
|
+
if (!_Str__WEBPACK_IMPORTED_MODULE_9__.startsWith(subscriber.key, collectionKey)) {
|
|
614
715
|
continue;
|
|
615
716
|
}
|
|
616
717
|
|
|
@@ -696,7 +797,7 @@ function keysChanged(collectionKey, partialCollection) {let notifyRegularSubscib
|
|
|
696
797
|
finalCollection[dataKey] = cachedCollection[dataKey];
|
|
697
798
|
}
|
|
698
799
|
|
|
699
|
-
|
|
800
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(subscriber, prevState[subscriber.statePropertyName], finalCollection, 'keysChanged', collectionKey);
|
|
700
801
|
return {
|
|
701
802
|
[subscriber.statePropertyName]: finalCollection
|
|
702
803
|
};
|
|
@@ -721,7 +822,7 @@ function keysChanged(collectionKey, partialCollection) {let notifyRegularSubscib
|
|
|
721
822
|
const prevData = prevState[subscriber.statePropertyName];
|
|
722
823
|
const newData = getSubsetOfData(cachedCollection[subscriber.key], subscriber.selector, subscriber.withOnyxInstance.state);
|
|
723
824
|
if (!(0,fast_equals__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(prevData, newData)) {
|
|
724
|
-
|
|
825
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(subscriber, prevData, newData, 'keysChanged', collectionKey);
|
|
725
826
|
return {
|
|
726
827
|
[subscriber.statePropertyName]: newData
|
|
727
828
|
};
|
|
@@ -737,14 +838,14 @@ function keysChanged(collectionKey, partialCollection) {let notifyRegularSubscib
|
|
|
737
838
|
const previousData = prevState[subscriber.statePropertyName];
|
|
738
839
|
|
|
739
840
|
// Avoids triggering unnecessary re-renders when feeding empty objects
|
|
740
|
-
if (
|
|
841
|
+
if (_utils__WEBPACK_IMPORTED_MODULE_4__["default"].areObjectsEmpty(data, previousData)) {
|
|
741
842
|
return null;
|
|
742
843
|
}
|
|
743
844
|
if (data === previousData) {
|
|
744
845
|
return null;
|
|
745
846
|
}
|
|
746
847
|
|
|
747
|
-
|
|
848
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(subscriber, previousData, data, 'keysChanged', collectionKey);
|
|
748
849
|
return {
|
|
749
850
|
[subscriber.statePropertyName]: data
|
|
750
851
|
};
|
|
@@ -822,7 +923,7 @@ function keyChanged(key, data, canUpdateSubscriber) {let notifyRegularSubscibers
|
|
|
822
923
|
...newData
|
|
823
924
|
};
|
|
824
925
|
if (!(0,fast_equals__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(prevData, prevDataWithNewData)) {
|
|
825
|
-
|
|
926
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(subscriber, prevData, newData, 'keyChanged', key);
|
|
826
927
|
return {
|
|
827
928
|
[subscriber.statePropertyName]: prevDataWithNewData
|
|
828
929
|
};
|
|
@@ -838,7 +939,7 @@ function keyChanged(key, data, canUpdateSubscriber) {let notifyRegularSubscibers
|
|
|
838
939
|
...collection,
|
|
839
940
|
[key]: data
|
|
840
941
|
};
|
|
841
|
-
|
|
942
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(subscriber, collection, newCollection, 'keyChanged', key);
|
|
842
943
|
return {
|
|
843
944
|
[subscriber.statePropertyName]: newCollection
|
|
844
945
|
};
|
|
@@ -867,14 +968,14 @@ function keyChanged(key, data, canUpdateSubscriber) {let notifyRegularSubscibers
|
|
|
867
968
|
const previousData = prevState[subscriber.statePropertyName];
|
|
868
969
|
|
|
869
970
|
// Avoids triggering unnecessary re-renders when feeding empty objects
|
|
870
|
-
if (
|
|
971
|
+
if (_utils__WEBPACK_IMPORTED_MODULE_4__["default"].areObjectsEmpty(data, previousData)) {
|
|
871
972
|
return null;
|
|
872
973
|
}
|
|
873
974
|
if (previousData === data) {
|
|
874
975
|
return null;
|
|
875
976
|
}
|
|
876
977
|
|
|
877
|
-
|
|
978
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(subscriber, previousData, data, 'keyChanged', key);
|
|
878
979
|
return {
|
|
879
980
|
[subscriber.statePropertyName]: data
|
|
880
981
|
};
|
|
@@ -921,7 +1022,7 @@ function sendDataToConnection(mapping, val, matchedKey, isBatched) {
|
|
|
921
1022
|
}
|
|
922
1023
|
}
|
|
923
1024
|
|
|
924
|
-
|
|
1025
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.logSetStateCall(mapping, null, newData, 'sendDataToConnection');
|
|
925
1026
|
if (isBatched) {
|
|
926
1027
|
batchUpdates(() => {
|
|
927
1028
|
mapping.withOnyxInstance.setWithOnyxState(mapping.statePropertyName, newData);
|
|
@@ -950,7 +1051,7 @@ function addKeyToRecentlyAccessedIfNeeded(mapping) {
|
|
|
950
1051
|
}
|
|
951
1052
|
|
|
952
1053
|
// Try to free some cache whenever we connect to a safe eviction key
|
|
953
|
-
|
|
1054
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].removeLeastRecentlyUsedKeys();
|
|
954
1055
|
|
|
955
1056
|
if (mapping.withOnyxInstance && !isCollectionKey(mapping.key)) {
|
|
956
1057
|
// All React components subscribing to a key flagged as a safe eviction key must implement the canEvict property.
|
|
@@ -1029,7 +1130,7 @@ function connect(mapping) {
|
|
|
1029
1130
|
// Performance improvement
|
|
1030
1131
|
// If the mapping is connected to an onyx key that is not a collection
|
|
1031
1132
|
// we can skip the call to getAllKeys() and return an array with a single item
|
|
1032
|
-
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !mapping.key.endsWith('_') &&
|
|
1133
|
+
if (Boolean(mapping.key) && typeof mapping.key === 'string' && !mapping.key.endsWith('_') && _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].storageKeys.has(mapping.key)) {
|
|
1033
1134
|
return [mapping.key];
|
|
1034
1135
|
}
|
|
1035
1136
|
return getAllKeys();
|
|
@@ -1046,7 +1147,7 @@ function connect(mapping) {
|
|
|
1046
1147
|
// component. This null value will be filtered out so that the connected component can utilize defaultProps.
|
|
1047
1148
|
if (matchingKeys.length === 0) {
|
|
1048
1149
|
if (mapping.key && !isCollectionKey(mapping.key)) {
|
|
1049
|
-
|
|
1150
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].set(mapping.key, null);
|
|
1050
1151
|
}
|
|
1051
1152
|
|
|
1052
1153
|
// Here we cannot use batching because the null value is expected to be set immediately for default props
|
|
@@ -1160,9 +1261,9 @@ function scheduleNotifyCollectionSubscribers(key, value) {
|
|
|
1160
1261
|
* @return {Promise}
|
|
1161
1262
|
*/
|
|
1162
1263
|
function remove(key) {
|
|
1163
|
-
|
|
1264
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].drop(key);
|
|
1164
1265
|
scheduleSubscriberUpdate(key, null);
|
|
1165
|
-
return
|
|
1266
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].removeItem(key);
|
|
1166
1267
|
}
|
|
1167
1268
|
|
|
1168
1269
|
/**
|
|
@@ -1170,12 +1271,12 @@ function remove(key) {
|
|
|
1170
1271
|
* @returns {Promise<void>}
|
|
1171
1272
|
*/
|
|
1172
1273
|
function reportStorageQuota() {
|
|
1173
|
-
return
|
|
1274
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].getDatabaseSize().
|
|
1174
1275
|
then((_ref) => {let { bytesUsed, bytesRemaining } = _ref;
|
|
1175
|
-
|
|
1276
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logInfo(`Storage Quota Check -- bytesUsed: ${bytesUsed} bytesRemaining: ${bytesRemaining}`);
|
|
1176
1277
|
}).
|
|
1177
1278
|
catch((dbSizeError) => {
|
|
1178
|
-
|
|
1279
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logAlert(`Unable to get database size. Error: ${dbSizeError}`);
|
|
1179
1280
|
});
|
|
1180
1281
|
}
|
|
1181
1282
|
|
|
@@ -1191,10 +1292,10 @@ function reportStorageQuota() {
|
|
|
1191
1292
|
* @return {Promise}
|
|
1192
1293
|
*/
|
|
1193
1294
|
function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {args[_key - 2] = arguments[_key];}
|
|
1194
|
-
|
|
1295
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logInfo(`Failed to save to storage. Error: ${error}. onyxMethod: ${onyxMethod.name}`);
|
|
1195
1296
|
|
|
1196
|
-
if (error &&
|
|
1197
|
-
|
|
1297
|
+
if (error && _Str__WEBPACK_IMPORTED_MODULE_9__.startsWith(error.message, "Failed to execute 'put' on 'IDBObjectStore'")) {
|
|
1298
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logAlert('Attempted to set invalid data set in Onyx. Please ensure all data is serializable.');
|
|
1198
1299
|
throw error;
|
|
1199
1300
|
}
|
|
1200
1301
|
|
|
@@ -1204,12 +1305,12 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
1204
1305
|
// If we have no acceptable keys to remove then we are possibly trying to save mission critical data. If this is the case,
|
|
1205
1306
|
// then we should stop retrying as there is not much the user can do to fix this. Instead of getting them stuck in an infinite loop we
|
|
1206
1307
|
// will allow this write to be skipped.
|
|
1207
|
-
|
|
1308
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logAlert('Out of storage. But found no acceptable keys to remove.');
|
|
1208
1309
|
return reportStorageQuota();
|
|
1209
1310
|
}
|
|
1210
1311
|
|
|
1211
1312
|
// Remove the least recently viewed key that is not currently being accessed and retry.
|
|
1212
|
-
|
|
1313
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logInfo(`Out of storage. Evicting least recently accessed key (${keyForRemoval}) and retrying.`);
|
|
1213
1314
|
reportStorageQuota();
|
|
1214
1315
|
return remove(keyForRemoval).then(() => onyxMethod(...args));
|
|
1215
1316
|
}
|
|
@@ -1226,14 +1327,14 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
1226
1327
|
*/
|
|
1227
1328
|
function broadcastUpdate(key, value, method, hasChanged) {let wasRemoved = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
1228
1329
|
// Logging properties only since values could be sensitive things we don't want to log
|
|
1229
|
-
|
|
1330
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logInfo(`${method}() called for key: ${key}${underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(value) ? ` properties: ${underscore__WEBPACK_IMPORTED_MODULE_1___default().keys(value).join(',')}` : ''}`);
|
|
1230
1331
|
|
|
1231
1332
|
// Update subscribers if the cached value has changed, or when the subscriber specifically requires
|
|
1232
1333
|
// all updates regardless of value changes (indicated by initWithStoredValues set to false).
|
|
1233
1334
|
if (hasChanged && !wasRemoved) {
|
|
1234
|
-
|
|
1335
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].set(key, value);
|
|
1235
1336
|
} else {
|
|
1236
|
-
|
|
1337
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].addToAccessedKeys(key);
|
|
1237
1338
|
}
|
|
1238
1339
|
|
|
1239
1340
|
return scheduleSubscriberUpdate(key, value, (subscriber) => hasChanged || subscriber.initWithStoredValues === false);
|
|
@@ -1263,7 +1364,7 @@ function removeNullValues(key, value) {
|
|
|
1263
1364
|
// We can remove all null values in an object by merging it with itself
|
|
1264
1365
|
// utils.fastMerge recursively goes through the object and removes all null values
|
|
1265
1366
|
// Passing two identical objects as source and target to fastMerge will not change it, but only remove the null values
|
|
1266
|
-
return { value:
|
|
1367
|
+
return { value: _utils__WEBPACK_IMPORTED_MODULE_4__["default"].removeNestedNullValues(value), wasRemoved: false };
|
|
1267
1368
|
}
|
|
1268
1369
|
|
|
1269
1370
|
/**
|
|
@@ -1275,8 +1376,8 @@ function removeNullValues(key, value) {
|
|
|
1275
1376
|
* @returns {Promise}
|
|
1276
1377
|
*/
|
|
1277
1378
|
function set(key, value) {
|
|
1278
|
-
if (!
|
|
1279
|
-
|
|
1379
|
+
if (!_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader()) {
|
|
1380
|
+
_broadcast__WEBPACK_IMPORTED_MODULE_12__.sendMessage({ type: METHOD.SET, key, value });
|
|
1280
1381
|
return Promise.resolve();
|
|
1281
1382
|
}
|
|
1282
1383
|
|
|
@@ -1291,7 +1392,7 @@ function set(key, value) {
|
|
|
1291
1392
|
delete mergeQueue[key];
|
|
1292
1393
|
}
|
|
1293
1394
|
|
|
1294
|
-
const hasChanged =
|
|
1395
|
+
const hasChanged = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].hasValueChanged(key, valueAfterRemoving);
|
|
1295
1396
|
|
|
1296
1397
|
// This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
|
|
1297
1398
|
const updatePromise = broadcastUpdate(key, valueAfterRemoving, 'set', hasChanged, wasRemoved);
|
|
@@ -1301,9 +1402,12 @@ function set(key, value) {
|
|
|
1301
1402
|
return updatePromise;
|
|
1302
1403
|
}
|
|
1303
1404
|
|
|
1304
|
-
return
|
|
1405
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].setItem(key, valueAfterRemoving).
|
|
1305
1406
|
catch((error) => evictStorageAndRetry(error, set, key, valueAfterRemoving)).
|
|
1306
|
-
then(() =>
|
|
1407
|
+
then(() => {
|
|
1408
|
+
sendActionToDevTools(METHOD.SET, key, valueAfterRemoving);
|
|
1409
|
+
return updatePromise;
|
|
1410
|
+
});
|
|
1307
1411
|
}
|
|
1308
1412
|
|
|
1309
1413
|
/**
|
|
@@ -1337,8 +1441,8 @@ function prepareKeyValuePairsForStorage(data) {
|
|
|
1337
1441
|
* @returns {Promise}
|
|
1338
1442
|
*/
|
|
1339
1443
|
function multiSet(data) {
|
|
1340
|
-
if (!
|
|
1341
|
-
|
|
1444
|
+
if (!_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader()) {
|
|
1445
|
+
_broadcast__WEBPACK_IMPORTED_MODULE_12__.sendMessage({ type: METHOD.MULTI_SET, data });
|
|
1342
1446
|
return Promise.resolve();
|
|
1343
1447
|
}
|
|
1344
1448
|
|
|
@@ -1350,13 +1454,16 @@ function multiSet(data) {
|
|
|
1350
1454
|
|
|
1351
1455
|
const updatePromises = underscore__WEBPACK_IMPORTED_MODULE_1___default().map(keyValuePairs, (_ref2) => {let [key, value] = _ref2;
|
|
1352
1456
|
// Update cache and optimistically inform subscribers on the next tick
|
|
1353
|
-
|
|
1457
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].set(key, value);
|
|
1354
1458
|
return scheduleSubscriberUpdate(key, value);
|
|
1355
1459
|
});
|
|
1356
1460
|
|
|
1357
|
-
return
|
|
1461
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].multiSet(keyValuePairs).
|
|
1358
1462
|
catch((error) => evictStorageAndRetry(error, multiSet, data)).
|
|
1359
|
-
then(() =>
|
|
1463
|
+
then(() => {
|
|
1464
|
+
sendActionToDevTools(METHOD.MULTI_SET, undefined, data);
|
|
1465
|
+
return Promise.all(updatePromises);
|
|
1466
|
+
});
|
|
1360
1467
|
}
|
|
1361
1468
|
|
|
1362
1469
|
/**
|
|
@@ -1377,7 +1484,7 @@ function applyMerge(existingValue, changes, shouldRemoveNullObjectValues) {
|
|
|
1377
1484
|
|
|
1378
1485
|
if (underscore__WEBPACK_IMPORTED_MODULE_1___default().some(changes, (underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject))) {
|
|
1379
1486
|
// Object values are then merged one after the other
|
|
1380
|
-
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(changes, (modifiedData, change) =>
|
|
1487
|
+
return underscore__WEBPACK_IMPORTED_MODULE_1___default().reduce(changes, (modifiedData, change) => _utils__WEBPACK_IMPORTED_MODULE_4__["default"].fastMerge(modifiedData, change, shouldRemoveNullObjectValues), existingValue || {});
|
|
1381
1488
|
}
|
|
1382
1489
|
|
|
1383
1490
|
// If we have anything else we can't merge it so we'll
|
|
@@ -1406,8 +1513,8 @@ function applyMerge(existingValue, changes, shouldRemoveNullObjectValues) {
|
|
|
1406
1513
|
* @returns {Promise}
|
|
1407
1514
|
*/
|
|
1408
1515
|
function merge(key, changes) {
|
|
1409
|
-
if (!
|
|
1410
|
-
|
|
1516
|
+
if (!_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader()) {
|
|
1517
|
+
_broadcast__WEBPACK_IMPORTED_MODULE_12__.sendMessage({ type: METHOD.MERGE, key, changes });
|
|
1411
1518
|
return Promise.resolve();
|
|
1412
1519
|
}
|
|
1413
1520
|
|
|
@@ -1462,7 +1569,7 @@ function merge(key, changes) {
|
|
|
1462
1569
|
batchedChanges = applyMerge(undefined, [batchedChanges], true);
|
|
1463
1570
|
}
|
|
1464
1571
|
|
|
1465
|
-
const hasChanged =
|
|
1572
|
+
const hasChanged = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].hasValueChanged(key, modifiedData);
|
|
1466
1573
|
|
|
1467
1574
|
// This approach prioritizes fast UI changes without waiting for data to be stored in device storage.
|
|
1468
1575
|
const updatePromise = broadcastUpdate(key, modifiedData, 'merge', hasChanged, wasRemoved);
|
|
@@ -1472,9 +1579,12 @@ function merge(key, changes) {
|
|
|
1472
1579
|
return updatePromise;
|
|
1473
1580
|
}
|
|
1474
1581
|
|
|
1475
|
-
return
|
|
1582
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].mergeItem(key, batchedChanges, modifiedData).then(() => {
|
|
1583
|
+
sendActionToDevTools(METHOD.MERGE, key, changes, modifiedData);
|
|
1584
|
+
return updatePromise;
|
|
1585
|
+
});
|
|
1476
1586
|
} catch (error) {
|
|
1477
|
-
|
|
1587
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
|
|
1478
1588
|
return Promise.resolve();
|
|
1479
1589
|
}
|
|
1480
1590
|
});
|
|
@@ -1488,11 +1598,11 @@ function merge(key, changes) {
|
|
|
1488
1598
|
* @returns {Promise}
|
|
1489
1599
|
*/
|
|
1490
1600
|
function initializeWithDefaultKeyStates() {
|
|
1491
|
-
return
|
|
1601
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].multiGet(underscore__WEBPACK_IMPORTED_MODULE_1___default().keys(defaultKeyStates)).then((pairs) => {
|
|
1492
1602
|
const asObject = underscore__WEBPACK_IMPORTED_MODULE_1___default().object(pairs);
|
|
1493
1603
|
|
|
1494
|
-
const merged =
|
|
1495
|
-
|
|
1604
|
+
const merged = _utils__WEBPACK_IMPORTED_MODULE_4__["default"].fastMerge(asObject, defaultKeyStates);
|
|
1605
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].merge(merged);
|
|
1496
1606
|
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(merged, (val, key) => keyChanged(key, val));
|
|
1497
1607
|
});
|
|
1498
1608
|
}
|
|
@@ -1520,8 +1630,8 @@ function initializeWithDefaultKeyStates() {
|
|
|
1520
1630
|
* @returns {Promise<void>}
|
|
1521
1631
|
*/
|
|
1522
1632
|
function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1523
|
-
if (!
|
|
1524
|
-
|
|
1633
|
+
if (!_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader()) {
|
|
1634
|
+
_broadcast__WEBPACK_IMPORTED_MODULE_12__.sendMessage({ type: METHOD.CLEAR, keysToPreserve });
|
|
1525
1635
|
return Promise.resolve();
|
|
1526
1636
|
}
|
|
1527
1637
|
|
|
@@ -1550,10 +1660,10 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1550
1660
|
// 2. Figure out whether it is a collection key or not,
|
|
1551
1661
|
// since collection key subscribers need to be updated differently
|
|
1552
1662
|
if (!isKeyToPreserve) {
|
|
1553
|
-
const oldValue =
|
|
1663
|
+
const oldValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].getValue(key);
|
|
1554
1664
|
const newValue = underscore__WEBPACK_IMPORTED_MODULE_1___default().get(defaultKeyStates, key, null);
|
|
1555
1665
|
if (newValue !== oldValue) {
|
|
1556
|
-
|
|
1666
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].set(key, newValue);
|
|
1557
1667
|
const collectionKey = key.substring(0, key.indexOf('_') + 1);
|
|
1558
1668
|
if (collectionKey) {
|
|
1559
1669
|
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
@@ -1587,12 +1697,13 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1587
1697
|
const defaultKeyValuePairs = underscore__WEBPACK_IMPORTED_MODULE_1___default().pairs(underscore__WEBPACK_IMPORTED_MODULE_1___default().omit(defaultKeyStates, keysToPreserve));
|
|
1588
1698
|
|
|
1589
1699
|
// Remove only the items that we want cleared from storage, and reset others to default
|
|
1590
|
-
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keysToBeClearedFromStorage, (key) =>
|
|
1591
|
-
return
|
|
1592
|
-
then(() =>
|
|
1700
|
+
underscore__WEBPACK_IMPORTED_MODULE_1___default().each(keysToBeClearedFromStorage, (key) => _OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].drop(key));
|
|
1701
|
+
return _storage__WEBPACK_IMPORTED_MODULE_7__["default"].removeItems(keysToBeClearedFromStorage).
|
|
1702
|
+
then(() => _storage__WEBPACK_IMPORTED_MODULE_7__["default"].multiSet(defaultKeyValuePairs)).
|
|
1593
1703
|
then(() => {
|
|
1594
1704
|
isClearing = false;
|
|
1595
|
-
|
|
1705
|
+
_broadcast__WEBPACK_IMPORTED_MODULE_12__.sendMessage({ type: METHOD.CLEAR, keysToPreserve });
|
|
1706
|
+
_DevTools__WEBPACK_IMPORTED_MODULE_3__["default"].clearState(keysToPreserve);
|
|
1596
1707
|
return Promise.all(updatePromises);
|
|
1597
1708
|
});
|
|
1598
1709
|
});
|
|
@@ -1614,7 +1725,7 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1614
1725
|
*/
|
|
1615
1726
|
function mergeCollection(collectionKey, collection) {
|
|
1616
1727
|
if (!underscore__WEBPACK_IMPORTED_MODULE_1___default().isObject(collection) || underscore__WEBPACK_IMPORTED_MODULE_1___default().isArray(collection) || underscore__WEBPACK_IMPORTED_MODULE_1___default().isEmpty(collection)) {
|
|
1617
|
-
|
|
1728
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logInfo('mergeCollection() called with invalid or empty value. Skipping this update.');
|
|
1618
1729
|
return Promise.resolve();
|
|
1619
1730
|
}
|
|
1620
1731
|
|
|
@@ -1630,7 +1741,7 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1630
1741
|
}
|
|
1631
1742
|
|
|
1632
1743
|
hasCollectionKeyCheckFailed = true;
|
|
1633
|
-
|
|
1744
|
+
_Logger__WEBPACK_IMPORTED_MODULE_8__.logAlert(`Provided collection doesn't have all its data belonging to the same parent. CollectionKey: ${collectionKey}, DataKey: ${dataKey}`);
|
|
1634
1745
|
});
|
|
1635
1746
|
|
|
1636
1747
|
// Gracefully handle bad mergeCollection updates so it doesn't block the merge queue
|
|
@@ -1662,23 +1773,26 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1662
1773
|
// New keys will be added via multiSet while existing keys will be updated using multiMerge
|
|
1663
1774
|
// This is because setting a key that doesn't exist yet with multiMerge will throw errors
|
|
1664
1775
|
if (keyValuePairsForExistingCollection.length > 0) {
|
|
1665
|
-
promises.push(
|
|
1776
|
+
promises.push(_storage__WEBPACK_IMPORTED_MODULE_7__["default"].multiMerge(keyValuePairsForExistingCollection));
|
|
1666
1777
|
}
|
|
1667
1778
|
|
|
1668
1779
|
if (keyValuePairsForNewCollection.length > 0) {
|
|
1669
|
-
promises.push(
|
|
1780
|
+
promises.push(_storage__WEBPACK_IMPORTED_MODULE_7__["default"].multiSet(keyValuePairsForNewCollection));
|
|
1670
1781
|
}
|
|
1671
1782
|
|
|
1672
1783
|
// Prefill cache if necessary by calling get() on any existing keys and then merge original data to cache
|
|
1673
1784
|
// and update all subscribers
|
|
1674
1785
|
const promiseUpdate = Promise.all(underscore__WEBPACK_IMPORTED_MODULE_1___default().map(existingKeys, get)).then(() => {
|
|
1675
|
-
|
|
1786
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].merge(collection);
|
|
1676
1787
|
return scheduleNotifyCollectionSubscribers(collectionKey, collection);
|
|
1677
1788
|
});
|
|
1678
1789
|
|
|
1679
1790
|
return Promise.all(promises).
|
|
1680
1791
|
catch((error) => evictStorageAndRetry(error, mergeCollection, collection)).
|
|
1681
|
-
then(() =>
|
|
1792
|
+
then(() => {
|
|
1793
|
+
sendActionToDevTools(METHOD.MERGE_COLLECTION, undefined, collection);
|
|
1794
|
+
return promiseUpdate;
|
|
1795
|
+
});
|
|
1682
1796
|
});
|
|
1683
1797
|
}
|
|
1684
1798
|
|
|
@@ -1737,10 +1851,10 @@ function update(data) {
|
|
|
1737
1851
|
* @param {string[]} keyList
|
|
1738
1852
|
*/
|
|
1739
1853
|
function setMemoryOnlyKeys(keyList) {
|
|
1740
|
-
|
|
1854
|
+
_storage__WEBPACK_IMPORTED_MODULE_7__["default"].setMemoryOnlyKeys(keyList);
|
|
1741
1855
|
|
|
1742
1856
|
// When in memory only mode for certain keys we do not want to ever drop items from the cache as the user will have no way to recover them again via storage.
|
|
1743
|
-
|
|
1857
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].setRecentKeysLimit(Infinity);
|
|
1744
1858
|
}
|
|
1745
1859
|
|
|
1746
1860
|
/**
|
|
@@ -1756,8 +1870,8 @@ function onClear(callback) {
|
|
|
1756
1870
|
* types of events.
|
|
1757
1871
|
*/
|
|
1758
1872
|
function subscribeToEvents() {
|
|
1759
|
-
|
|
1760
|
-
if (!
|
|
1873
|
+
_broadcast__WEBPACK_IMPORTED_MODULE_12__.subscribe((_ref5) => {let { data } = _ref5;
|
|
1874
|
+
if (!_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader()) {
|
|
1761
1875
|
return;
|
|
1762
1876
|
}
|
|
1763
1877
|
switch (data.type) {
|
|
@@ -1819,10 +1933,10 @@ function init()
|
|
|
1819
1933
|
|
|
1820
1934
|
|
|
1821
1935
|
{let { keys = {}, initialKeyStates = {}, safeEvictionKeys = [], maxCachedKeysCount = 1000, captureMetrics = false, shouldSyncMultipleInstances = Boolean(__webpack_require__.g.localStorage), debugSetState = false } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1822
|
-
|
|
1936
|
+
_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.init();
|
|
1823
1937
|
|
|
1824
|
-
|
|
1825
|
-
if (!
|
|
1938
|
+
_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isReady().then(() => {
|
|
1939
|
+
if (!_ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader()) {
|
|
1826
1940
|
return;
|
|
1827
1941
|
}
|
|
1828
1942
|
subscribeToEvents();
|
|
@@ -1835,11 +1949,11 @@ function init()
|
|
|
1835
1949
|
}
|
|
1836
1950
|
|
|
1837
1951
|
if (debugSetState) {
|
|
1838
|
-
|
|
1952
|
+
_metrics_PerformanceUtils__WEBPACK_IMPORTED_MODULE_10__.setShouldDebugSetState(true);
|
|
1839
1953
|
}
|
|
1840
1954
|
|
|
1841
1955
|
if (maxCachedKeysCount > 0) {
|
|
1842
|
-
|
|
1956
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].setRecentKeysLimit(maxCachedKeysCount);
|
|
1843
1957
|
}
|
|
1844
1958
|
|
|
1845
1959
|
// We need the value of the collection keys later for checking if a
|
|
@@ -1857,15 +1971,17 @@ function init()
|
|
|
1857
1971
|
// Set our default key states to use when initializing and clearing Onyx data
|
|
1858
1972
|
defaultKeyStates = initialKeyStates;
|
|
1859
1973
|
|
|
1974
|
+
_DevTools__WEBPACK_IMPORTED_MODULE_3__["default"].initState(initialKeyStates);
|
|
1975
|
+
|
|
1860
1976
|
// Let Onyx know about which keys are safe to evict
|
|
1861
1977
|
evictionAllowList = safeEvictionKeys;
|
|
1862
1978
|
|
|
1863
1979
|
// Initialize all of our keys with data provided then give green light to any pending connections
|
|
1864
1980
|
Promise.all([addAllSafeEvictionKeysToRecentlyAccessedList(), initializeWithDefaultKeyStates()]).then(deferredInitTask.resolve);
|
|
1865
1981
|
|
|
1866
|
-
if (shouldSyncMultipleInstances && underscore__WEBPACK_IMPORTED_MODULE_1___default().isFunction(
|
|
1867
|
-
|
|
1868
|
-
|
|
1982
|
+
if (shouldSyncMultipleInstances && underscore__WEBPACK_IMPORTED_MODULE_1___default().isFunction(_storage__WEBPACK_IMPORTED_MODULE_7__["default"].keepInstancesSync)) {
|
|
1983
|
+
_storage__WEBPACK_IMPORTED_MODULE_7__["default"].keepInstancesSync((key, value) => {
|
|
1984
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_6__["default"].set(key, value);
|
|
1869
1985
|
keyChanged(key, value);
|
|
1870
1986
|
});
|
|
1871
1987
|
}
|
|
@@ -1882,7 +1998,7 @@ const Onyx = {
|
|
|
1882
1998
|
clear,
|
|
1883
1999
|
getAllKeys,
|
|
1884
2000
|
init,
|
|
1885
|
-
registerLogger:
|
|
2001
|
+
registerLogger: _Logger__WEBPACK_IMPORTED_MODULE_8__.registerLogger,
|
|
1886
2002
|
addToEvictionBlockList,
|
|
1887
2003
|
removeFromEvictionBlockList,
|
|
1888
2004
|
isSafeEvictionKey,
|
|
@@ -1891,9 +2007,9 @@ const Onyx = {
|
|
|
1891
2007
|
tryGetCachedValue,
|
|
1892
2008
|
hasPendingMergeForKey,
|
|
1893
2009
|
onClear,
|
|
1894
|
-
isClientManagerReady:
|
|
1895
|
-
isClientTheLeader:
|
|
1896
|
-
subscribeToClientChange:
|
|
2010
|
+
isClientManagerReady: _ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isReady,
|
|
2011
|
+
isClientTheLeader: _ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.isClientTheLeader,
|
|
2012
|
+
subscribeToClientChange: _ActiveClientManager__WEBPACK_IMPORTED_MODULE_11__.subscribeToClientChange
|
|
1897
2013
|
};
|
|
1898
2014
|
|
|
1899
2015
|
/**
|
|
@@ -2840,7 +2956,11 @@ function removeNestedNullValues(value) {
|
|
|
2840
2956
|
return value;
|
|
2841
2957
|
}
|
|
2842
2958
|
|
|
2843
|
-
|
|
2959
|
+
function formatActionName(method, key) {
|
|
2960
|
+
return key ? `${method.toUpperCase()}/${key}` : method.toUpperCase();
|
|
2961
|
+
}
|
|
2962
|
+
|
|
2963
|
+
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ areObjectsEmpty, fastMerge, formatActionName, removeNestedNullValues });
|
|
2844
2964
|
|
|
2845
2965
|
/***/ }),
|
|
2846
2966
|
|