Skip to content

Commit bab25ae

Browse files
committed
fix lint and ts checks
1 parent 77128e2 commit bab25ae

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

lib/OnyxSnapshotCache.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class OnyxSnapshotCache {
1010
/**
1111
* Snapshot cache for ultimate performance - separate cache per Onyx key
1212
*/
13-
private snapshotCache: Map<string, Map<string, any>>;
13+
private snapshotCache: Map<string, Map<string, unknown>>;
1414

1515
/**
1616
* Maps selector functions to unique IDs for cache key generation
1717
*/
18-
private selectorIdMap: Map<UseOnyxSelector<any, any>, string>;
18+
private selectorIdMap: Map<UseOnyxSelector<OnyxKey, unknown>, string>;
1919

2020
/**
2121
* Counter for generating incremental selector IDs
@@ -31,12 +31,13 @@ class OnyxSnapshotCache {
3131
/**
3232
* Generate unique ID for selector functions using incrementing numbers
3333
*/
34-
getSelectorId(selector: UseOnyxSelector<any, any>): string {
35-
if (!this.selectorIdMap.has(selector)) {
34+
getSelectorId<TKey extends OnyxKey, TReturnValue>(selector: UseOnyxSelector<TKey, TReturnValue>): string {
35+
const typedSelector = selector as unknown as UseOnyxSelector<OnyxKey, unknown>;
36+
if (!this.selectorIdMap.has(typedSelector)) {
3637
const id = `selector_${this.selectorIdCounter++}`;
37-
this.selectorIdMap.set(selector, id);
38+
this.selectorIdMap.set(typedSelector, id);
3839
}
39-
return this.selectorIdMap.get(selector)!;
40+
return this.selectorIdMap.get(typedSelector)!;
4041
}
4142

4243
/**
@@ -54,15 +55,15 @@ class OnyxSnapshotCache {
5455
/**
5556
* Get cached snapshot result for a key and cache key combination
5657
*/
57-
getCachedResult(key: string, cacheKey: string): any {
58+
getCachedResult<T>(key: string, cacheKey: string): T | undefined {
5859
const keyCache = this.snapshotCache.get(key);
59-
return keyCache?.get(cacheKey);
60+
return keyCache?.get(cacheKey) as T | undefined;
6061
}
6162

6263
/**
6364
* Set cached snapshot result for a key and cache key combination
6465
*/
65-
setCachedResult(key: string, cacheKey: string, result: any): void {
66+
setCachedResult<T>(key: string, cacheKey: string, result: T): void {
6667
if (!this.snapshotCache.has(key)) {
6768
this.snapshotCache.set(key, new Map());
6869
}

lib/useOnyx.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
209209
// Don't use cache for first connection with initWithStoredValues: false
210210
// Also don't use cache during active data updates (when shouldGetCachedValueRef is true)
211211
if (!(isFirstConnectionRef.current && options?.initWithStoredValues === false) && !shouldGetCachedValueRef.current) {
212-
const cachedResult = onyxSnapshotCache.getCachedResult(keyStr, cacheKey);
212+
const cachedResult = onyxSnapshotCache.getCachedResult<UseOnyxResult<TReturnValue>>(keyStr, cacheKey);
213213
if (cachedResult !== undefined) {
214214
resultRef.current = cachedResult;
215215
return cachedResult;
@@ -222,7 +222,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
222222
if (isFirstConnectionRef.current && options?.initWithStoredValues === false) {
223223
const result = resultRef.current;
224224
// Store result in snapshot cache
225-
onyxSnapshotCache.setCachedResult(keyStr, cacheKey, result);
225+
onyxSnapshotCache.setCachedResult<UseOnyxResult<TReturnValue>>(keyStr, cacheKey, result);
226226
return result;
227227
}
228228

@@ -298,7 +298,7 @@ function useOnyx<TKey extends OnyxKey, TReturnValue = OnyxValue<TKey>>(
298298
}
299299
}
300300

301-
onyxSnapshotCache.setCachedResult(keyStr, cacheKey, resultRef.current);
301+
onyxSnapshotCache.setCachedResult<UseOnyxResult<TReturnValue>>(keyStr, cacheKey, resultRef.current);
302302

303303
return resultRef.current;
304304
}, [options?.initWithStoredValues, options?.allowStaleData, options?.canBeMissing, key, memoizedSelector]);

0 commit comments

Comments
 (0)