@@ -2161,6 +2161,13 @@ firebase.firestore.batch = (): firestore.WriteBatch => {
21612161 return batch ;
21622162} ;
21632163
2164+ firebase . firestore . runTransaction = ( updateFunction : ( transaction : firestore . Transaction ) => Promise < any > ) : Promise < void > => {
2165+ return new Promise ( ( resolve , reject ) => {
2166+ // Why? See the note in the commented 'runTransaction' function below.
2167+ reject ( "Not supported on Android. If you need a x-platform implementation, use 'batch' instead." ) ;
2168+ } ) ;
2169+ } ;
2170+
21642171/*
21652172class FirestoreTransaction implements firestore.Transaction {
21662173
@@ -2172,7 +2179,6 @@ class FirestoreTransaction implements firestore.Transaction {
21722179 };
21732180
21742181 public set = (documentRef: firestore.DocumentReference, data: firestore.DocumentData, options?: firestore.SetOptions): firestore.Transaction => {
2175- console.log(">>> in tx.set");
21762182 if (options && options.merge) {
21772183 this.nativeTransaction.set(documentRef.android, firebase.toValue(data), com.google.firebase.firestore.SetOptions.merge());
21782184 } else {
@@ -2182,13 +2188,11 @@ class FirestoreTransaction implements firestore.Transaction {
21822188 };
21832189
21842190 public update = (documentRef: firestore.DocumentReference, data: firestore.UpdateData): firestore.Transaction => {
2185- console.log(">>> in tx.update");
21862191 this.nativeTransaction.update(documentRef.android, firebase.toValue(data));
21872192 return this;
21882193 };
21892194
21902195 public delete = (documentRef: firestore.DocumentReference): firestore.Transaction => {
2191- console.log(">>> in tx.delete");
21922196 this.nativeTransaction.delete(documentRef.android);
21932197 return this;
21942198 }
@@ -2209,49 +2213,16 @@ firebase.firestore.runTransaction = (updateFunction: (transaction: firestore.Tra
22092213 }
22102214 });
22112215
2212- const l = new java.util.ArrayList();
2213- l.add("foooo");
2214- l.add("barrr");
2215- org.nativescript.plugins.firebase.FirebaseFirestore.STATE = onSuccessListenert; // for this assignment to 'stick', this needs to be a real Java object
2216- org.nativescript.plugins.firebase.FirebaseFirestore.UPDATE_FUNCTION = updateFunction;
2217- console.log(">>> STATE: " + org.nativescript.plugins.firebase.FirebaseFirestore.STATE);
2218- console.log(">>> UPDATE_FUNCTION: " + org.nativescript.plugins.firebase.FirebaseFirestore.UPDATE_FUNCTION);
2219-
2220- let worker;
2221- if (global['TNS_WEBPACK']) {
2222- const WorkerScript = require('nativescript-worker-loader!./android-firestoretx-worker.js');
2223- worker = new WorkerScript();
2224- } else {
2225- worker = new Worker('./android-firestoretx-worker.js');
2226- }
2227-
2228- (<any>global).theUpdateFunction = updateFunction;
2229-
2230- worker.onmessage = msg => {
2231- console.log(">>> msg from worker, stringified: " + JSON.stringify(msg));
2232- };
2233-
2234- worker.onerror = err => {
2235- console.log(">>> worker err: " + JSON.stringify(err));
2236- };
2237-
2238- worker.postMessage({
2239- in: "innn",
2240- someArray: l,
2241- onSuccessListenert: onSuccessListenert
2242- // updateFunction: updateFunction
2243- });
2244-
22452216 const onSuccessListener = new com.google.android.gms.tasks.OnSuccessListener({
2246- onSuccess: resolve // TODO does this syntax work? if so: refactor other instances... otherwise use: onSuccess: () => resolve()
2217+ onSuccess: () => resolve()
22472218 });
22482219
22492220 const onFailureListener = new com.google.android.gms.tasks.OnFailureListener({
22502221 onFailure: exception => reject(exception.getMessage())
22512222 });
22522223
2253- // TODO apply is called from java to js, so that makes it run on the main/UI thread.. so doesn't work
2254- // .. can we share native objects via appcontext (for a worker)?
2224+ // NOTE: Here's the problem: ' apply' is called from java to js, so that makes it run on the main/UI thread,
2225+ // which is not allowed by Firebase.. so doesn't work in {N}
22552226 const txFunction = new com.google.firebase.firestore.Transaction.Function({
22562227 apply: (nativeTransaction: com.google.firebase.firestore.Transaction) => {
22572228 const tx = new firebase.firestore.Transaction(nativeTransaction);
@@ -2262,8 +2233,6 @@ firebase.firestore.runTransaction = (updateFunction: (transaction: firestore.Tra
22622233 com.google.firebase.firestore.FirebaseFirestore.getInstance().runTransaction(txFunction)
22632234 .addOnSuccessListener(onSuccessListener)
22642235 .addOnFailureListener(onFailureListener);
2265-
2266- // org.nativescript.plugins.firebase.FirebaseFirestore.runTransaction(txFunction, onSuccessListener, onFailureListener);
22672236 });
22682237};
22692238*/
0 commit comments