My goal is to create a series of batch actions using functions that do not require a specific instance of WriteBatch. Currently, I am passing an instance of the WriteBatch class to the functions so they can utilize the .set(), .update(), or .delete() methods on the batch.
Consider my code snippet:
export class BatchHelperService {
constructor(private afStore: AngularFirestore) { }
executeBatchActions(batchActions: BaseBatchAction[]): Observable<void> {
const batch = this.afStore.firestore.batch();
batchActions.forEach(action => action.attachActionToBatch(batch));
return from(batch.commit());
}
}
In this code, I have a function that takes an array of a base class BaseBatchAction. There are three derived classes that represent different types of batch actions (set, update, delete), all implementing the attachActionToBatch() method requiring a pre-existing WriteBatch object.
I aim to eliminate this reliance as it goes against clean coding principles for monadic functions (avoiding the use of output arguments). Is there a way to achieve this with the SDK?