From 3186a2ba273c41c91bde9f4adff3067ae1c901f7 Mon Sep 17 00:00:00 2001 From: voxmatt Date: Thu, 9 Mar 2017 16:52:56 -0800 Subject: [PATCH 1/5] fleshing out the relayProp --- react-relay/index.d.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/react-relay/index.d.ts b/react-relay/index.d.ts index 9c45ed9c7c..8170e03190 100644 --- a/react-relay/index.d.ts +++ b/react-relay/index.d.ts @@ -31,6 +31,24 @@ declare module "react-relay" { response: any } + type RelayMutationStatus = + 'UNCOMMITTED' | // Transaction hasn't yet been sent to the server. Transaction can be committed or rolled back. + 'COMMIT_QUEUED' | // Transaction was committed but another transaction with the same collision key is pending, so the transaction has been queued to send to the server. + 'COLLISION_COMMIT_FAILED' | //Transaction was queued for commit but another transaction with the same collision key failed. All transactions in the collision queue, including this one, have been failed. Transaction can be recommitted or rolled back. + 'COMMITTING' | // Transaction is waiting for the server to respond. + 'COMMIT_FAILED'; + + class RelayMutationTransaction { + applyOptimistic(): RelayMutationTransaction; + commit(): RelayMutationTransaction; + recommit(): void; + rollback(): void; + getError(): Error; + getStatus(): RelayMutationStatus; + getHash(): string; + getID(): string; + } + interface RelayMutationRequest { getQueryString(): string getVariables(): RelayVariables @@ -104,7 +122,7 @@ declare module "react-relay" { renderFailure?(error: Error, retry: Function): JSX.Element } - type ReadyStateEvent = + type ReadyStateEvent = 'ABORT' | 'CACHE_RESTORED_REQUIRED' | 'CACHE_RESTORE_FAILED' | @@ -128,7 +146,12 @@ declare module "react-relay" { } interface RelayProp { - variables: any - setVariables(variables: Object, onReadyStateChange?: OnReadyStateChange): void + route: { name: string; }; // incomplete, also has params and queries + variables: any; + pendingVariables?: any; + setVariables(variables: Object, onReadyStateChange?: OnReadyStateChange): void; + forceFetch(variables: Object, onReadyStateChange?: OnReadyStateChange): void; + hasOptimisticUpdate(record: any): boolean; + getPendingTransactions(record: any): RelayMutationTransaction[]; } } From 4cc74c831a3f186cf42e417a462257f97fa526e3 Mon Sep 17 00:00:00 2001 From: voxmatt Date: Thu, 9 Mar 2017 17:22:18 -0800 Subject: [PATCH 2/5] fixing tests --- react-relay/index.d.ts | 4 ++-- react-relay/react-relay-tests.tsx | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/react-relay/index.d.ts b/react-relay/index.d.ts index 8170e03190..5b40145d18 100644 --- a/react-relay/index.d.ts +++ b/react-relay/index.d.ts @@ -151,7 +151,7 @@ declare module "react-relay" { pendingVariables?: any; setVariables(variables: Object, onReadyStateChange?: OnReadyStateChange): void; forceFetch(variables: Object, onReadyStateChange?: OnReadyStateChange): void; - hasOptimisticUpdate(record: any): boolean; - getPendingTransactions(record: any): RelayMutationTransaction[]; + hasOptimisticUpdate(record?: any): boolean; + getPendingTransactions(record?: any): RelayMutationTransaction[]; } } diff --git a/react-relay/react-relay-tests.tsx b/react-relay/react-relay-tests.tsx index 7160e60b0a..fa27f10c01 100644 --- a/react-relay/react-relay-tests.tsx +++ b/react-relay/react-relay-tests.tsx @@ -74,10 +74,16 @@ class StubbedArtwork extends React.Component { const props = { artwork: { title: "CHAMPAGNE FORMICA FLAG" }, relay: { + route: { + name: "champagne" + }, variables: { artworkID: "champagne-formica-flag", }, setVariables: () => {}, + forceFetch: () => {}, + hasOptimisticUpdate: () => false, + getPendingTransactions: (): Relay.RelayMutationTransaction[] => undefined, } } return From 498bf589489249b77f4259a95fe9dd97a670aab6 Mon Sep 17 00:00:00 2001 From: voxmatt Date: Thu, 9 Mar 2017 17:26:33 -0800 Subject: [PATCH 3/5] adding in commitUpdate while I'm at it --- react-relay/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/react-relay/index.d.ts b/react-relay/index.d.ts index 5b40145d18..0f6dbba024 100644 --- a/react-relay/index.d.ts +++ b/react-relay/index.d.ts @@ -153,5 +153,6 @@ declare module "react-relay" { forceFetch(variables: Object, onReadyStateChange?: OnReadyStateChange): void; hasOptimisticUpdate(record?: any): boolean; getPendingTransactions(record?: any): RelayMutationTransaction[]; + commitUpdate?: (mutation: Mutation, callbacks?: StoreUpdateCallbacks) => any; } } From e466571159287b9cbab031fc0b4f919a95694c12 Mon Sep 17 00:00:00 2001 From: voxmatt Date: Fri, 10 Mar 2017 10:29:12 -0800 Subject: [PATCH 4/5] a bunch of updates in response to code review --- react-relay/index.d.ts | 16 +++++++++------- react-relay/react-relay-tests.tsx | 1 + 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/react-relay/index.d.ts b/react-relay/index.d.ts index 0f6dbba024..961acbccc2 100644 --- a/react-relay/index.d.ts +++ b/react-relay/index.d.ts @@ -7,6 +7,8 @@ declare module "react-relay" { import * as React from "react"; + type ClientMutationID = string; + /** Fragments are a hash of functions */ interface Fragments { [query: string]: ((variables?: RelayVariables) => string) @@ -40,13 +42,13 @@ declare module "react-relay" { class RelayMutationTransaction { applyOptimistic(): RelayMutationTransaction; - commit(): RelayMutationTransaction; + commit(): RelayMutationTransaction | null; recommit(): void; rollback(): void; getError(): Error; getStatus(): RelayMutationStatus; getHash(): string; - getID(): string; + getID(): ClientMutationID; } interface RelayMutationRequest { @@ -147,12 +149,12 @@ declare module "react-relay" { interface RelayProp { route: { name: string; }; // incomplete, also has params and queries - variables: any; - pendingVariables?: any; + variables: Object; + pendingVariables?: Object | null; setVariables(variables: Object, onReadyStateChange?: OnReadyStateChange): void; forceFetch(variables: Object, onReadyStateChange?: OnReadyStateChange): void; - hasOptimisticUpdate(record?: any): boolean; - getPendingTransactions(record?: any): RelayMutationTransaction[]; - commitUpdate?: (mutation: Mutation, callbacks?: StoreUpdateCallbacks) => any; + hasOptimisticUpdate(record: Object): boolean; + getPendingTransactions(record: Object): RelayMutationTransaction[]; + commitUpdate: (mutation: Mutation, callbacks?: StoreUpdateCallbacks) => any; } } diff --git a/react-relay/react-relay-tests.tsx b/react-relay/react-relay-tests.tsx index fa27f10c01..091909cabd 100644 --- a/react-relay/react-relay-tests.tsx +++ b/react-relay/react-relay-tests.tsx @@ -84,6 +84,7 @@ class StubbedArtwork extends React.Component { forceFetch: () => {}, hasOptimisticUpdate: () => false, getPendingTransactions: (): Relay.RelayMutationTransaction[] => undefined, + commitUpdate: () => {}, } } return From 0a5c482bc7b4a830644c6103640d391749517fae Mon Sep 17 00:00:00 2001 From: voxmatt Date: Fri, 10 Mar 2017 14:23:33 -0800 Subject: [PATCH 5/5] fixing tests and removing Object references --- react-relay/index.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/react-relay/index.d.ts b/react-relay/index.d.ts index 961acbccc2..a693527e3e 100644 --- a/react-relay/index.d.ts +++ b/react-relay/index.d.ts @@ -15,7 +15,7 @@ declare module "react-relay" { } interface CreateContainerOpts { - initialVariables?: Object + initialVariables?: any fragments: Fragments prepareVariables?(prevVariables: RelayVariables): RelayVariables } @@ -148,13 +148,13 @@ declare module "react-relay" { } interface RelayProp { - route: { name: string; }; // incomplete, also has params and queries - variables: Object; - pendingVariables?: Object | null; - setVariables(variables: Object, onReadyStateChange?: OnReadyStateChange): void; - forceFetch(variables: Object, onReadyStateChange?: OnReadyStateChange): void; - hasOptimisticUpdate(record: Object): boolean; - getPendingTransactions(record: Object): RelayMutationTransaction[]; + readonly route: { name: string; }; // incomplete, also has params and queries + readonly variables: any; + readonly pendingVariables?: any | null; + setVariables(variables: any, onReadyStateChange?: OnReadyStateChange): void; + forceFetch(variables: any, onReadyStateChange?: OnReadyStateChange): void; + hasOptimisticUpdate(record: any): boolean; + getPendingTransactions(record: any): RelayMutationTransaction[]; commitUpdate: (mutation: Mutation, callbacks?: StoreUpdateCallbacks) => any; } }