Skip to content

Commit 1fd6859

Browse files
authored
Merge pull request #633 from callstack-internal/feature/reassure-phase-2
Reassure Phase 2
2 parents 2f04430 + df7fede commit 1fd6859

12 files changed

Lines changed: 6269 additions & 9517 deletions

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ['module:metro-react-native-babel-preset'],
2+
presets: ['module:@react-native/babel-preset'],
33
};

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = {
1010
__DEV__: true,
1111
WebSocket: {},
1212
},
13-
timers: 'fake',
1413
testEnvironment: 'jsdom',
15-
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect', './jestSetup.js'],
16-
testTimeout: 10000,
14+
setupFilesAfterEnv: ['./jestSetup.js'],
15+
testTimeout: 60000,
16+
transformIgnorePatterns: ['node_modules/(?!((@)?react-native|@ngneat/falso|uuid)/)'],
1717
};

lib/useOnyx.ts

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {Connection} from './OnyxConnectionManager';
66
import connectionManager from './OnyxConnectionManager';
77
import OnyxUtils from './OnyxUtils';
88
import * as GlobalSettings from './GlobalSettings';
9-
import type {CollectionKeyBase, KeyValueMapping, OnyxCollection, OnyxKey, OnyxValue} from './types';
9+
import type {CollectionKeyBase, OnyxKey, OnyxValue} from './types';
1010
import useLiveRef from './useLiveRef';
1111
import usePrevious from './usePrevious';
1212
import decorateWithMetrics from './metrics';
@@ -79,35 +79,6 @@ type ResultMetadata<TValue> = {
7979

8080
type UseOnyxResult<TValue> = [NonNullable<TValue> | undefined, ResultMetadata<TValue>];
8181

82-
/**
83-
* Gets the cached value from the Onyx cache. If the key is a collection key, it will return all the values in the collection.
84-
* It is a fork of `tryGetCachedValue` from `OnyxUtils` caused by different selector logic in `useOnyx`. It should be unified in the future, when `withOnyx` is removed.
85-
*/
86-
function tryGetCachedValue<TKey extends OnyxKey>(key: TKey): OnyxValue<OnyxKey> {
87-
if (!OnyxUtils.isCollectionKey(key)) {
88-
return OnyxCache.get(key);
89-
}
90-
91-
const allCacheKeys = OnyxCache.getAllKeys();
92-
93-
// It is possible we haven't loaded all keys yet so we do not know if the
94-
// collection actually exists.
95-
if (allCacheKeys.size === 0) {
96-
return;
97-
}
98-
99-
const values: OnyxCollection<KeyValueMapping[TKey]> = {};
100-
allCacheKeys.forEach((cacheKey) => {
101-
if (!cacheKey.startsWith(key)) {
102-
return;
103-
}
104-
105-
values[cacheKey] = OnyxCache.get(cacheKey);
106-
});
107-
108-
return values;
109-
}
110-
11182
function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
11283
key: TKey,
11384
options?: BaseUseOnyxOptions & UseOnyxInitialValueOption<TReturnValue> & Required<UseOnyxSelectorOption<TKey, TReturnValue>>,
@@ -233,7 +204,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
233204
// update `newValueRef` when `Onyx.connect()` callback is fired.
234205
if (isFirstConnectionRef.current || shouldGetCachedValueRef.current) {
235206
// Gets the value from cache and maps it with selector. It changes `null` to `undefined` for `useOnyx` compatibility.
236-
const value = tryGetCachedValue(key) as OnyxValue<TKey>;
207+
const value = OnyxUtils.tryGetCachedValue(key) as OnyxValue<TKey>;
237208
const selectedValue = selectorRef.current ? selectorRef.current(value) : value;
238209
newValueRef.current = (selectedValue ?? undefined) as TReturnValue | undefined;
239210

0 commit comments

Comments
 (0)