Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Transactions sample #90

Closed
wants to merge 2 commits into from

Conversation

Janamou
Copy link
Contributor

@Janamou Janamou commented Jan 15, 2017

Because of this issue: #52

I created another version of the database example which uses only transactions for adding/removing/updating data.

I was able to rewrite it and have it working (also with delete through the transaction).

BUT!
I started to play with it and I have found a big differences in final behaviour of Dart and js version when the transaction function returns the same thing.

When I try to do this the transaction method:

  • return undefined;
    • js - Aborts transaction according to the docs
    • Dart - not possible to return simply undefined (without any interop?). So the only way is to return the old data… I can't use return null; for this
  • return null;
    • js - deletes the node
    • Dart - deletes the node but only in Dartium (stops working while compiled to js)
  • return;
    • js - same as return undefined;
    • Dart - deletes the node (stops working when compiled to js); e.g. same as return null;
  • return {};
    • js - deletes the node
    • Dart - deletes the node (WORKS compiled to js)

So the problem is that I am not able to simply do "abortion of the transaction" in Dart (only return the old data) and that return null doesn't work for node deletion after compilation. But I found the workaround of return {}; (it's commented in the sample)

I know that there is this issue but what about devs using the library. Mention this in the documentation of transaction() function? What do you think?

@kevmoo
Copy link
Contributor

kevmoo commented Jan 16, 2017

We'll really need dart-lang/sdk#24088 fixed to make progress here.

Is this straight-forward, @jacob314 ? @jakemac53 ?

@jacob314
Copy link

We could add a getter to js_util called "undefined".
It will work great it in ddc and dart2js but in dartium it will be a bit wonky.
Specifically in dart2js and dartium, it will work any time you would have used null but in dartium it will be strangely different from null. It will convert to undefined when passed to JS but otherwise it will look like an instance of some strange class (e.g. _JSUndefined).

@kevmoo
Copy link
Contributor

kevmoo commented Jan 17, 2017

I don't think folks would mind _JSUndefined showing up w/ Dartium.

@Janamou
Copy link
Contributor Author

Janamou commented Mar 26, 2017

Hi @kevmoo what to do with this pull req?

I think we should have some example with transactions in the library and I know that this is not ideal now (until fixed) :-) Or should I implement something easier (in another pull req to have this still opened) without deletion which is problematic?

@kevmoo
Copy link
Contributor

kevmoo commented Feb 25, 2018

Closing for now. I think we should focus on firestore.

@kevmoo kevmoo closed this Feb 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants