react-native-onyx 1.0.26 → 1.0.28
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/web.development.js +26 -12
- 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/Onyx.js +25 -11
- package/package.json +1 -1
package/lib/Onyx.js
CHANGED
|
@@ -10,6 +10,14 @@ import createDeferredTask from './createDeferredTask';
|
|
|
10
10
|
import fastMerge from './fastMerge';
|
|
11
11
|
import * as PerformanceUtils from './metrics/PerformanceUtils';
|
|
12
12
|
|
|
13
|
+
// Method constants
|
|
14
|
+
const METHOD = {
|
|
15
|
+
SET: 'set',
|
|
16
|
+
MERGE: 'merge',
|
|
17
|
+
MERGE_COLLECTION: 'mergecollection',
|
|
18
|
+
CLEAR: 'clear',
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
// Keeps track of the last connectionID that was used so we can keep incrementing it
|
|
14
22
|
let lastConnectionID = 0;
|
|
15
23
|
|
|
@@ -515,7 +523,7 @@ function keyChanged(key, data, canUpdateSubscriber) {
|
|
|
515
523
|
// returned by the selector and only if the selected data has changed.
|
|
516
524
|
if (subscriber.selector) {
|
|
517
525
|
subscriber.withOnyxInstance.setState((prevState) => {
|
|
518
|
-
const previousValue = getSubsetOfData(prevState, subscriber.selector);
|
|
526
|
+
const previousValue = getSubsetOfData(prevState[subscriber.statePropertyName], subscriber.selector);
|
|
519
527
|
const newValue = getSubsetOfData(data, subscriber.selector);
|
|
520
528
|
if (!deepEqual(previousValue, newValue)) {
|
|
521
529
|
return {
|
|
@@ -1101,36 +1109,41 @@ function mergeCollection(collectionKey, collection) {
|
|
|
1101
1109
|
* Insert API responses and lifecycle data into Onyx
|
|
1102
1110
|
*
|
|
1103
1111
|
* @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge', 'mergeCollection'), key: string, value: *}
|
|
1112
|
+
* @returns {Promise} resolves when all operations are complete
|
|
1104
1113
|
*/
|
|
1105
1114
|
function update(data) {
|
|
1106
1115
|
// First, validate the Onyx object is in the format we expect
|
|
1107
1116
|
_.each(data, ({onyxMethod, key}) => {
|
|
1108
|
-
if (!_.contains([
|
|
1117
|
+
if (!_.contains([METHOD.CLEAR, METHOD.SET, METHOD.MERGE, METHOD.MERGE_COLLECTION], onyxMethod)) {
|
|
1109
1118
|
throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`);
|
|
1110
1119
|
}
|
|
1111
|
-
if (onyxMethod !==
|
|
1120
|
+
if (onyxMethod !== METHOD.CLEAR && !_.isString(key)) {
|
|
1112
1121
|
throw new Error(`Invalid ${typeof key} key provided in Onyx update. Onyx key must be of type string.`);
|
|
1113
1122
|
}
|
|
1114
1123
|
});
|
|
1115
1124
|
|
|
1125
|
+
const promises = [];
|
|
1126
|
+
|
|
1116
1127
|
_.each(data, ({onyxMethod, key, value}) => {
|
|
1117
1128
|
switch (onyxMethod) {
|
|
1118
|
-
case
|
|
1119
|
-
set(key, value);
|
|
1129
|
+
case METHOD.SET:
|
|
1130
|
+
promises.push(set(key, value));
|
|
1120
1131
|
break;
|
|
1121
|
-
case
|
|
1122
|
-
merge(key, value);
|
|
1132
|
+
case METHOD.MERGE:
|
|
1133
|
+
promises.push(merge(key, value));
|
|
1123
1134
|
break;
|
|
1124
|
-
case
|
|
1125
|
-
mergeCollection(key, value);
|
|
1135
|
+
case METHOD.MERGE_COLLECTION:
|
|
1136
|
+
promises.push(mergeCollection(key, value));
|
|
1126
1137
|
break;
|
|
1127
|
-
case
|
|
1128
|
-
clear();
|
|
1138
|
+
case METHOD.CLEAR:
|
|
1139
|
+
promises.push(clear());
|
|
1129
1140
|
break;
|
|
1130
1141
|
default:
|
|
1131
1142
|
break;
|
|
1132
1143
|
}
|
|
1133
1144
|
});
|
|
1145
|
+
|
|
1146
|
+
return Promise.all(promises);
|
|
1134
1147
|
}
|
|
1135
1148
|
|
|
1136
1149
|
/**
|
|
@@ -1219,6 +1232,7 @@ const Onyx = {
|
|
|
1219
1232
|
addToEvictionBlockList,
|
|
1220
1233
|
removeFromEvictionBlockList,
|
|
1221
1234
|
isSafeEvictionKey,
|
|
1235
|
+
METHOD,
|
|
1222
1236
|
};
|
|
1223
1237
|
|
|
1224
1238
|
/**
|