Skip to content

Apply functional-style naming pattern to mutation.ts #5285

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

Merged
merged 2 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions packages/firestore/src/local/local_documents_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from '../model/collections';
import { Document, MutableDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { applyMutationToLocalView, PatchMutation } from '../model/mutation';
import { mutationApplyToLocalView, PatchMutation } from '../model/mutation';
import { MutationBatch } from '../model/mutation_batch';
import { ResourcePath } from '../model/path';
import { debugAssert } from '../util/assert';
Expand Down Expand Up @@ -251,7 +251,7 @@ export class LocalDocumentsView {
document = MutableDocument.newInvalidDocument(key);
results = results.insert(key, document);
}
applyMutationToLocalView(
mutationApplyToLocalView(
mutation,
document,
batch.localWriteTime
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/local/local_store_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import { Document } from '../model/document';
import { DocumentKey } from '../model/document_key';
import {
extractMutationBaseValue,
mutationExtractBaseValue,
Mutation,
PatchMutation,
Precondition
Expand Down Expand Up @@ -318,7 +318,7 @@ export function localStoreWriteLocally(
const baseMutations: Mutation[] = [];

for (const mutation of mutations) {
const baseValue = extractMutationBaseValue(
const baseValue = mutationExtractBaseValue(
mutation,
existingDocs.get(mutation.key)!
);
Expand Down
40 changes: 20 additions & 20 deletions packages/firestore/src/model/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function preconditionIsValidForDocument(
*
* Every type of mutation needs to implement its own applyToRemoteDocument() and
* applyToLocalView() to implement the actual behavior of applying the mutation
* to some source document (see `applySetMutationToRemoteDocument()` for an
* to some source document (see `setMutationApplyToRemoteDocument()` for an
* example).
*/
export abstract class Mutation {
Expand All @@ -226,22 +226,22 @@ export abstract class Mutation {
* of the document.
* @param mutationResult - The result of applying the mutation from the backend.
*/
export function applyMutationToRemoteDocument(
export function mutationApplyToRemoteDocument(
mutation: Mutation,
document: MutableDocument,
mutationResult: MutationResult
): void {
verifyMutationKeyMatches(mutation, document);
mutationVerifyKeyMatches(mutation, document);
if (mutation instanceof SetMutation) {
applySetMutationToRemoteDocument(mutation, document, mutationResult);
setMutationApplyToRemoteDocument(mutation, document, mutationResult);
} else if (mutation instanceof PatchMutation) {
applyPatchMutationToRemoteDocument(mutation, document, mutationResult);
patchMutationApplyToRemoteDocument(mutation, document, mutationResult);
} else {
debugAssert(
mutation instanceof DeleteMutation,
'Unexpected mutation type: ' + mutation
);
applyDeleteMutationToRemoteDocument(mutation, document, mutationResult);
deleteMutationApplyToRemoteDocument(mutation, document, mutationResult);
}
}

Expand All @@ -257,23 +257,23 @@ export function applyMutationToRemoteDocument(
* @param localWriteTime - A timestamp indicating the local write time of the
* batch this mutation is a part of.
*/
export function applyMutationToLocalView(
export function mutationApplyToLocalView(
mutation: Mutation,
document: MutableDocument,
localWriteTime: Timestamp
): void {
verifyMutationKeyMatches(mutation, document);
mutationVerifyKeyMatches(mutation, document);

if (mutation instanceof SetMutation) {
applySetMutationToLocalView(mutation, document, localWriteTime);
setMutationApplyToLocalView(mutation, document, localWriteTime);
} else if (mutation instanceof PatchMutation) {
applyPatchMutationToLocalView(mutation, document, localWriteTime);
patchMutationApplyToLocalView(mutation, document, localWriteTime);
} else {
debugAssert(
mutation instanceof DeleteMutation,
'Unexpected mutation type: ' + mutation
);
applyDeleteMutationToLocalView(mutation, document);
deleteMutationApplyToLocalView(mutation, document);
}
}

Expand All @@ -293,7 +293,7 @@ export function applyMutationToLocalView(
* @returns a base value to store along with the mutation, or null for
* idempotent mutations.
*/
export function extractMutationBaseValue(
export function mutationExtractBaseValue(
mutation: Mutation,
document: Document
): ObjectValue | null {
Expand Down Expand Up @@ -348,7 +348,7 @@ export function mutationEquals(left: Mutation, right: Mutation): boolean {
return true;
}

function verifyMutationKeyMatches(
function mutationVerifyKeyMatches(
mutation: Mutation,
document: MutableDocument
): void {
Expand Down Expand Up @@ -385,12 +385,12 @@ export class SetMutation extends Mutation {
readonly type: MutationType = MutationType.Set;
}

function applySetMutationToRemoteDocument(
function setMutationApplyToRemoteDocument(
mutation: SetMutation,
document: MutableDocument,
mutationResult: MutationResult
): void {
// Unlike applySetMutationToLocalView, if we're applying a mutation to a
// Unlike setMutationApplyToLocalView, if we're applying a mutation to a
// remote document the server has accepted the mutation so the precondition
// must have held.
const newData = mutation.value.clone();
Expand All @@ -405,7 +405,7 @@ function applySetMutationToRemoteDocument(
.setHasCommittedMutations();
}

function applySetMutationToLocalView(
function setMutationApplyToLocalView(
mutation: SetMutation,
document: MutableDocument,
localWriteTime: Timestamp
Expand Down Expand Up @@ -455,7 +455,7 @@ export class PatchMutation extends Mutation {
readonly type: MutationType = MutationType.Patch;
}

function applyPatchMutationToRemoteDocument(
function patchMutationApplyToRemoteDocument(
mutation: PatchMutation,
document: MutableDocument,
mutationResult: MutationResult
Expand All @@ -482,7 +482,7 @@ function applyPatchMutationToRemoteDocument(
.setHasCommittedMutations();
}

function applyPatchMutationToLocalView(
function patchMutationApplyToLocalView(
mutation: PatchMutation,
document: MutableDocument,
localWriteTime: Timestamp
Expand Down Expand Up @@ -601,7 +601,7 @@ export class DeleteMutation extends Mutation {
readonly fieldTransforms: FieldTransform[] = [];
}

function applyDeleteMutationToRemoteDocument(
function deleteMutationApplyToRemoteDocument(
mutation: DeleteMutation,
document: MutableDocument,
mutationResult: MutationResult
Expand All @@ -619,7 +619,7 @@ function applyDeleteMutationToRemoteDocument(
.setHasCommittedMutations();
}

function applyDeleteMutationToLocalView(
function deleteMutationApplyToLocalView(
mutation: DeleteMutation,
document: MutableDocument
): void {
Expand Down
10 changes: 5 additions & 5 deletions packages/firestore/src/model/mutation_batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import {
} from './collections';
import { MutableDocument } from './document';
import {
applyMutationToLocalView,
applyMutationToRemoteDocument,
Mutation,
mutationApplyToLocalView,
mutationApplyToRemoteDocument,
mutationEquals,
MutationResult
} from './mutation';
Expand Down Expand Up @@ -85,7 +85,7 @@ export class MutationBatch {
const mutation = this.mutations[i];
if (mutation.key.isEqual(document.key)) {
const mutationResult = mutationResults[i];
applyMutationToRemoteDocument(mutation, document, mutationResult);
mutationApplyToRemoteDocument(mutation, document, mutationResult);
}
}
}
Expand All @@ -101,14 +101,14 @@ export class MutationBatch {
// transform against a consistent set of values.
for (const mutation of this.baseMutations) {
if (mutation.key.isEqual(document.key)) {
applyMutationToLocalView(mutation, document, this.localWriteTime);
mutationApplyToLocalView(mutation, document, this.localWriteTime);
}
}

// Second, apply all user-provided mutations.
for (const mutation of this.mutations) {
if (mutation.key.isEqual(document.key)) {
applyMutationToLocalView(mutation, document, this.localWriteTime);
mutationApplyToLocalView(mutation, document, this.localWriteTime);
}
}
}
Expand Down
Loading