From 53b8a46ae3acbf3258c3c117afc1c91986655d96 Mon Sep 17 00:00:00 2001 From: HANAI tohru Date: Sat, 15 Aug 2020 21:30:51 +0900 Subject: [PATCH] Fix remove unnecessary Promises from tx write functions Since the original Firestore's tx write functions are synchronous. e.g. ```ts set(documentRef: DocumentReference, data: DocumentData, options?: SetOptions): Transaction; ``` --- src/transaction/index.ts | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/transaction/index.ts b/src/transaction/index.ts index da85f168..fdd33d8e 100644 --- a/src/transaction/index.ts +++ b/src/transaction/index.ts @@ -77,7 +77,7 @@ export interface TransactionWrite { * @param ref - the reference to the document to set * @param data - the document data */ - set(ref: Ref, data: SetModel): Promise + set(ref: Ref, data: SetModel): void /** * @param collection - the collection to set document in * @param id - the id of the document to set @@ -87,7 +87,7 @@ export interface TransactionWrite { collection: Collection, id: string, data: SetModel - ): Promise + ): void /** * Sets or updates a document with the given data. @@ -108,7 +108,7 @@ export interface TransactionWrite { * @param ref - the reference to the document to set or update * @param data - the document data */ - upset(ref: Ref, data: UpsetModel): Promise + upset(ref: Ref, data: UpsetModel): void /** * @param collection - the collection to set document in * @param id - the id of the document to set @@ -118,7 +118,7 @@ export interface TransactionWrite { collection: Collection, id: string, data: UpsetModel - ): Promise + ): void /** * Updates a document. @@ -154,12 +154,12 @@ export interface TransactionWrite { collection: Collection, id: string, data: Field[] - ): Promise + ): void /** * @param ref - the reference to the document to set * @param data - the document data to update */ - update(ref: Ref, data: Field[]): Promise + update(ref: Ref, data: Field[]): void /** * @param collection - the collection to update document in * @param id - the id of the document to update @@ -169,12 +169,12 @@ export interface TransactionWrite { collection: Collection, id: string, data: UpdateModel - ): Promise + ): void /** * @param ref - the reference to the document to set * @param data - the document data to update */ - update(ref: Ref, data: UpdateModel): Promise + update(ref: Ref, data: UpdateModel): void /** * Removes a document. @@ -203,11 +203,11 @@ export interface TransactionWrite { * @param collection - The collection to remove document in * @param id - The id of the documented to remove */ - remove(collection: Collection, id: string): Promise + remove(collection: Collection, id: string): void /** * @param ref - The reference to the document to remove */ - remove(ref: Ref): Promise + remove(ref: Ref): void } /** @@ -282,11 +282,11 @@ export async function transaction( return data ? doc(ref(collection, id), data) : null } - async function set( + function set( collectionOrRef: Collection | Ref, idOrData: string | SetModel, maybeData?: SetModel - ): Promise { + ): void { let collection: Collection let id: string let data: SetModel @@ -305,14 +305,14 @@ export async function transaction( const firestoreDoc = a.firestore.collection(collection.path).doc(id) // ^ above // TODO: Refactor code above and below because is all the same as in the regular set function - await t.set(firestoreDoc, unwrapData(a, data)) + t.set(firestoreDoc, unwrapData(a, data)) } - async function upset( + function upset( collectionOrRef: Collection | Ref, idOrData: string | SetModel, maybeData?: UpsetModel - ): Promise { + ): void { let collection: Collection let id: string let data: UpsetModel @@ -331,14 +331,14 @@ export async function transaction( const firestoreDoc = a.firestore.collection(collection.path).doc(id) // ^ above // TODO: Refactor code above and below because is all the same as in the regular set function - await t.set(firestoreDoc, unwrapData(a, data), { merge: true }) + t.set(firestoreDoc, unwrapData(a, data), { merge: true }) } - async function update( + function update( collectionOrRef: Collection | Ref, idOrData: string | Field[] | UpdateModel, maybeData?: Field[] | UpdateModel - ): Promise { + ): void { let collection: Collection let id: string let data: Model @@ -366,13 +366,13 @@ export async function transaction( : data // ^ above // TODO: Refactor code above because is all the same as in the regular update function - await t.update(firebaseDoc, unwrapData(a, updateData)) + t.update(firebaseDoc, unwrapData(a, updateData)) } - async function remove( + function remove( collectionOrRef: Collection | Ref, maybeId?: string - ): Promise { + ): void { let collection: Collection let id: string @@ -388,7 +388,7 @@ export async function transaction( const firebaseDoc = a.firestore.collection(collection.path).doc(id) // ^ above // TODO: Refactor code above because is all the same as in the regular update function - await t.delete(firebaseDoc) + t.delete(firebaseDoc) } return readFunction({ get }).then(data =>