Skip to content

Commit 8e1a33d

Browse files
committed
Minor fixes
1 parent fa95648 commit 8e1a33d

5 files changed

Lines changed: 9 additions & 53 deletions

File tree

API-INTERNAL.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,6 @@ If the requested key is a collection, it will return an object with all the coll
114114
<dt><a href="#getCollectionDataAndSendAsObject">getCollectionDataAndSendAsObject()</a></dt>
115115
<dd><p>Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.</p>
116116
</dd>
117-
<dt><a href="#prepareSubscriberUpdate">prepareSubscriberUpdate(callback)</a></dt>
118-
<dd><p>Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.</p>
119-
</dd>
120-
<dt><a href="#scheduleSubscriberUpdate">scheduleSubscriberUpdate()</a></dt>
121-
<dd><p>Schedules an update that will be appended to the macro task queue (so it doesn&#39;t update the subscribers immediately).</p>
122-
</dd>
123-
<dt><a href="#scheduleNotifyCollectionSubscribers">scheduleNotifyCollectionSubscribers()</a></dt>
124-
<dd><p>This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
125-
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
126-
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.</p>
127-
</dd>
128117
<dt><a href="#remove">remove()</a></dt>
129118
<dd><p>Remove a key from Onyx and update the subscribers</p>
130119
</dd>
@@ -463,35 +452,6 @@ Sends the data obtained from the keys to the connection.
463452
## getCollectionDataAndSendAsObject()
464453
Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.
465454

466-
**Kind**: global function
467-
<a name="prepareSubscriberUpdate"></a>
468-
469-
## prepareSubscriberUpdate(callback)
470-
Delays promise resolution until the next macrotask to prevent race condition if the key subscription is in progress.
471-
472-
**Kind**: global function
473-
474-
| Param | Description |
475-
| --- | --- |
476-
| callback | The keyChanged/keysChanged callback |
477-
478-
<a name="scheduleSubscriberUpdate"></a>
479-
480-
## scheduleSubscriberUpdate()
481-
Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).
482-
483-
**Kind**: global function
484-
**Example**
485-
```js
486-
scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
487-
```
488-
<a name="scheduleNotifyCollectionSubscribers"></a>
489-
490-
## scheduleNotifyCollectionSubscribers()
491-
This method is similar to scheduleSubscriberUpdate but it is built for working specifically with collections
492-
so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the
493-
subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
494-
495455
**Kind**: global function
496456
<a name="remove"></a>
497457

lib/OnyxConnectionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class OnyxConnectionManager {
247247
* Disconnect all subscribers from Onyx.
248248
*/
249249
disconnectAll(): void {
250-
for (const [, connectionMetadata] of this.connectionsMap.entries()) {
250+
for (const connectionMetadata of this.connectionsMap.values()) {
251251
OnyxUtils.unsubscribeFromKey(connectionMetadata.subscriptionID);
252252
}
253253

lib/OnyxSnapshotCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OnyxSnapshotCache {
6060
* - `selector`: Different selectors produce different results, so each selector needs its own cache entry
6161
* - `initWithStoredValues`: This flag changes the initial loading behavior and affects the returned fetch status
6262
*
63-
* Other options like `reuseConnection` and `allowDynamicKey` don't affect the data transformation
63+
* Other options like `reuseConnection` don't affect the data transformation
6464
* or timing behavior of getSnapshot, so they're excluded from the cache key for better cache hit rates.
6565
*/
6666
registerConsumer<TKey extends OnyxKey, TReturnValue>(options: Pick<UseOnyxOptions<TKey, TReturnValue>, 'selector' | 'initWithStoredValues'>): string {

lib/OnyxUtils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,7 @@ function retryOperation<TMethod extends RetriableOnyxOperation>(error: Error, on
739739

740740
if (nextRetryAttempt > MAX_STORAGE_OPERATION_RETRY_ATTEMPTS) {
741741
Logger.logAlert(`Storage operation failed after ${MAX_STORAGE_OPERATION_RETRY_ATTEMPTS} retries. Error: ${error}. onyxMethod: ${onyxMethod.name}.`);
742-
reportStorageQuota();
743-
return Promise.resolve();
742+
return reportStorageQuota();
744743
}
745744

746745
// @ts-expect-error No overload matches this call.
@@ -872,7 +871,7 @@ function initializeWithDefaultKeyStates(): Promise<void> {
872871
// 2. All subsequent reads are synchronous cache hits
873872
return Storage.getAll()
874873
.then((pairs) => {
875-
const allDataFromStorage: Record<string, unknown> = {};
874+
const allDataFromStorage: Record<OnyxKey, OnyxValue<OnyxKey>> = {};
876875
for (const [key, value] of pairs) {
877876
// RAM-only keys should never be loaded from storage as they may have stale persisted data
878877
// from before the key was migrated to RAM-only.
@@ -902,7 +901,6 @@ function initializeWithDefaultKeyStates(): Promise<void> {
902901

903902
// Only notify subscribers for default key states — same as before.
904903
// Other keys will be picked up by subscribers when they connect.
905-
// FIXME: Maybe we dont need this, but some tests in E/App are failing if we remove it.
906904
for (const [key, value] of Object.entries(merged ?? {})) keyChanged(key, value);
907905
})
908906
.catch((error) => {
@@ -916,6 +914,7 @@ function initializeWithDefaultKeyStates(): Promise<void> {
916914
// Boot with defaults so the app renders instead of deadlocking.
917915
// Users will get a fresh-install experience but the app won't be bricked.
918916
cache.merge(defaultKeyStates);
917+
for (const [key, value] of Object.entries(defaultKeyStates)) keyChanged(key, value);
919918
});
920919
}
921920

tests/unit/useOnyxTest.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,16 @@ describe('useOnyx', () => {
107107
});
108108

109109
it('should return loaded state after an Onyx.clear() call while connecting and loading from cache', async () => {
110-
// Write directly to storage so the data is not in cache when Onyx.clear() is called
111-
// TODO: Check if this test still makes sense
112-
await StorageMock.setItem(ONYXKEYS.TEST_KEY, 'test');
110+
await Onyx.set(ONYXKEYS.TEST_KEY, 'test');
113111

114112
Onyx.clear();
115113

116114
const {result: result1} = renderHook(() => useOnyx(ONYXKEYS.TEST_KEY));
117115
const {result: result2} = renderHook(() => useOnyx(ONYXKEYS.TEST_KEY));
118116

119-
expect(result1.current[0]).toBeUndefined();
117+
expect(result1.current[0]).toEqual('test');
120118
expect(result1.current[1].status).toEqual('loaded');
121-
expect(result2.current[0]).toBeUndefined();
119+
expect(result2.current[0]).toEqual('test');
122120
expect(result2.current[1].status).toEqual('loaded');
123121

124122
Onyx.merge(ONYXKEYS.TEST_KEY, 'test2');
@@ -848,8 +846,7 @@ describe('useOnyx', () => {
848846
});
849847

850848
it('should always return undefined when subscribing to a skippable collection member id', async () => {
851-
// TODO: Check if this test still makes sense
852-
await StorageMock.setItem<string>(`${ONYXKEYS.COLLECTION.TEST_KEY}skippable-id`, 'skippable-id_value');
849+
await Onyx.set(`${ONYXKEYS.COLLECTION.TEST_KEY}skippable-id`, 'skippable-id_value');
853850

854851
const {result} = renderHook(() => useOnyx(`${ONYXKEYS.COLLECTION.TEST_KEY}skippable-id`));
855852

0 commit comments

Comments
 (0)