react-native-firebase-compiled
Version:
A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto
65 lines (54 loc) • 1.42 kB
JavaScript
/**
*
* WriteBatch representation wrapper
*/
import { parseUpdateArgs } from './utils';
import { buildNativeMap } from './utils/serialize';
import { getNativeModule } from '../../utils/native';
/**
* @class WriteBatch
*/
export default class WriteBatch {
constructor(firestore) {
this._firestore = firestore;
this._writes = [];
}
commit() {
return getNativeModule(this._firestore).documentBatch(this._writes);
}
delete(docRef) {
// TODO: Validation
// validate.isDocumentReference('docRef', docRef);
// validate.isOptionalPrecondition('deleteOptions', deleteOptions);
this._writes.push({
path: docRef.path,
type: 'DELETE'
});
return this;
}
set(docRef, data, options) {
// TODO: Validation
// validate.isDocumentReference('docRef', docRef);
// validate.isDocument('data', data);
// validate.isOptionalPrecondition('options', writeOptions);
const nativeData = buildNativeMap(data);
this._writes.push({
data: nativeData,
options,
path: docRef.path,
type: 'SET'
});
return this;
}
update(docRef, ...args) {
// TODO: Validation
// validate.isDocumentReference('docRef', docRef);
const data = parseUpdateArgs(args, 'WriteBatch.update');
this._writes.push({
data: buildNativeMap(data),
path: docRef.path,
type: 'UPDATE'
});
return this;
}
}