react-native-onyx 2.0.48 → 2.0.49
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/dist/Onyx.js +35 -1
- package/dist/OnyxUtils.d.ts +2 -0
- package/dist/OnyxUtils.js +8 -0
- package/package.json +1 -1
package/dist/Onyx.js
CHANGED
|
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
/* eslint-disable no-continue */
|
|
30
30
|
const underscore_1 = __importDefault(require("underscore"));
|
|
31
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
31
32
|
const Logger = __importStar(require("./Logger"));
|
|
32
33
|
const OnyxCache_1 = __importDefault(require("./OnyxCache"));
|
|
33
34
|
const createDeferredTask_1 = __importDefault(require("./createDeferredTask"));
|
|
@@ -549,6 +550,36 @@ function clear(keysToPreserve = []) {
|
|
|
549
550
|
})
|
|
550
551
|
.then(() => undefined);
|
|
551
552
|
}
|
|
553
|
+
function updateSnapshots(data) {
|
|
554
|
+
const snapshotCollectionKey = OnyxUtils_1.default.getSnapshotKey();
|
|
555
|
+
if (!snapshotCollectionKey)
|
|
556
|
+
return;
|
|
557
|
+
const promises = [];
|
|
558
|
+
const snapshotCollection = OnyxUtils_1.default.getCachedCollection(snapshotCollectionKey);
|
|
559
|
+
Object.entries(snapshotCollection).forEach(([snapshotKey, snapshotValue]) => {
|
|
560
|
+
// Snapshots may not be present in cache. We don't know how to update them so we skip.
|
|
561
|
+
if (!snapshotValue) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
let updatedData = {};
|
|
565
|
+
data.forEach(({ key, value }) => {
|
|
566
|
+
// snapshots are normal keys so we want to skip update if they are written to Onyx
|
|
567
|
+
if (OnyxUtils_1.default.isCollectionMemberKey(snapshotCollectionKey, key)) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
if (typeof snapshotValue !== 'object' || !('data' in snapshotValue)) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const snapshotData = snapshotValue.data;
|
|
574
|
+
if (!snapshotData || !snapshotData[key]) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
updatedData = Object.assign(Object.assign({}, updatedData), { [key]: (0, pick_1.default)(value, Object.keys(snapshotData[key])) });
|
|
578
|
+
});
|
|
579
|
+
promises.push(() => merge(snapshotKey, { data: updatedData }));
|
|
580
|
+
});
|
|
581
|
+
return Promise.all(promises.map((p) => p()));
|
|
582
|
+
}
|
|
552
583
|
/**
|
|
553
584
|
* Insert API responses and lifecycle data into Onyx
|
|
554
585
|
*
|
|
@@ -595,7 +626,10 @@ function update(data) {
|
|
|
595
626
|
break;
|
|
596
627
|
}
|
|
597
628
|
});
|
|
598
|
-
return clearPromise
|
|
629
|
+
return clearPromise
|
|
630
|
+
.then(() => Promise.all(promises.map((p) => p())))
|
|
631
|
+
.then(() => updateSnapshots(data))
|
|
632
|
+
.then(() => undefined);
|
|
599
633
|
}
|
|
600
634
|
const Onyx = {
|
|
601
635
|
METHOD: OnyxUtils_1.default.METHOD,
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare const METHOD: {
|
|
|
9
9
|
readonly CLEAR: "clear";
|
|
10
10
|
};
|
|
11
11
|
type OnyxMethod = ValueOf<typeof METHOD>;
|
|
12
|
+
declare function getSnapshotKey(): OnyxKey | null;
|
|
12
13
|
/**
|
|
13
14
|
* Getter - returns the merge queue.
|
|
14
15
|
*/
|
|
@@ -235,5 +236,6 @@ declare const OnyxUtils: {
|
|
|
235
236
|
prepareKeyValuePairsForStorage: typeof prepareKeyValuePairsForStorage;
|
|
236
237
|
applyMerge: typeof applyMerge;
|
|
237
238
|
initializeWithDefaultKeyStates: typeof initializeWithDefaultKeyStates;
|
|
239
|
+
getSnapshotKey: typeof getSnapshotKey;
|
|
238
240
|
};
|
|
239
241
|
export default OnyxUtils;
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -65,6 +65,10 @@ const evictionBlocklist = {};
|
|
|
65
65
|
let defaultKeyStates = {};
|
|
66
66
|
let batchUpdatesPromise = null;
|
|
67
67
|
let batchUpdatesQueue = [];
|
|
68
|
+
let snapshotKey = null;
|
|
69
|
+
function getSnapshotKey() {
|
|
70
|
+
return snapshotKey;
|
|
71
|
+
}
|
|
68
72
|
/**
|
|
69
73
|
* Getter - returns the merge queue.
|
|
70
74
|
*/
|
|
@@ -110,6 +114,9 @@ function initStoreValues(keys, initialKeyStates, safeEvictionKeys) {
|
|
|
110
114
|
DevTools_1.default.initState(initialKeyStates);
|
|
111
115
|
// Let Onyx know about which keys are safe to evict
|
|
112
116
|
evictionAllowList = safeEvictionKeys;
|
|
117
|
+
if (typeof keys.COLLECTION === 'object' && typeof keys.COLLECTION.SNAPSHOT === 'string') {
|
|
118
|
+
snapshotKey = keys.COLLECTION.SNAPSHOT;
|
|
119
|
+
}
|
|
113
120
|
}
|
|
114
121
|
function sendActionToDevTools(method, key, value, mergedValue = undefined) {
|
|
115
122
|
DevTools_1.default.registerAction(utils_1.default.formatActionName(method, key), value, key ? { [key]: mergedValue || value } : value);
|
|
@@ -931,5 +938,6 @@ const OnyxUtils = {
|
|
|
931
938
|
prepareKeyValuePairsForStorage,
|
|
932
939
|
applyMerge,
|
|
933
940
|
initializeWithDefaultKeyStates,
|
|
941
|
+
getSnapshotKey,
|
|
934
942
|
};
|
|
935
943
|
exports.default = OnyxUtils;
|