Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add commitUpdate method, deprecate update #607

Closed
wants to merge 2 commits into from

Conversation

xuorig
Copy link
Contributor

@xuorig xuorig commented Nov 17, 2015

Follow up to #599, #550

Deprecate RelayStore.update, rename to RelayStore.commitUpdate

commitUpdate now returns the RelayMutationTransaction just like applyUpdate.

Changed to commitUpdate in the docs.

I used warning to deprecate and also call the correct method, let me know if this is the way we should deprecate the function.

@@ -161,6 +162,10 @@ var RelayStore = {
return new RelayQueryResultObservable(storeData, fragmentPointer);
},

/**
* Adds an update to the store without committing it. The returned
* RelayMutationTransaction can be commited or rollbacked at a later time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay docblocks! maybe "committed or rolled back"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep makes more sense 👯

@xuorig
Copy link
Contributor Author

xuorig commented Nov 17, 2015

Addressed the comments ☕

@@ -15,7 +15,7 @@ The Relay `Store` provides an API for dispatching mutations to the server.

<ul class="apiIndex">
<li>
<a href="#update-static-method">
<a href="#commitupdate-static-method">
<pre>static update(mutation, callbacks)</pre>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the link text: update -> commitUpdate

@xuorig
Copy link
Contributor Author

xuorig commented Nov 17, 2015

@plievone done

@plievone
Copy link
Contributor

Perhaps also the few mentions in examples and docs could be commitUpdated, as they are in the same repo and easy to grep?
https://github.com/facebook/relay/search?utf8=%E2%9C%93&q=%22Store.update%22&type=Code

@xuorig
Copy link
Contributor Author

xuorig commented Nov 17, 2015

Good catch, I've updated docs and examples

@josephsavona
Copy link
Contributor

@facebook-github-bot import

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1679180675656670/int_phab to review.

@josephsavona
Copy link
Contributor

@xuorig we'll land this as time permits - shipping it requires a codemod bc we don't want warnings everywhere we call update.

@xuorig
Copy link
Contributor Author

xuorig commented Nov 19, 2015

👍

@jardakotesovec
Copy link
Contributor

It seems to me that this implementation does not cover use case, when it just wants to avoid stacking many mutations in collision queue. Which is the use case for updating text input or anything where user can change values quickly and it wants to remove previous transaction if its just sitting on the queue with newer one.

As far as I can see - to put mutation on the collision queue I have to commit it, but I can't rollback if it just sits on the queue and has not been sent, right?

Maybe if rollback would be also possible when transaction is in COMMIT_QUEUED?

@jardakotesovec
Copy link
Contributor

@josephsavona @xuorig What do you think? Should I provide another PR that adjust rollback function that can rollback also transactions with status COMMIT_QUEUED?

@josephsavona
Copy link
Contributor

Should I provide another PR that adjust rollback function that can rollback also transactions with status COMMIT_QUEUED?

@jardakotesovec That would be great - all that should be required is updating the status check in RelayMutationTransaction to allow calling rollback when the transaction is queued. The actual logic for the rollback in RelayMutationQueue should already handle this case.

@Globegitter
Copy link
Contributor

Does this cover the use case where I want to commit data to my local cache in different places (don't care about the transactions returned) but then just want to update everything that is stored in the cache, but now out of sync with the backend?

@jardakotesovec
Copy link
Contributor

@Globegitter It does not.. as decided in #550, control of transaction handling is given to the programmer. So with this PR, you have to keep track of the transactions on your own.

But api could be extended for example to either provide function that commit all uncommited transactions as you suggested, or just provide you list of uncommited transactions so you can commit them.

@Globegitter
Copy link
Contributor

@jardakotesovec So right now we would have to manually keep track of each transaction that is being returned by applyUpdate (and e.g. store them in an array). Then at some point just go through all the transactions and commit them? Would this then make an individual request for each committed transaction or is there a way to commit all transactions in one HTTP request?

But yeah for our use-case it would be useful to have an API to commit all uncommitted transactions (in one request).

@jardakotesovec
Copy link
Contributor

@Globegitter I think you should open new issue/PR to keep track of this use case and discuss potential improvements.

Relay currently sends one http request per mutation.

What you have described is correct (keeping list of transaction and committing all of them individually)

@ghost ghost closed this in 8961271 Jan 8, 2016
ghost pushed a commit that referenced this pull request Mar 8, 2016
Summary:This is follow up to #607 that adds posibility to rollback transaction with status `COMMIT_QUEUED`.

There is one more missing piece for this use case that I was not sure how to approach.

To replace transaction that is queued I need to first check if its status is still `COMMIT_QUEUED`. Issue is that transaction is removed from pendingTransactionMap once its successfully committed. So I can easily end up with exception from `getStatus()`, which is bit overreaction :-).

So maybe return some status like `FINISHED` instead of throwing if its not in pending queue? I am of course very opened about naming :-).
Closes #646

Reviewed By: josephsavona

Differential Revision: D3021199

Pulled By: yungsters

fb-gh-sync-id: 2ee1d2849d8bd5081ef57a42c136d644b61e95bd
shipit-source-id: 2ee1d2849d8bd5081ef57a42c136d644b61e95bd
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants