ReallySmallSoftware / cordova-plugin-firestore

A Google Firebase Firestore plugin to enable realtime synchronisation between app and cloud and automatically handle limited connectivity.
Other
22 stars 10 forks source link

[FIX] Firestore.FieldValue(arrayUnion||arrayRemove||increment) - iOS #48

Open spoxies opened 1 year ago

spoxies commented 1 year ago

Fixes Firestore.Firestore.FieldValue.arrayUnion() Firestore.Firestore.FieldValue.arrayRemove() Firestore.Firestore.FieldValue.increment(1)

Example use case:

var firebaseOptions = {
    "datePrefix": '__DATE:',
    "fieldValueDelete": "__DELETE",
    "fieldValueServerTimestamp": "__SERVERTIMESTAMP",
    "persist": true,
};

Firestore.initialise(firebaseOptions).then(function (db) {
    // Add a second document with a generated ID.
    return db.get().collection("users").doc("someUserId").update({
        someField : Firestore.Firestore.FieldValue.arrayUnion('carrot'),
        someCount: Firestore.Firestore.FieldValue.increment(4)
    }).catch(function (error) {
        console.error("Error adding document: ", error);
    });
});

Proposed Changes

spoxies commented 1 year ago

Colon was not removed by unwrap method in @implementation FirestorePluginJSONHelper (iOS) eg: "__INCREMENT:4" returned ":4" instead of "4"

Added +1 to return [stringValue substringFromIndex:prefix.length+1];.

Seems this was all ready implemented as such on Android FieldValueHelper.java