Skip to content

Commit 8c92c1a

Browse files
Tree-Shake OperationSource (#4470)
1 parent 9ac2093 commit 8c92c1a

File tree

3 files changed

+46
-44
lines changed

3 files changed

+46
-44
lines changed

packages/database/src/core/SyncTree.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import { ChildrenNode } from './snap/ChildrenNode';
2222
import { ImmutableTree } from './util/ImmutableTree';
2323
import { ListenComplete } from './operation/ListenComplete';
2424
import { Merge } from './operation/Merge';
25-
import { Operation, OperationSource } from './operation/Operation';
25+
import {
26+
newOperationSourceServer,
27+
newOperationSourceServerTaggedQuery,
28+
newOperationSourceUser,
29+
Operation
30+
} from './operation/Operation';
2631
import { Overwrite } from './operation/Overwrite';
2732
import { Path } from './util/Path';
2833
import { SyncPoint } from './SyncPoint';
@@ -118,7 +123,7 @@ export class SyncTree {
118123
return [];
119124
} else {
120125
return this.applyOperationToSyncPoints_(
121-
new Overwrite(OperationSource.user(), path, newData)
126+
new Overwrite(newOperationSourceUser(), path, newData)
122127
);
123128
}
124129
}
@@ -139,7 +144,7 @@ export class SyncTree {
139144
const changeTree = ImmutableTree.fromObject(changedChildren);
140145

141146
return this.applyOperationToSyncPoints_(
142-
new Merge(OperationSource.user(), path, changeTree)
147+
new Merge(newOperationSourceUser(), path, changeTree)
143148
);
144149
}
145150

@@ -177,7 +182,7 @@ export class SyncTree {
177182
*/
178183
applyServerOverwrite(path: Path, newData: Node): Event[] {
179184
return this.applyOperationToSyncPoints_(
180-
new Overwrite(OperationSource.server(), path, newData)
185+
new Overwrite(newOperationSourceServer(), path, newData)
181186
);
182187
}
183188

@@ -193,7 +198,7 @@ export class SyncTree {
193198
const changeTree = ImmutableTree.fromObject(changedChildren);
194199

195200
return this.applyOperationToSyncPoints_(
196-
new Merge(OperationSource.server(), path, changeTree)
201+
new Merge(newOperationSourceServer(), path, changeTree)
197202
);
198203
}
199204

@@ -204,7 +209,7 @@ export class SyncTree {
204209
*/
205210
applyListenComplete(path: Path): Event[] {
206211
return this.applyOperationToSyncPoints_(
207-
new ListenComplete(OperationSource.server(), path)
212+
new ListenComplete(newOperationSourceServer(), path)
208213
);
209214
}
210215

@@ -221,7 +226,7 @@ export class SyncTree {
221226
queryId = r.queryId;
222227
const relativePath = Path.relativePath(queryPath, path);
223228
const op = new Overwrite(
224-
OperationSource.forServerTaggedQuery(queryId),
229+
newOperationSourceServerTaggedQuery(queryId),
225230
relativePath,
226231
snap
227232
);
@@ -250,7 +255,7 @@ export class SyncTree {
250255
const relativePath = Path.relativePath(queryPath, path);
251256
const changeTree = ImmutableTree.fromObject(changedChildren);
252257
const op = new Merge(
253-
OperationSource.forServerTaggedQuery(queryId),
258+
newOperationSourceServerTaggedQuery(queryId),
254259
relativePath,
255260
changeTree
256261
);
@@ -274,7 +279,7 @@ export class SyncTree {
274279
queryId = r.queryId;
275280
const relativePath = Path.relativePath(queryPath, path);
276281
const op = new ListenComplete(
277-
OperationSource.forServerTaggedQuery(queryId),
282+
newOperationSourceServerTaggedQuery(queryId),
278283
relativePath
279284
);
280285
return this.applyTaggedOperation_(queryPath, op);

packages/database/src/core/operation/AckUserWrite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717

1818
import { assert } from '@firebase/util';
1919
import { Path } from '../util/Path';
20-
import { Operation, OperationSource, OperationType } from './Operation';
20+
import { newOperationSourceUser, Operation, OperationType } from './Operation';
2121
import { ImmutableTree } from '../util/ImmutableTree';
2222

2323
export class AckUserWrite implements Operation {
2424
/** @inheritDoc */
2525
type = OperationType.ACK_USER_WRITE;
2626

2727
/** @inheritDoc */
28-
source = OperationSource.user();
28+
source = newOperationSourceUser();
2929

3030
/**
3131
* @param affectedTree A tree containing true for each affected path. Affected paths can't overlap.

packages/database/src/core/operation/Operation.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { assert } from '@firebase/util';
1918
import { Path } from '../util/Path';
2019

2120
/**
@@ -42,40 +41,38 @@ export interface Operation {
4241
operationForChild(childName: string): Operation | null;
4342
}
4443

45-
export class OperationSource {
46-
constructor(
47-
public fromUser: boolean,
48-
public fromServer: boolean,
49-
public queryId: string | null,
50-
public tagged: boolean
51-
) {
52-
assert(!tagged || fromServer, 'Tagged queries must be from server.');
53-
}
44+
export interface OperationSource {
45+
fromUser: boolean;
46+
fromServer: boolean;
47+
queryId: string | null;
48+
tagged: boolean;
49+
}
5450

55-
static user() {
56-
return new OperationSource(
57-
/*fromUser=*/ true,
58-
false,
59-
null,
60-
/*tagged=*/ false
61-
);
62-
}
51+
export function newOperationSourceUser(): OperationSource {
52+
return {
53+
fromUser: true,
54+
fromServer: false,
55+
queryId: null,
56+
tagged: false
57+
};
58+
}
6359

64-
static server() {
65-
return new OperationSource(
66-
false,
67-
/*fromServer=*/ true,
68-
null,
69-
/*tagged=*/ false
70-
);
71-
}
60+
export function newOperationSourceServer(): OperationSource {
61+
return {
62+
fromUser: false,
63+
fromServer: true,
64+
queryId: null,
65+
tagged: false
66+
};
67+
}
7268

73-
static forServerTaggedQuery = function (queryId: string): OperationSource {
74-
return new OperationSource(
75-
false,
76-
/*fromServer=*/ true,
77-
queryId,
78-
/*tagged=*/ true
79-
);
69+
export function newOperationSourceServerTaggedQuery(
70+
queryId: string
71+
): OperationSource {
72+
return {
73+
fromUser: false,
74+
fromServer: true,
75+
queryId,
76+
tagged: true
8077
};
8178
}

0 commit comments

Comments
 (0)