Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UserDataReader tree-shakeable #3333

Merged
merged 9 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions packages/firestore/exp/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ import * as firestore from '../../index';
import { Firestore } from './database';
import {
DocumentKeyReference,
ParsedUpdateData
ParsedUpdateData,
parseSetData,
parseUpdateData,
parseUpdateVarargs
} from '../../../src/api/user_data_reader';
import { debugAssert } from '../../../src/util/assert';
import { cast } from '../../../lite/src/api/util';
import { DocumentSnapshot, QuerySnapshot } from './snapshot';
import {
addDocSnapshotListener,
addSnapshotsInSyncListener,
addQuerySnapshotListener,
addSnapshotsInSyncListener,
applyFirestoreDataConverter,
getDocsViaSnapshotListener,
getDocViaSnapshotListener,
Expand Down Expand Up @@ -175,7 +178,8 @@ export function setDoc<T>(
options
);
const dataReader = newUserDataReader(firestore);
const parsed = dataReader.parseSetData(
const parsed = parseSetData(
dataReader,
'setDoc',
ref._key,
convertedValue,
Expand Down Expand Up @@ -215,15 +219,17 @@ export function updateDoc(
typeof fieldOrUpdateData === 'string' ||
fieldOrUpdateData instanceof FieldPath
) {
parsed = dataReader.parseUpdateVarargs(
parsed = parseUpdateVarargs(
dataReader,
'updateDoc',
ref._key,
fieldOrUpdateData,
value,
moreFieldsAndValues
);
} else {
parsed = dataReader.parseUpdateData(
parsed = parseUpdateData(
dataReader,
'updateDoc',
ref._key,
fieldOrUpdateData
Expand Down Expand Up @@ -262,11 +268,13 @@ export function addDoc<T>(
const convertedValue = applyFirestoreDataConverter(collRef._converter, data);

const dataReader = newUserDataReader(collRef.firestore);
const parsed = dataReader.parseSetData(
const parsed = parseSetData(
dataReader,
'addDoc',
docRef._key,
convertedValue,
collRef._converter !== null
collRef._converter !== null,
{}
);

return firestore
Expand Down
19 changes: 13 additions & 6 deletions packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { Firestore } from './database';
import {
DocumentKeyReference,
ParsedUpdateData,
parseSetData,
parseUpdateData,
parseUpdateVarargs,
UserDataReader
} from '../../../src/api/user_data_reader';
import {
Expand All @@ -35,9 +38,9 @@ import { ResourcePath } from '../../../src/model/path';
import { AutoId } from '../../../src/util/misc';
import {
DocumentSnapshot,
fieldPathFromArgument,
QueryDocumentSnapshot,
QuerySnapshot,
fieldPathFromArgument
QuerySnapshot
} from './snapshot';
import {
invokeBatchGetDocumentsRpc,
Expand Down Expand Up @@ -464,7 +467,8 @@ export function setDoc<T>(
options
);
const dataReader = newUserDataReader(ref.firestore);
const parsed = dataReader.parseSetData(
const parsed = parseSetData(
dataReader,
'setDoc',
ref._key,
convertedValue,
Expand Down Expand Up @@ -506,15 +510,17 @@ export function updateDoc(
typeof fieldOrUpdateData === 'string' ||
fieldOrUpdateData instanceof FieldPath
) {
parsed = dataReader.parseUpdateVarargs(
parsed = parseUpdateVarargs(
dataReader,
'updateDoc',
ref._key,
fieldOrUpdateData,
value,
moreFieldsAndValues
);
} else {
parsed = dataReader.parseUpdateData(
parsed = parseUpdateData(
dataReader,
'updateDoc',
ref._key,
fieldOrUpdateData
Expand Down Expand Up @@ -554,7 +560,8 @@ export function addDoc<T>(
const convertedValue = applyFirestoreDataConverter(collRef._converter, data);

const dataReader = newUserDataReader(collRef.firestore);
const parsed = dataReader.parseSetData(
const parsed = parseSetData(
dataReader,
'addDoc',
docRef._key,
convertedValue,
Expand Down
16 changes: 12 additions & 4 deletions packages/firestore/lite/src/api/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

import * as firestore from '../../';

import { UserDataReader } from '../../../src/api/user_data_reader';
import {
parseSetData,
parseUpdateData,
parseUpdateVarargs,
UserDataReader
} from '../../../src/api/user_data_reader';
import { Transaction as InternalTransaction } from '../../../src/core/transaction';
import {
Document,
Expand Down Expand Up @@ -100,7 +105,8 @@ export class Transaction implements firestore.Transaction {
value,
options
);
const parsed = this._dataReader.parseSetData(
const parsed = parseSetData(
this._dataReader,
'Transaction.set',
ref._key,
convertedValue,
Expand Down Expand Up @@ -134,15 +140,17 @@ export class Transaction implements firestore.Transaction {
typeof fieldOrUpdateData === 'string' ||
fieldOrUpdateData instanceof FieldPath
) {
parsed = this._dataReader.parseUpdateVarargs(
parsed = parseUpdateVarargs(
this._dataReader,
'Transaction.update',
ref._key,
fieldOrUpdateData,
value,
moreFieldsAndValues
);
} else {
parsed = this._dataReader.parseUpdateData(
parsed = parseUpdateData(
this._dataReader,
'Transaction.update',
ref._key,
fieldOrUpdateData
Expand Down
12 changes: 9 additions & 3 deletions packages/firestore/lite/src/api/write_batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { Code, FirestoreError } from '../../../src/util/error';
import { applyFirestoreDataConverter } from '../../../src/api/database';
import {
DocumentKeyReference,
parseSetData,
parseUpdateData,
parseUpdateVarargs,
UserDataReader
} from '../../../src/api/user_data_reader';
import { cast } from './util';
Expand Down Expand Up @@ -67,7 +70,8 @@ export class WriteBatch implements firestore.WriteBatch {
value,
options
);
const parsed = this._dataReader.parseSetData(
const parsed = parseSetData(
this._dataReader,
'WriteBatch.set',
ref._key,
convertedValue,
Expand Down Expand Up @@ -105,15 +109,17 @@ export class WriteBatch implements firestore.WriteBatch {
typeof fieldOrUpdateData === 'string' ||
fieldOrUpdateData instanceof FieldPath
) {
parsed = this._dataReader.parseUpdateVarargs(
parsed = parseUpdateVarargs(
this._dataReader,
'WriteBatch.update',
ref._key,
fieldOrUpdateData,
value,
moreFieldsAndValues
);
} else {
parsed = this._dataReader.parseUpdateData(
parsed = parseUpdateData(
this._dataReader,
'WriteBatch.update',
ref._key,
fieldOrUpdateData
Expand Down
Loading