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 updateLocal method to create transaction without comitting it #599

Closed
wants to merge 1 commit into from

Conversation

xuorig
Copy link
Contributor

@xuorig xuorig commented Nov 14, 2015

For #550

Adds an updateLocal method to RelayStore that creates a transaction in the Queue, but doesn't commit it.

Returns a reference to the transaction so it can be committed or rollbacked afterwards.

There weren't any tests for update so I added a test for update and updateLocal, just making sure if the correct functions on the Queue and Transaction are called.

@josephsavona
Copy link
Contributor

This looks good, and thanks for the tests!

Having two such similar methods is definitely redundant though. @yungsters @wincent - thoughts on making it the default for update to not commit the transaction, and require users to call commit()? We could keep the old behavior for one release with a warning.

@wincent
Copy link
Contributor

wincent commented Nov 15, 2015

thoughts on making it the default for update to not commit the transaction

We should optimize for the most common use case, although figuring out what exactly that is is tricky. My intuition is that controlled inputs bound to mutations are actually the edge case, so the existing auto-commit behavior should be easy and the deferred-commit-managed-by-the-user behavior should be possible.

So another possible option to consider:

  • Make it a single method, with the commit behavior controllable via an options object where {commit: true} is the default.

If we go with two methods, I am not sure the meaning of the updateLocal method is obvious from its name. Naming is hard, but other ideas that crossed my mind are enqueueUpdate/commitUpdate.

Finally, as for the idea of making update the only method and not committing by default, I could live with that (and it would conveniently liberate us from having to come up with decent names for two methods).

@josephsavona
Copy link
Contributor

Good points. So there are three options:

  • two methods, which should then both return a MutationTransaction for consistency
  • one method that auto-commits by default, with an option to not commit. It returns the transaction. This means store.update(mutation, callbacks).commit() will throw (already committing) but store.update(mutation, callbacks, {commit: false}).commit() is ok
  • one method, never auto-commits: store.update(mutation, callbacks).commit() or leave off the commit() call to defer.

The last option feels the least awkward (especially with a rename s/update/enqueueUpdate/), and it also makes the option to enqueue a mutation but not commit it more discoverable.

@xuorig
Copy link
Contributor Author

xuorig commented Nov 15, 2015

the existing auto-commit behavior should be easy and the deferred-commit-managed-by-the-user behavior should be possible.

Totally agree with this, I really think the deferred commit way will be used in edge cases and probably should not be the default.

This means store.update(mutation, callbacks).commit() will throw (already committing) but store.update(mutation, callbacks, {commit: false}).commit() is ok

Which means this would make sense, but it does seem fairly awkward. I would personally probably go for this anyway I think.

Let me know what you guys decide to go for and I'll update the PR

@josephsavona
Copy link
Contributor

@xuorig thanks for your patience. We chatted offline and came up with the following API:

  1. Relay.Store.applyUpdate(mutation, callbacks): RelayMutationTransaction - does not commit the mutation immediately (e.g: rename updateLocal to applyUpdate)
  2. Relay.Store.commitUpdate(mutation, callbacks): RelayMutationTransaction - commits the mutation immediately (this replaces the existing update)
  3. Relay.Store.update(...): void - mark this as deprecated and suggest using commitUpdate.

Would you mind changing updateLocal -> applyUpdate and adding docs for this method (item 1)? We can address 2 & 3 separately (of course you're welcome to do these too if you have time). Thanks!

@xuorig xuorig force-pushed the debounce-mutations branch from e7a14bf to f004a3c Compare November 16, 2015 19:31
@xuorig
Copy link
Contributor Author

xuorig commented Nov 16, 2015

Alright, I changed the method name to applyUpdate + updated the docs with example and some info.

Squashed + reworded commit also.

I will tackle 2 and 3 in another PR

@xuorig xuorig force-pushed the debounce-mutations branch 2 times, most recently from d7b7302 to 658fe5e Compare November 16, 2015 19:44

```
static applyUpdate(mutation: RelayMutation, callbacks: {
onFailure?: (transaction: Transaction) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: transaction: RelayMutationTransaction (also should update the above doc for update for consistency)

@josephsavona
Copy link
Contributor

@xuorig awesome, thanks! just two minor nits, otherwise this looks good to go.

@xuorig xuorig force-pushed the debounce-mutations branch from 658fe5e to a43fa63 Compare November 16, 2015 23:57
@xuorig
Copy link
Contributor Author

xuorig commented Nov 16, 2015

Addressed your nits!

@josephsavona
Copy link
Contributor

@facebook-github-bot import

@josephsavona
Copy link
Contributor

👍

@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/1727015024195186/int_phab to review.

@ghost ghost closed this in 598a343 Nov 17, 2015
ghost pushed a commit that referenced this pull request Jan 8, 2016
Summary:
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.
Closes #607

Reviewed By: yungsters

Differential Revision: D2668030

fb-gh-sync-id: 2a02b38009cf125089ddc341ce82173aee9fa294
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.

4 participants