mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-12 10:27:00 +08:00
### Summary Add methods arrayRemove and arrayUnion to work with arrays in firestore. Fixes #1389 ### Checklist * [x] Supports `Android` * [x] Supports `iOS` * [x] `e2e` tests added or updated in [/tests/e2e/*](/tests/e2e) * [x] Updated the documentation in the [docs repo](https://github.com/invertase/react-native-firebase-docs) https://github.com/invertase/react-native-firebase-docs/pull/134 * [x] Flow types updated * [x] Typescript types updated
47 lines
1012 B
JavaScript
47 lines
1012 B
JavaScript
/**
|
|
* @flow
|
|
* FieldValue representation wrapper
|
|
*/
|
|
import AnyJs from './utils/any';
|
|
|
|
// TODO: Salakar: Refactor in v6
|
|
export default class FieldValue {
|
|
_type: string;
|
|
|
|
_elements: AnyJs[] | any;
|
|
|
|
constructor(type: string, elements?: AnyJs[]) {
|
|
this._type = type;
|
|
this._elements = elements;
|
|
}
|
|
|
|
get type(): string {
|
|
return this._type;
|
|
}
|
|
|
|
get elements(): AnyJs[] {
|
|
return this._elements;
|
|
}
|
|
|
|
static delete(): FieldValue {
|
|
return new FieldValue(TypeFieldValueDelete);
|
|
}
|
|
|
|
static serverTimestamp(): FieldValue {
|
|
return new FieldValue(TypeFieldValueTimestamp);
|
|
}
|
|
|
|
static arrayUnion(...elements: AnyJs[]) {
|
|
return new FieldValue(TypeFieldValueUnion, elements);
|
|
}
|
|
|
|
static arrayRemove(...elements: AnyJs[]) {
|
|
return new FieldValue(TypeFieldValueRemove, elements);
|
|
}
|
|
}
|
|
|
|
export const TypeFieldValueDelete = 'delete';
|
|
export const TypeFieldValueRemove = 'remove';
|
|
export const TypeFieldValueUnion = 'union';
|
|
export const TypeFieldValueTimestamp = 'timestamp';
|