Skip to content

Commit 7d4e095

Browse files
Reduce size impact of Target/TargetImpl pattern (#3272)
1 parent e90304c commit 7d4e095

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

.changeset/tricky-rocks-dream.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/firestore/src/core/target.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,28 @@ import { debugCast } from '../util/assert';
3737
* maps to a single WatchTarget in RemoteStore and a single TargetData entry
3838
* in persistence.
3939
*/
40-
export class Target {
41-
protected constructor(
42-
readonly path: ResourcePath,
43-
readonly collectionGroup: string | null,
44-
readonly orderBy: OrderBy[],
45-
readonly filters: Filter[],
46-
readonly limit: number | null,
47-
readonly startAt: Bound | null,
48-
readonly endAt: Bound | null
49-
) {}
40+
export interface Target {
41+
readonly path: ResourcePath;
42+
readonly collectionGroup: string | null;
43+
readonly orderBy: OrderBy[];
44+
readonly filters: Filter[];
45+
readonly limit: number | null;
46+
readonly startAt: Bound | null;
47+
readonly endAt: Bound | null;
5048
}
5149

52-
class TargetImpl extends Target {
50+
// Visible for testing
51+
export class TargetImpl implements Target {
5352
memoizedCanonicalId: string | null = null;
5453
constructor(
55-
path: ResourcePath,
56-
collectionGroup: string | null = null,
57-
orderBy: OrderBy[] = [],
58-
filters: Filter[] = [],
59-
limit: number | null = null,
60-
startAt: Bound | null = null,
61-
endAt: Bound | null = null
62-
) {
63-
super(path, collectionGroup, orderBy, filters, limit, startAt, endAt);
64-
}
54+
readonly path: ResourcePath,
55+
readonly collectionGroup: string | null = null,
56+
readonly orderBy: OrderBy[] = [],
57+
readonly filters: Filter[] = [],
58+
readonly limit: number | null = null,
59+
readonly startAt: Bound | null = null,
60+
readonly endAt: Bound | null = null
61+
) {}
6562
}
6663

6764
/**

packages/firestore/test/unit/local/target_cache.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ import {
3434
import { Timestamp } from '../../../src/api/timestamp';
3535
import * as persistenceHelpers from './persistence_test_helpers';
3636
import { TestTargetCache } from './test_target_cache';
37-
import { canonifyTarget, Target, targetEquals } from '../../../src/core/target';
37+
import {
38+
canonifyTarget,
39+
Target,
40+
targetEquals,
41+
TargetImpl
42+
} from '../../../src/core/target';
3843

3944
describe('MemoryTargetCache', () => {
4045
genericTargetCacheTests(persistenceHelpers.testMemoryEagerPersistence);
@@ -106,7 +111,7 @@ describe('IndexedDbTargetCache', () => {
106111
function genericTargetCacheTests(
107112
persistencePromise: () => Promise<Persistence>
108113
): void {
109-
addEqualityMatcher({ equalsFn: targetEquals, forType: Target });
114+
addEqualityMatcher({ equalsFn: targetEquals, forType: TargetImpl });
110115
let cache: TestTargetCache;
111116

112117
const QUERY_ROOMS = Query.atPath(path('rooms')).toTarget();

packages/firestore/test/unit/specs/describe_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { SpecBuilder } from './spec_builder';
2626
import { SpecStep } from './spec_test_runner';
2727

2828
import * as stringify from 'json-stable-stringify';
29-
import { Target, targetEquals } from '../../../src/core/target';
29+
import { targetEquals, TargetImpl } from '../../../src/core/target';
3030

3131
// Disables all other tests; useful for debugging. Multiple tests can have
3232
// this tag and they'll all be run (but all others won't).
@@ -240,7 +240,7 @@ export function describeSpec(
240240

241241
if (!writeJSONFile) {
242242
describe(name, () => {
243-
addEqualityMatcher({ equalsFn: targetEquals, forType: Target });
243+
addEqualityMatcher({ equalsFn: targetEquals, forType: TargetImpl });
244244
return builder();
245245
});
246246
} else {

0 commit comments

Comments
 (0)