Nativescript-plugin-firebase: Batch and Transaction Operation in FireStore

Created on 4 Apr 2018  Â·  17Comments  Â·  Source: EddyVerbruggen/nativescript-plugin-firebase

Firestore supports Batch and Transaction Operation api. The same can be found here https://firebase.google.com/docs/firestore/manage-data/transactions. But the current plugin does not support this api. Please look into this.

Android Firestore enhancement iOS

Most helpful comment

I've just finished support for Firebase "batched writes", see the docs here: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/FIRESTORE.md#batch

The API is 100% compatible with the Web API you can find here, in the Firebase docs (scroll down to "Batched Writes" and select the "Web" tab).

I've also been working on runTransaction (see "Updating data with transactions" in the aforementioned Firebase doc). On iOS this works perfectly fine, but on Android I ran into a nasty threading issue I wasn't able to solve (yet).

Luckily most of the transaction features are covered by batch. But I will take another look before closing this issue.

Available with 6.5.0, which will be released later this month.

All 17 comments

Yep, that's not supported yet. Are you up for a PR?

I'm a rookie. I'll need understanding of nativescript. Nevertheless, I'm up for it. Could you just guide me how to contribute?

That would be great!

You can press the 'Fork' button at the top right, and clone the repo locally. The (preferably) switch to a new branch). Once done you push everything to your fork's GitHub repo and press the 'Pull Request' button to request merging it to this (upstream) repo.

The first rule of any PR is: keep it focused; make sure you're only doing 1 thing and not fi also refactor everything (that could be a separate Pull Request).

As for the actual content of the PR, you probably want to look at this doc (for iOS in this case).

To run the plugin and demo app locally you can cd src and npm run demo.ios.

Thanks for your input. Forking the repo. Will post here, if I get stuck.

Any news on batch and transactions implementation?

Hey @EddyVerbruggen, welcome back from vacation!

We are about to start converting our existing cordova app to nativescript, but need to have transaction and batch support in your plugin.

Can you give us a timeframe?

Apology guys!

I could not contribute.

On Wed 8 Aug, 2018, 3:11 PM nuvoPoint, notifications@github.com wrote:

Hey @EddyVerbruggen https://github.com/EddyVerbruggen, welcome back
from vacation!

We are about to start converting our existing cordova app to nativescript,
but need to have transaction and batch support in your plugin.

Can you give us a timeframe?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/667#issuecomment-411348592,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AE9jEkidmt02F_WsN16Ct4y85aZRlJN_ks5uOrI7gaJpZM4TGhew
.

Nice to see you here @EddyVerbruggen. You're disillusioned with Cordova as well I take it? 😄

If I have time (rarely do), I'll do a PR later.

Hi @larssn, lets’s say I’m expanding my horizon :)

I’m actually currently working on this feature, but thanks for offering help! There are plenty of issues to look at if you ever feel like contributing. But steer away from anything related to push notifications because that’ll soon be refactored.

@EddyVerbruggen Alrighty :-)

We're planning on expanding our horizons into Nativescript beginning next year, by converting our pretty big Cordova app to Nativescript. We're mostly annoyed with webview quirks, and the inefficient indexeddb layer in said webviews.

I've just finished support for Firebase "batched writes", see the docs here: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/FIRESTORE.md#batch

The API is 100% compatible with the Web API you can find here, in the Firebase docs (scroll down to "Batched Writes" and select the "Web" tab).

I've also been working on runTransaction (see "Updating data with transactions" in the aforementioned Firebase doc). On iOS this works perfectly fine, but on Android I ran into a nasty threading issue I wasn't able to solve (yet).

Luckily most of the transaction features are covered by batch. But I will take another look before closing this issue.

Available with 6.5.0, which will be released later this month.

I tried standing on my head and every other trick to get "Transactional Updates" working on Android, but I give up. You can use it on iOS (see the docs), but for a x-plat solution use "Batched Writes" as mentioned above.

What problems are you seeing? Asking in case I decide to dive into it :-)

See the commented runTransaction code in src/firebase.android.ts.

It wants to not run on the main thread.

Have you tried using workers? From the sound of it, they don't run on the UI thread. Could be wrong, the docs are unclear about that.

@larssn Absolutely, but workers only allow sending plain JS objects back and forth, and this implementation requires sending native objects. I even implemented entirely in native Java, but still, that native code needs to call back to JS while it's running, forcing it to go back to the main thread.

@EddyVerbruggen Going to take a stab at making this work for Android. I wrote some java code and wanted to put that into the src directory, but when I put it in src/platforms/android/java/com/tns/test.java it fails to build with Could not get unknown property 'supportVersion' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

If I wanted to have native Java code, where should I put it so I can access it from firebase.android.ts? Not sure if I need to create a .jar or .aar file with my java class.

I am also curious as to what you have already tried so that I do not redo the same thing (You mentioned that you tried implementing the entire thing in Java and it wouldn't work.)

Was this page helpful?
0 / 5 - 0 ratings