react-native-onyx 3.0.89 → 3.0.91
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 +2 -2
- package/dist/OnyxConnectionManager.js +2 -3
- package/dist/OnyxUtils.js +2 -2
- package/dist/storage/providers/SQLiteProvider.js +11 -4
- package/dist/types.d.ts +3 -3
- package/dist/useOnyx.d.ts +2 -3
- package/dist/useOnyx.js +1 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -257,10 +257,10 @@ export default MyComponent;
|
|
|
257
257
|
This will add a prop to the component called `allReports` which is an object of collection member key/values. Changes to the individual member keys will modify the entire object and new props will be passed with each individual key update. The prop doesn't update on the initial rendering of the component until the entire collection has been read out of Onyx.
|
|
258
258
|
|
|
259
259
|
```js
|
|
260
|
-
Onyx.connect({key: ONYXKEYS.COLLECTION.REPORT}, callback: (allReports, collectionKey
|
|
260
|
+
Onyx.connect({key: ONYXKEYS.COLLECTION.REPORT}, callback: (allReports, collectionKey) => {...});
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
-
This will fire the callback once with the entire collection initially and later with an updated version of the collection when individual keys update.
|
|
263
|
+
This will fire the callback once with the entire collection initially and later with an updated version of the collection when individual keys update.
|
|
264
264
|
|
|
265
265
|
### Performance Considerations When Using Collections
|
|
266
266
|
|
|
@@ -83,7 +83,7 @@ class OnyxConnectionManager {
|
|
|
83
83
|
for (const callback of connection.callbacks.values()) {
|
|
84
84
|
try {
|
|
85
85
|
if (OnyxKeys_1.default.isCollectionKey(connection.onyxKey)) {
|
|
86
|
-
callback(connection.cachedCallbackValue, connection.cachedCallbackKey
|
|
86
|
+
callback(connection.cachedCallbackValue, connection.cachedCallbackKey);
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
callback(connection.cachedCallbackValue, connection.cachedCallbackKey);
|
|
@@ -107,7 +107,7 @@ class OnyxConnectionManager {
|
|
|
107
107
|
const callbackID = String(this.lastCallbackID++);
|
|
108
108
|
// If there is no connection yet for that connection ID, we create a new one.
|
|
109
109
|
if (!connectionMetadata) {
|
|
110
|
-
const callback = (value, key
|
|
110
|
+
const callback = (value, key) => {
|
|
111
111
|
const createdConnection = this.connectionsMap.get(connectionID);
|
|
112
112
|
if (createdConnection) {
|
|
113
113
|
// We signal that the first connection was made and now any new subscribers
|
|
@@ -115,7 +115,6 @@ class OnyxConnectionManager {
|
|
|
115
115
|
createdConnection.isConnectionMade = true;
|
|
116
116
|
createdConnection.cachedCallbackValue = value;
|
|
117
117
|
createdConnection.cachedCallbackKey = key;
|
|
118
|
-
createdConnection.sourceValue = sourceValue;
|
|
119
118
|
this.fireCallbacks(connectionID);
|
|
120
119
|
}
|
|
121
120
|
};
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -483,7 +483,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
483
483
|
}
|
|
484
484
|
try {
|
|
485
485
|
lastConnectionCallbackData.set(subscriber.subscriptionID, { value: cachedCollection, matchedKey: subscriber.key });
|
|
486
|
-
subscriber.callback(cachedCollection, subscriber.key
|
|
486
|
+
subscriber.callback(cachedCollection, subscriber.key);
|
|
487
487
|
}
|
|
488
488
|
catch (error) {
|
|
489
489
|
Logger.logAlert(`[OnyxUtils.keysChanged] Subscriber callback threw an error for key '${collectionKey}': ${error}`);
|
|
@@ -567,7 +567,7 @@ function keyChanged(key, value, canUpdateSubscriber = () => true, isProcessingCo
|
|
|
567
567
|
cachedCollections[subscriber.key] = cachedCollection;
|
|
568
568
|
}
|
|
569
569
|
lastConnectionCallbackData.set(subscriber.subscriptionID, { value: cachedCollection, matchedKey: subscriber.key });
|
|
570
|
-
subscriber.callback(cachedCollection, subscriber.key
|
|
570
|
+
subscriber.callback(cachedCollection, subscriber.key);
|
|
571
571
|
continue;
|
|
572
572
|
}
|
|
573
573
|
const subscriberCallback = subscriber.callback;
|
|
@@ -150,10 +150,17 @@ const provider = {
|
|
|
150
150
|
if (!provider.store) {
|
|
151
151
|
throw new Error('Store is not initialized!');
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
// Aggregate the whole table into a single JSON string in SQLite so we only run JSON.parse
|
|
154
|
+
// once, instead of returning every row and parsing each one individually in JavaScript.
|
|
155
|
+
return provider.store
|
|
156
|
+
.executeAsync('SELECT json_group_array(json_array(record_key, json(valueJSON))) AS aggregated FROM keyvaluepairs;')
|
|
157
|
+
.then(({ rows }) => {
|
|
158
|
+
var _a;
|
|
159
|
+
const aggregated = (_a = rows === null || rows === void 0 ? void 0 : rows.item(0)) === null || _a === void 0 ? void 0 : _a.aggregated;
|
|
160
|
+
if (aggregated == null) {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
return JSON.parse(aggregated);
|
|
157
164
|
});
|
|
158
165
|
},
|
|
159
166
|
removeItem(key) {
|
package/dist/types.d.ts
CHANGED
|
@@ -187,20 +187,20 @@ type BaseConnectOptions = {
|
|
|
187
187
|
/** Represents the callback function used in `Onyx.connect()` method with a regular key. */
|
|
188
188
|
type DefaultConnectCallback<TKey extends OnyxKey> = (value: OnyxEntry<KeyValueMapping[TKey]>, key: TKey) => void;
|
|
189
189
|
/** Represents the callback function used in `Onyx.connect()` method with a collection key. */
|
|
190
|
-
type CollectionConnectCallback<TKey extends OnyxKey> = (value: NonUndefined<OnyxCollection<KeyValueMapping[TKey]>>, key: TKey
|
|
190
|
+
type CollectionConnectCallback<TKey extends OnyxKey> = (value: NonUndefined<OnyxCollection<KeyValueMapping[TKey]>>, key: TKey) => void;
|
|
191
191
|
/**
|
|
192
192
|
* Represents the options used in `Onyx.connect()` method.
|
|
193
193
|
*
|
|
194
194
|
* For a collection root key (e.g. `ONYXKEYS.COLLECTION.REPORT`), the callback fires
|
|
195
195
|
* with the entire collection object whenever any member changes (signature
|
|
196
|
-
* `(collection, key
|
|
196
|
+
* `(collection, key)`). For any other key, the callback fires with the value at
|
|
197
197
|
* that key (signature `(value, key)`).
|
|
198
198
|
*/
|
|
199
199
|
type ConnectOptions<TKey extends OnyxKey> = BaseConnectOptions & {
|
|
200
200
|
/** The Onyx key to subscribe to. */
|
|
201
201
|
key: TKey;
|
|
202
202
|
/** A function that will be called when the Onyx data we are subscribed changes. */
|
|
203
|
-
callback?: (value: TKey extends CollectionKeyBase ? NonUndefined<OnyxCollection<KeyValueMapping[TKey]>> : OnyxEntry<KeyValueMapping[TKey]>, key: TKey
|
|
203
|
+
callback?: (value: TKey extends CollectionKeyBase ? NonUndefined<OnyxCollection<KeyValueMapping[TKey]>> : OnyxEntry<KeyValueMapping[TKey]>, key: TKey) => void;
|
|
204
204
|
};
|
|
205
205
|
type CallbackToStateMapping<TKey extends OnyxKey> = ConnectOptions<TKey> & {
|
|
206
206
|
subscriptionID: number;
|
package/dist/useOnyx.d.ts
CHANGED
|
@@ -17,11 +17,10 @@ type UseOnyxOptions<TKey extends OnyxKey, TReturnValue> = {
|
|
|
17
17
|
selector?: UseOnyxSelector<TKey, TReturnValue>;
|
|
18
18
|
};
|
|
19
19
|
type FetchStatus = 'loading' | 'loaded';
|
|
20
|
-
type ResultMetadata
|
|
20
|
+
type ResultMetadata = {
|
|
21
21
|
status: FetchStatus;
|
|
22
|
-
sourceValue?: NonNullable<TValue> | undefined;
|
|
23
22
|
};
|
|
24
|
-
type UseOnyxResult<TValue> = [NonNullable<TValue> | undefined, ResultMetadata
|
|
23
|
+
type UseOnyxResult<TValue> = [NonNullable<TValue> | undefined, ResultMetadata];
|
|
25
24
|
declare function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(key: TKey, options?: UseOnyxOptions<TKey, TReturnValue>, dependencies?: DependencyList): UseOnyxResult<TReturnValue>;
|
|
26
25
|
export default useOnyx;
|
|
27
26
|
export type { FetchStatus, ResultMetadata, UseOnyxResult, UseOnyxOptions, UseOnyxSelector };
|
package/dist/useOnyx.js
CHANGED
|
@@ -103,8 +103,6 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
103
103
|
const onStoreChangeFnRef = (0, react_1.useRef)(null);
|
|
104
104
|
// Indicates if we should get the newest cached value from Onyx during `getSnapshot()` execution.
|
|
105
105
|
const shouldGetCachedValueRef = (0, react_1.useRef)(true);
|
|
106
|
-
// Inside useOnyx.ts, we need to track the sourceValue separately
|
|
107
|
-
const sourceValueRef = (0, react_1.useRef)(undefined);
|
|
108
106
|
// Cache the options key to avoid regenerating it every getSnapshot call
|
|
109
107
|
const cacheKey = (0, react_1.useMemo)(() => OnyxSnapshotCache_1.default.registerConsumer(key, {
|
|
110
108
|
selector: options === null || options === void 0 ? void 0 : options.selector,
|
|
@@ -191,7 +189,6 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
191
189
|
(_c = previousValueRef.current) !== null && _c !== void 0 ? _c : undefined,
|
|
192
190
|
{
|
|
193
191
|
status: newFetchStatus,
|
|
194
|
-
sourceValue: sourceValueRef.current,
|
|
195
192
|
},
|
|
196
193
|
];
|
|
197
194
|
}
|
|
@@ -207,7 +204,6 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
207
204
|
if (hasMountedRef.current) {
|
|
208
205
|
previousValueRef.current = null;
|
|
209
206
|
newValueRef.current = null;
|
|
210
|
-
sourceValueRef.current = undefined;
|
|
211
207
|
resultRef.current = [undefined, { status: 'loading' }];
|
|
212
208
|
shouldGetCachedValueRef.current = true;
|
|
213
209
|
}
|
|
@@ -216,7 +212,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
216
212
|
onStoreChangeFnRef.current = onStoreChange;
|
|
217
213
|
connectionRef.current = OnyxConnectionManager_1.default.connect({
|
|
218
214
|
key,
|
|
219
|
-
callback: (
|
|
215
|
+
callback: () => {
|
|
220
216
|
isConnectingRef.current = false;
|
|
221
217
|
onStoreChangeFnRef.current = onStoreChange;
|
|
222
218
|
// Signals that the first connection was made for this key, so some logics
|
|
@@ -224,8 +220,6 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
224
220
|
connectedKeyRef.current = key;
|
|
225
221
|
// Signals that we want to get the newest cached value again in `getSnapshot()`.
|
|
226
222
|
shouldGetCachedValueRef.current = true;
|
|
227
|
-
// sourceValue is unknown type, so we need to cast it to the correct type.
|
|
228
|
-
sourceValueRef.current = sourceValue;
|
|
229
223
|
// Invalidate snapshot cache for this key when data changes
|
|
230
224
|
OnyxSnapshotCache_1.default.invalidateForKey(key);
|
|
231
225
|
// Finally, we signal that the store changed, making `getSnapshot()` be called again.
|