Skip to content

Commit 3361a63

Browse files
Feedback
1 parent 6a34bbb commit 3361a63

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

packages/firestore/lite/src/api/field_path.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import * as firestore from '../../index';
1919

20-
import { tryCast } from './util';
20+
import { cast } from './util';
2121
import {
2222
DOCUMENT_KEY_NAME,
2323
FieldPath as InternalFieldPath
@@ -54,21 +54,20 @@ export class FieldPath implements firestore.FieldPath {
5454
1
5555
);
5656

57-
for (let i = 0; i < fieldNames.length; ++i) {
58-
if (fieldNames[i].length === 0) {
59-
throw new FirestoreError(
60-
Code.INVALID_ARGUMENT,
61-
`Invalid field name at argument $(i + 1). ` +
62-
'Field names must not be empty.'
63-
);
64-
}
57+
const emptyElement = fieldNames.indexOf('');
58+
if (emptyElement !== -1) {
59+
throw new FirestoreError(
60+
Code.INVALID_ARGUMENT,
61+
`Invalid field name at argument $(i + 1). ` +
62+
'Field names must not be empty.'
63+
);
6564
}
6665

6766
this._internalPath = new InternalFieldPath(fieldNames);
6867
}
6968

7069
isEqual(other: firestore.FieldPath): boolean {
71-
const path = tryCast(other, FieldPath);
70+
const path = cast(other, FieldPath);
7271
return this._internalPath.isEqual(path._internalPath);
7372
}
7473
}

packages/firestore/lite/src/api/snapshot.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as firestore from '../../index';
2020
import { Firestore } from './database';
2121
import { DocumentReference } from './reference';
2222
import { FieldPath } from './field_path';
23-
import { tryCast } from './util';
23+
import { cast } from './util';
2424
import { DocumentKey } from '../../../src/model/document_key';
2525
import { Document } from '../../../src/model/document';
2626
import { UserDataWriter } from '../../../src/api/user_data_writer';
@@ -60,25 +60,23 @@ export class DocumentSnapshot<T = firestore.DocumentData>
6060
data(): T | undefined {
6161
if (!this._document) {
6262
return undefined;
63-
} else {
63+
} else if (this._converter) {
6464
// We only want to use the converter and create a new DocumentSnapshot
6565
// if a converter has been provided.
66-
if (this._converter) {
67-
const snapshot = new QueryDocumentSnapshot(
68-
this._firestore,
69-
this._key,
70-
this._document
71-
);
72-
return this._converter.fromFirestore(snapshot);
73-
} else {
74-
const userDataWriter = new UserDataWriter(
75-
this._firestore._databaseId,
76-
/* timestampsInSnapshots= */ false,
77-
/* serverTimestampBehavior=*/ 'none',
78-
key => new DocumentReference(this._firestore, key)
79-
);
80-
return userDataWriter.convertValue(this._document.toProto()) as T;
81-
}
66+
const snapshot = new QueryDocumentSnapshot(
67+
this._firestore,
68+
this._key,
69+
this._document
70+
);
71+
return this._converter.fromFirestore(snapshot);
72+
} else {
73+
const userDataWriter = new UserDataWriter(
74+
this._firestore._databaseId,
75+
/* timestampsInSnapshots= */ false,
76+
/* serverTimestampBehavior=*/ 'none',
77+
key => new DocumentReference(this._firestore, key)
78+
);
79+
return userDataWriter.convertValue(this._document.toProto()) as T;
8280
}
8381
}
8482

@@ -119,7 +117,7 @@ export function fieldPathFromArgument(
119117
if (typeof arg === 'string') {
120118
return fieldPathFromDotSeparatedString(methodName, arg);
121119
} else {
122-
const path = tryCast(arg, FieldPath);
120+
const path = cast(arg, FieldPath);
123121
return path._internalPath;
124122
}
125123
}

0 commit comments

Comments
 (0)