Skip to content

Commit 08f927a

Browse files
Review review
1 parent c28a9f5 commit 08f927a

File tree

2 files changed

+17
-47
lines changed

2 files changed

+17
-47
lines changed

packages/firestore/src/local/local_store.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,10 +1054,9 @@ export function lookupMutationDocuments(
10541054
localStore: LocalStore,
10551055
batchId: BatchId
10561056
): Promise<MaybeDocumentMap | null> {
1057-
const [localStoreImpl, mutationQueueImpl] = debugCast(
1058-
localStore,
1059-
LocalStoreImpl,
1060-
(localStore as LocalStoreImpl).mutationQueue,
1057+
const localStoreImpl = debugCast(localStore, LocalStoreImpl);
1058+
const mutationQueueImpl = debugCast(
1059+
localStoreImpl.mutationQueue,
10611060
IndexedDbMutationQueue // We only support IndexedDb in multi-tab mode.
10621061
);
10631062
return localStoreImpl.persistence.runTransaction(
@@ -1106,10 +1105,9 @@ export function getCachedTarget(
11061105
localStore: LocalStore,
11071106
targetId: TargetId
11081107
): Promise<Target | null> {
1109-
const [localStoreImpl, targetCacheImpl] = debugCast(
1110-
localStore,
1111-
LocalStoreImpl,
1112-
(localStore as LocalStoreImpl).targetCache,
1108+
const localStoreImpl = debugCast(localStore, LocalStoreImpl);
1109+
const targetCacheImpl = debugCast(
1110+
localStoreImpl.targetCache,
11131111
IndexedDbTargetCache // We only support IndexedDb in multi-tab mode.
11141112
);
11151113
const cachedTargetData = localStoreImpl.targetDataByTarget.get(targetId);
@@ -1138,10 +1136,9 @@ export function getCachedTarget(
11381136
export function getNewDocumentChanges(
11391137
localStore: LocalStore
11401138
): Promise<MaybeDocumentMap> {
1141-
const [localStoreImpl, remoteDocumentCacheImpl] = debugCast(
1142-
localStore,
1143-
LocalStoreImpl,
1144-
(localStore as LocalStoreImpl).remoteDocuments,
1139+
const localStoreImpl = debugCast(localStore, LocalStoreImpl);
1140+
const remoteDocumentCacheImpl = debugCast(
1141+
localStoreImpl.remoteDocuments,
11451142
IndexedDbRemoteDocumentCache // We only support IndexedDb in multi-tab mode.
11461143
);
11471144
return localStoreImpl.persistence

packages/firestore/src/util/assert.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,44 +72,17 @@ export function debugAssert(
7272
}
7373

7474
/**
75-
* Casts `obj1` to `S` and `obj2` to `T`. In non-production builds,
76-
* verifies that `obj1` and `obj2` are instances of `S` and `T` before casting.
75+
* Casts `obj` to `T`. In non-production builds, verifies that `obj` is an
76+
* instance of `T` before casting.
7777
*/
78-
export function debugCast<S, T>(
79-
obj1: object,
80-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
81-
constructor1: { new (...args: any[]): S },
82-
obj2: object,
83-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84-
constructor2: { new (...args: any[]): T }
85-
): [S, T] | never;
86-
/**
87-
* Casts `obj` to `S`. In non-production builds, verifies that `obj` is an
88-
* instance of `S` before casting.
89-
*/
90-
export function debugCast<S>(
78+
export function debugCast<T>(
9179
obj: object,
9280
// eslint-disable-next-line @typescript-eslint/no-explicit-any
93-
constructor: { new (...args: any[]): S }
94-
): S | never;
95-
export function debugCast<S, T>(
96-
obj1: object,
97-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
98-
constructor1: { new (...args: any[]): S },
99-
obj2?: object,
100-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101-
constructor2?: { new (...args: any[]): T }
102-
): S | [S, T] | never {
103-
debugAssert(
104-
obj1 instanceof constructor1,
105-
`Expected type '${constructor1.name}', but was '${obj1.constructor.name}'`
106-
);
107-
if (!obj2 || !constructor2) {
108-
return obj1 as S;
109-
}
81+
constructor: { new (...args: any[]): T }
82+
): T | never {
11083
debugAssert(
111-
obj2 instanceof constructor2,
112-
`Expected type '${constructor2.name}', but was '${obj2.constructor.name}'`
84+
obj instanceof constructor,
85+
`Expected type '${constructor.name}', but was '${obj.constructor.name}'`
11386
);
114-
return [obj1 as S, obj2 as T];
87+
return obj as T;
11588
}

0 commit comments

Comments
 (0)