From d0c8f10aa17c6cb5af1b213cbd72d19de91d24bb Mon Sep 17 00:00:00 2001 From: Matt Martin Date: Thu, 8 Dec 2016 09:31:32 -0800 Subject: [PATCH] Adding onReadyStateChange callback to setVariables `this.props.relay.setVariables` takes an optional callback that's not currently represented in the types. Just adding that. See this answer on StackOverflow for a high-level overview: http://stackoverflow.com/questions/35471836/loading-indicator-after-this-props-relay-setvariables-triggered-fetch And the docs have more detailed information about what the callback provides: https://facebook.github.io/relay/docs/guides-ready-state.html --- react-relay/index.d.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/react-relay/index.d.ts b/react-relay/index.d.ts index 3731f9ca5d..5aedbf914f 100644 --- a/react-relay/index.d.ts +++ b/react-relay/index.d.ts @@ -103,8 +103,31 @@ declare module "react-relay" { renderFailure?(error: Error, retry: Function): JSX.Element } + type ReadyStateEvent = + 'ABORT' | + 'CACHE_RESTORED_REQUIRED' | + 'CACHE_RESTORE_FAILED' | + 'CACHE_RESTORE_START' | + 'NETWORK_QUERY_ERROR' | + 'NETWORK_QUERY_RECEIVED_ALL' | + 'NETWORK_QUERY_RECEIVED_REQUIRED' | + 'NETWORK_QUERY_START' | + 'STORE_FOUND_ALL' | + 'STORE_FOUND_REQUIRED'; + + interface OnReadyStateChange { + (readyState: { + ready: boolean, + done: boolean, + stale: boolean, + error?: Error, + events: Array, + aborted: boolean + }): void + } + interface RelayProp { - variables: any - setVariables(variables: Object): void + variables: any + setVariables(variables: Object, onReadyStateChange?: OnReadyStateChange): void } }