Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 43e76f8

Browse files
Merge pull request #1158 from Roomify/android-arrayRemove-object
#1157: Allow objects in arrayRemove on android
2 parents d2537f4 + 3196c5e commit 43e76f8

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

demo-ng/app/tabs/firestore/firestore.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ export class FirestoreComponent {
254254
.update({
255255
last: "Updated From 'arrayRemove'",
256256
updateTs: firebase.firestore().FieldValue().serverTimestamp(),
257-
colors: firebase.firestore().FieldValue().arrayRemove("red")
257+
colors: firestore.FieldValue.arrayUnion("red"),
258+
messages: firebase.firestore().FieldValue().arrayRemove({
259+
message: "Test 1",
260+
source: "central",
261+
time: Date.now()
262+
})
258263
})
259264
.then(() => console.log("Woofie updated from 'arrayRemove'"))
260265
.catch(err => console.log("Updating Woofie from 'arrayRemove' failed, error: " + JSON.stringify(err)));

src/firebase.android.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ firebase.toHashMap = obj => {
146146
values = values.map(v => typeof (v) === "object" ? firebase.toHashMap(v) : v);
147147
node.put(property, com.google.firebase.firestore.FieldValue.arrayUnion(values));
148148
} else if (fieldValue.type === "ARRAY_REMOVE") {
149-
node.put(property, com.google.firebase.firestore.FieldValue.arrayRemove(Array.isArray(fieldValue.value[0]) ? fieldValue.value[0] : fieldValue.value));
149+
let values: Array<any> = Array.isArray(fieldValue.value[0]) ? fieldValue.value[0] : fieldValue.value;
150+
values = values.map(v => typeof (v) === "object" ? firebase.toHashMap(v) : v);
151+
node.put(property, com.google.firebase.firestore.FieldValue.arrayRemove(values));
150152
} else {
151153
console.log("You found a bug! Please report an issue at https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues, mention fieldValue.type = '" + fieldValue.type + "'. Thanks!");
152154
}

0 commit comments

Comments
 (0)