react-native-onyx 2.0.129 → 2.0.131
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.d.ts +1 -1
- package/dist/Onyx.js +2 -2
- package/dist/OnyxUtils.d.ts +1 -2
- package/dist/OnyxUtils.js +2 -14
- package/dist/types.d.ts +0 -7
- package/dist/useOnyx.js +34 -13
- package/package.json +1 -1
package/dist/Onyx.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as Logger from './Logger';
|
|
|
2
2
|
import type { CollectionKeyBase, ConnectOptions, InitOptions, Mapping, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate, SetOptions } from './types';
|
|
3
3
|
import type { Connection } from './OnyxConnectionManager';
|
|
4
4
|
/** Initialize the store with actions and listening for storage events */
|
|
5
|
-
declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances, debugSetState, enablePerformanceMetrics, skippableCollectionMemberIDs,
|
|
5
|
+
declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances, debugSetState, enablePerformanceMetrics, skippableCollectionMemberIDs, }: InitOptions): void;
|
|
6
6
|
/**
|
|
7
7
|
* Connects to an Onyx key given the options passed and listens to its changes.
|
|
8
8
|
* This method will be deprecated soon. Please use `Onyx.connectWithoutView()` instead.
|
package/dist/Onyx.js
CHANGED
|
@@ -49,7 +49,7 @@ const GlobalSettings = __importStar(require("./GlobalSettings"));
|
|
|
49
49
|
const metrics_1 = __importDefault(require("./metrics"));
|
|
50
50
|
const OnyxMerge_1 = __importDefault(require("./OnyxMerge"));
|
|
51
51
|
/** Initialize the store with actions and listening for storage events */
|
|
52
|
-
function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = !!global.localStorage, debugSetState = false, enablePerformanceMetrics = false, skippableCollectionMemberIDs = [],
|
|
52
|
+
function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = !!global.localStorage, debugSetState = false, enablePerformanceMetrics = false, skippableCollectionMemberIDs = [], }) {
|
|
53
53
|
var _a;
|
|
54
54
|
if (enablePerformanceMetrics) {
|
|
55
55
|
GlobalSettings.setPerformanceMetricsEnabled(true);
|
|
@@ -70,7 +70,7 @@ function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedK
|
|
|
70
70
|
if (maxCachedKeysCount > 0) {
|
|
71
71
|
OnyxCache_1.default.setRecentKeysLimit(maxCachedKeysCount);
|
|
72
72
|
}
|
|
73
|
-
OnyxUtils_1.default.initStoreValues(keys, initialKeyStates, evictableKeys
|
|
73
|
+
OnyxUtils_1.default.initStoreValues(keys, initialKeyStates, evictableKeys);
|
|
74
74
|
// Initialize all of our keys with data provided then give green light to any pending connections
|
|
75
75
|
Promise.all([OnyxCache_1.default.addEvictableKeysToRecentlyAccessedList(OnyxUtils_1.default.isCollectionKey, OnyxUtils_1.default.getAllKeys), OnyxUtils_1.default.initializeWithDefaultKeyStates()]).then(OnyxUtils_1.default.getDeferredInitTask().resolve);
|
|
76
76
|
}
|
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -45,9 +45,8 @@ declare function setSkippableCollectionMemberIDs(ids: Set<string>): void;
|
|
|
45
45
|
* @param keys - `ONYXKEYS` constants object from Onyx.init()
|
|
46
46
|
* @param initialKeyStates - initial data to set when `init()` and `clear()` are called
|
|
47
47
|
* @param evictableKeys - This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal.
|
|
48
|
-
* @param fullyMergedSnapshotKeys - Array of snapshot collection keys where full merge is supported and data structure can be changed after merge.
|
|
49
48
|
*/
|
|
50
|
-
declare function initStoreValues(keys: DeepRecord<string, OnyxKey>, initialKeyStates: Partial<KeyValueMapping>, evictableKeys: OnyxKey[]
|
|
49
|
+
declare function initStoreValues(keys: DeepRecord<string, OnyxKey>, initialKeyStates: Partial<KeyValueMapping>, evictableKeys: OnyxKey[]): void;
|
|
51
50
|
/**
|
|
52
51
|
* Sends an action to DevTools extension
|
|
53
52
|
*
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -79,7 +79,6 @@ let batchUpdatesQueue = [];
|
|
|
79
79
|
// Used for comparison with a new update to avoid invoking the Onyx.connect callback with the same data.
|
|
80
80
|
let lastConnectionCallbackData = new Map();
|
|
81
81
|
let snapshotKey = null;
|
|
82
|
-
let fullyMergedSnapshotKeys;
|
|
83
82
|
// Keeps track of the last subscriptionID that was used so we can keep incrementing it
|
|
84
83
|
let lastSubscriptionID = 0;
|
|
85
84
|
// Connections can be made before `Onyx.init`. They would wait for this task before resolving
|
|
@@ -131,9 +130,8 @@ function setSkippableCollectionMemberIDs(ids) {
|
|
|
131
130
|
* @param keys - `ONYXKEYS` constants object from Onyx.init()
|
|
132
131
|
* @param initialKeyStates - initial data to set when `init()` and `clear()` are called
|
|
133
132
|
* @param evictableKeys - This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal.
|
|
134
|
-
* @param fullyMergedSnapshotKeys - Array of snapshot collection keys where full merge is supported and data structure can be changed after merge.
|
|
135
133
|
*/
|
|
136
|
-
function initStoreValues(keys, initialKeyStates, evictableKeys
|
|
134
|
+
function initStoreValues(keys, initialKeyStates, evictableKeys) {
|
|
137
135
|
var _a;
|
|
138
136
|
// We need the value of the collection keys later for checking if a
|
|
139
137
|
// key is a collection. We store it in a map for faster lookup.
|
|
@@ -151,7 +149,6 @@ function initStoreValues(keys, initialKeyStates, evictableKeys, fullyMergedSnaps
|
|
|
151
149
|
OnyxCache_1.default.setCollectionKeys(onyxCollectionKeySet);
|
|
152
150
|
if (typeof keys.COLLECTION === 'object' && typeof keys.COLLECTION.SNAPSHOT === 'string') {
|
|
153
151
|
snapshotKey = keys.COLLECTION.SNAPSHOT;
|
|
154
|
-
fullyMergedSnapshotKeys = new Set(fullyMergedSnapshotKeysParam !== null && fullyMergedSnapshotKeysParam !== void 0 ? fullyMergedSnapshotKeysParam : []);
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
154
|
function sendActionToDevTools(method, key, value, mergedValue = undefined) {
|
|
@@ -1220,16 +1217,7 @@ function updateSnapshots(data, mergeFn) {
|
|
|
1220
1217
|
return;
|
|
1221
1218
|
}
|
|
1222
1219
|
const oldValue = updatedData[key] || {};
|
|
1223
|
-
|
|
1224
|
-
try {
|
|
1225
|
-
collectionKey = getCollectionKey(key);
|
|
1226
|
-
}
|
|
1227
|
-
catch (e) {
|
|
1228
|
-
// If getCollectionKey() throws an error it means the key is not a collection key.
|
|
1229
|
-
collectionKey = undefined;
|
|
1230
|
-
}
|
|
1231
|
-
const shouldFullyMerge = fullyMergedSnapshotKeys === null || fullyMergedSnapshotKeys === void 0 ? void 0 : fullyMergedSnapshotKeys.has(collectionKey || key);
|
|
1232
|
-
const newValue = shouldFullyMerge ? value : (0, pick_1.default)(value, Object.keys(snapshotData[key]));
|
|
1220
|
+
const newValue = (0, pick_1.default)(value, Object.keys(snapshotData[key]));
|
|
1233
1221
|
updatedData = Object.assign(Object.assign({}, updatedData), { [key]: Object.assign(oldValue, newValue) });
|
|
1234
1222
|
});
|
|
1235
1223
|
// Skip the update if there's no data to be merged
|
package/dist/types.d.ts
CHANGED
|
@@ -411,13 +411,6 @@ type InitOptions = {
|
|
|
411
411
|
* Additionally, any subscribers from these keys to won't receive any data from Onyx.
|
|
412
412
|
*/
|
|
413
413
|
skippableCollectionMemberIDs?: string[];
|
|
414
|
-
/**
|
|
415
|
-
* Array of snapshot collection keys where full merge is supported and data structure can be changed after merge.
|
|
416
|
-
* For e.g. if oldSnapshotData is {report_1: {name 'Fitsum'}} and BE update is {report_1: {name:'Fitsum2', nickName:'Fitse'}}
|
|
417
|
-
* if it is fullyMergedSnapshotkey the `nickName` prop that didn't exist in the previous data will be merged
|
|
418
|
-
* otherwise only existing prop will be picked from the BE update and merged (in this case only name).
|
|
419
|
-
*/
|
|
420
|
-
fullyMergedSnapshotKeys?: string[];
|
|
421
414
|
};
|
|
422
415
|
type GenericFunction = (...args: any[]) => any;
|
|
423
416
|
/**
|
package/dist/useOnyx.js
CHANGED
|
@@ -42,15 +42,33 @@ const OnyxCache_1 = __importStar(require("./OnyxCache"));
|
|
|
42
42
|
const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
|
|
43
43
|
const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
|
|
44
44
|
const GlobalSettings = __importStar(require("./GlobalSettings"));
|
|
45
|
-
const useLiveRef_1 = __importDefault(require("./useLiveRef"));
|
|
46
45
|
const usePrevious_1 = __importDefault(require("./usePrevious"));
|
|
47
46
|
const metrics_1 = __importDefault(require("./metrics"));
|
|
48
47
|
const Logger = __importStar(require("./Logger"));
|
|
49
48
|
function useOnyx(key, options, dependencies = []) {
|
|
50
49
|
const connectionRef = (0, react_1.useRef)(null);
|
|
51
50
|
const previousKey = (0, usePrevious_1.default)(key);
|
|
52
|
-
//
|
|
53
|
-
const
|
|
51
|
+
// Create memoized version of selector for performance
|
|
52
|
+
const memoizedSelector = (0, react_1.useMemo)(() => {
|
|
53
|
+
if (!(options === null || options === void 0 ? void 0 : options.selector))
|
|
54
|
+
return null;
|
|
55
|
+
let lastInput;
|
|
56
|
+
let lastOutput;
|
|
57
|
+
let hasComputed = false;
|
|
58
|
+
return (input) => {
|
|
59
|
+
// Always recompute when input changes
|
|
60
|
+
if (!hasComputed || lastInput !== input) {
|
|
61
|
+
const newOutput = options.selector(input);
|
|
62
|
+
// Deep equality mode: only update if output actually changed
|
|
63
|
+
if (!hasComputed || !(0, fast_equals_1.deepEqual)(lastOutput, newOutput)) {
|
|
64
|
+
lastInput = input;
|
|
65
|
+
lastOutput = newOutput;
|
|
66
|
+
hasComputed = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return lastOutput;
|
|
70
|
+
};
|
|
71
|
+
}, [options === null || options === void 0 ? void 0 : options.selector]);
|
|
54
72
|
// Stores the previous cached value as it's necessary to compare with the new value in `getSnapshot()`.
|
|
55
73
|
// We initialize it to `null` to simulate that we don't have any value from cache yet.
|
|
56
74
|
const previousValueRef = (0, react_1.useRef)(null);
|
|
@@ -120,7 +138,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
120
138
|
}
|
|
121
139
|
}, [key, options === null || options === void 0 ? void 0 : options.canEvict]);
|
|
122
140
|
const getSnapshot = (0, react_1.useCallback)(() => {
|
|
123
|
-
var _a, _b, _c;
|
|
141
|
+
var _a, _b, _c, _d;
|
|
124
142
|
let isOnyxValueDefined = true;
|
|
125
143
|
// We return the initial result right away during the first connection if `initWithStoredValues` is set to `false`.
|
|
126
144
|
if (isFirstConnectionRef.current && (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false) {
|
|
@@ -132,7 +150,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
132
150
|
if (isFirstConnectionRef.current || shouldGetCachedValueRef.current) {
|
|
133
151
|
// Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility.
|
|
134
152
|
const value = OnyxUtils_1.default.tryGetCachedValue(key);
|
|
135
|
-
const selectedValue =
|
|
153
|
+
const selectedValue = memoizedSelector ? memoizedSelector(value) : value;
|
|
136
154
|
newValueRef.current = (selectedValue !== null && selectedValue !== void 0 ? selectedValue : undefined);
|
|
137
155
|
// This flag is `false` when the original Onyx value (without selector) is not defined yet.
|
|
138
156
|
// It will be used later to check if we need to log an alert that the value is missing.
|
|
@@ -151,15 +169,18 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
151
169
|
newValueRef.current = undefined;
|
|
152
170
|
newFetchStatus = 'loading';
|
|
153
171
|
}
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
172
|
+
// Optimized equality checking - eliminated redundant deep equality:
|
|
173
|
+
// - Memoized selectors already handle deep equality internally, so we can use fast reference equality
|
|
174
|
+
// - Non-selector cases use shallow equality for object reference checks
|
|
175
|
+
// - Normalize null to undefined to ensure consistent comparison (both represent "no value")
|
|
157
176
|
let areValuesEqual;
|
|
158
|
-
if (
|
|
159
|
-
|
|
177
|
+
if (memoizedSelector) {
|
|
178
|
+
const normalizedPrevious = (_a = previousValueRef.current) !== null && _a !== void 0 ? _a : undefined;
|
|
179
|
+
const normalizedNew = (_b = newValueRef.current) !== null && _b !== void 0 ? _b : undefined;
|
|
180
|
+
areValuesEqual = normalizedPrevious === normalizedNew;
|
|
160
181
|
}
|
|
161
182
|
else {
|
|
162
|
-
areValuesEqual = (0, fast_equals_1.shallowEqual)((
|
|
183
|
+
areValuesEqual = (0, fast_equals_1.shallowEqual)((_c = previousValueRef.current) !== null && _c !== void 0 ? _c : undefined, newValueRef.current);
|
|
163
184
|
}
|
|
164
185
|
// We update the cached value and the result in the following conditions:
|
|
165
186
|
// We will update the cached value and the result in any of the following situations:
|
|
@@ -173,7 +194,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
173
194
|
// If the new value is `null` we default it to `undefined` to ensure the consumer gets a consistent result from the hook.
|
|
174
195
|
const newStatus = newFetchStatus !== null && newFetchStatus !== void 0 ? newFetchStatus : 'loaded';
|
|
175
196
|
resultRef.current = [
|
|
176
|
-
(
|
|
197
|
+
(_d = previousValueRef.current) !== null && _d !== void 0 ? _d : undefined,
|
|
177
198
|
{
|
|
178
199
|
status: newStatus,
|
|
179
200
|
sourceValue: sourceValueRef.current,
|
|
@@ -187,7 +208,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
187
208
|
}
|
|
188
209
|
}
|
|
189
210
|
return resultRef.current;
|
|
190
|
-
}, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key,
|
|
211
|
+
}, [options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.canBeMissing, key, memoizedSelector]);
|
|
191
212
|
const subscribe = (0, react_1.useCallback)((onStoreChange) => {
|
|
192
213
|
isConnectingRef.current = true;
|
|
193
214
|
onStoreChangeFnRef.current = onStoreChange;
|