mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
[firestore] Support FieldValue.delete() and FieldValue.serverTimestamp()
This commit is contained in:
17
lib/modules/firestore/FieldValue.js
Normal file
17
lib/modules/firestore/FieldValue.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @flow
|
||||
* FieldValue representation wrapper
|
||||
*/
|
||||
|
||||
export default class FieldValue {
|
||||
static delete(): FieldValue {
|
||||
return DELETE_FIELD_VALUE;
|
||||
}
|
||||
|
||||
static serverTimestamp(): FieldValue {
|
||||
return SERVER_TIMESTAMP_FIELD_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
export const DELETE_FIELD_VALUE = new FieldValue();
|
||||
export const SERVER_TIMESTAMP_FIELD_VALUE = new FieldValue();
|
||||
@@ -2,12 +2,11 @@
|
||||
* @flow
|
||||
* Firestore representation wrapper
|
||||
*/
|
||||
import { NativeModules } from 'react-native';
|
||||
|
||||
import ModuleBase from './../../utils/ModuleBase';
|
||||
import CollectionReference from './CollectionReference';
|
||||
import DocumentReference from './DocumentReference';
|
||||
import DocumentSnapshot from './DocumentSnapshot';
|
||||
import FieldValue from './FieldValue';
|
||||
import GeoPoint from './GeoPoint';
|
||||
import Path from './Path';
|
||||
import WriteBatch from './WriteBatch';
|
||||
@@ -137,9 +136,6 @@ export default class Firestore extends ModuleBase {
|
||||
}
|
||||
|
||||
export const statics = {
|
||||
FieldValue: {
|
||||
delete: () => NativeModules.RNFirebaseFirestore && NativeModules.RNFirebaseFirestore.deleteFieldValue || {},
|
||||
serverTimestamp: () => NativeModules.RNFirebaseFirestore && NativeModules.RNFirebaseFirestore.serverTimestampFieldValue || {}
|
||||
},
|
||||
FieldValue,
|
||||
GeoPoint,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
|
||||
import DocumentReference from '../DocumentReference';
|
||||
import { DELETE_FIELD_VALUE, SERVER_TIMESTAMP_FIELD_VALUE } from '../FieldValue';
|
||||
import GeoPoint from '../GeoPoint';
|
||||
import Path from '../Path';
|
||||
import { typeOf } from '../../../utils';
|
||||
@@ -42,6 +43,12 @@ const buildTypeMap = (value: any): any => {
|
||||
if (value === null) {
|
||||
typeMap.type = 'null';
|
||||
typeMap.value = null;
|
||||
} else if (value === DELETE_FIELD_VALUE) {
|
||||
typeMap.type = 'fieldvalue';
|
||||
typeMap.value = 'delete';
|
||||
} else if (value === SERVER_TIMESTAMP_FIELD_VALUE) {
|
||||
typeMap.type = 'fieldvalue';
|
||||
typeMap.value = 'timestamp';
|
||||
} else if (type === 'boolean' || type === 'number' || type === 'string') {
|
||||
typeMap.type = type;
|
||||
typeMap.value = value;
|
||||
@@ -99,7 +106,9 @@ const parseNativeArray = (firestore: Object, nativeArray: Object[]): any[] => {
|
||||
|
||||
const parseTypeMap = (firestore: Object, typeMap: TypeMap): any => {
|
||||
const { type, value } = typeMap;
|
||||
if (type === 'boolean' || type === 'number' || type === 'string' || type === 'null') {
|
||||
if (type === 'null') {
|
||||
return null;
|
||||
} else if (type === 'boolean' || type === 'number' || type === 'string') {
|
||||
return value;
|
||||
} else if (type === 'array') {
|
||||
return parseNativeArray(firestore, value);
|
||||
|
||||
Reference in New Issue
Block a user