Skip to content

Commit

Permalink
Create RelayMutationQueue
Browse files Browse the repository at this point in the history
Summary: This is part 2 of contextualizing `RelayMutationTransaction`. D2632150 moved some state into a class, but left the mutation queue and associated maps global. Changes include:

- Create `RelayMutationQueue` to manage the queue of mutations for a given Relay context.
- Move most queue management logic from MutationTransaction to MutationQueue so that individual transactions are no longer managing the queue.
- Turn `RelayMutationTransaction` into a thin wrapper object designed for use as a public API (`RelayStore.update` could eventually return these instances)

Note that the API of `RelayMutationQueue` requires an opaque `id` input for all public methods, and this id is only known to `RelayMutationTransaction` instances created via `queue.createTransaction`.

Reviewed By: yungsters

Differential Revision: D2645472

fb-gh-sync-id: 3d71e17d7295657974fdca86f453f0e8501c79db
  • Loading branch information
josephsavona authored and facebook-github-bot-7 committed Nov 12, 2015
1 parent 7619c41 commit 6c41756
Show file tree
Hide file tree
Showing 7 changed files with 600 additions and 435 deletions.
8 changes: 5 additions & 3 deletions src/container/RelayContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,19 @@ function createContainerComponent(
* Returns the pending mutation transactions affecting the given record.
*/
getPendingTransactions(record: Object): ?Array<RelayMutationTransaction> {
var dataID = GraphQLStoreDataHandler.getID(record);
const dataID = GraphQLStoreDataHandler.getID(record);
invariant(
dataID != null,
'RelayContainer.getPendingTransactions(): Expected a record in `%s`.',
componentName
);
var mutationIDs = storeData.getQueuedStore().getClientMutationIDs(dataID);
const mutationIDs =
storeData.getQueuedStore().getClientMutationIDs(dataID);
if (!mutationIDs) {
return null;
}
return mutationIDs.map(RelayMutationTransaction.get);
const mutationQueue = storeData.getMutationQueue();
return mutationIDs.map(id => mutationQueue.getTransaction(id));
}

/**
Expand Down
Loading

0 comments on commit 6c41756

Please sign in to comment.