Files
react-native-firebase/src/modules/firestore/FieldValue.js
Andrzej Lewandowski 44c7c92acf [Android][IOS][Firestore] add arrayRemove and arrayUnion to FieldValue (#1624)
### 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
2018-10-23 13:40:11 +01:00

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';