react-relay 14.0.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -2
  4. package/ReactRelayFragmentContainer.js.flow +6 -4
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -2
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -5
  7. package/ReactRelayPaginationContainer.js.flow +21 -14
  8. package/ReactRelayQueryFetcher.js.flow +28 -16
  9. package/ReactRelayQueryRenderer.js.flow +42 -13
  10. package/ReactRelayQueryRendererContext.js.flow +2 -3
  11. package/ReactRelayRefetchContainer.js.flow +9 -9
  12. package/ReactRelayTestMocker.js.flow +3 -3
  13. package/ReactRelayTypes.js.flow +7 -8
  14. package/RelayContext.js.flow +1 -2
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -2
  34. package/buildReactRelayContainer.js.flow +7 -7
  35. package/getRootVariablesForFragments.js.flow +1 -3
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -2
  38. package/index.js +1 -1
  39. package/index.js.flow +6 -2
  40. package/isRelayEnvironment.js.flow +1 -2
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -2
  46. package/lib/ReactRelayContainerUtils.js +2 -3
  47. package/lib/ReactRelayContext.js +3 -4
  48. package/lib/ReactRelayFragmentContainer.js +47 -73
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -4
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -31
  51. package/lib/ReactRelayPaginationContainer.js +74 -164
  52. package/lib/ReactRelayQueryFetcher.js +49 -76
  53. package/lib/ReactRelayQueryRenderer.js +63 -84
  54. package/lib/ReactRelayQueryRendererContext.js +2 -2
  55. package/lib/ReactRelayRefetchContainer.js +58 -108
  56. package/lib/ReactRelayTestMocker.js +33 -68
  57. package/lib/ReactRelayTypes.js +2 -1
  58. package/lib/RelayContext.js +4 -7
  59. package/lib/assertFragmentMap.js +3 -5
  60. package/lib/buildReactRelayContainer.js +11 -27
  61. package/lib/getRootVariablesForFragments.js +6 -10
  62. package/lib/hooks.js +5 -18
  63. package/lib/index.js +7 -24
  64. package/lib/isRelayEnvironment.js +5 -4
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -8
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
  74. package/lib/relay-hooks/FragmentResource.js +109 -203
  75. package/lib/relay-hooks/HooksImplementation.js +3 -6
  76. package/lib/relay-hooks/InternalLogger.js +2 -3
  77. package/lib/relay-hooks/LRUCache.js +2 -20
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
  79. package/lib/relay-hooks/MatchContainer.js +15 -24
  80. package/lib/relay-hooks/ProfilerContext.js +3 -3
  81. package/lib/relay-hooks/QueryResource.js +31 -101
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
  83. package/lib/relay-hooks/SuspenseResource.js +9 -33
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +42 -78
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
  99. package/lib/relay-hooks/useClientQuery.js +30 -0
  100. package/lib/relay-hooks/useEntryPointLoader.js +18 -38
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
  102. package/lib/relay-hooks/useFragment.js +8 -19
  103. package/lib/relay-hooks/useFragmentNode.js +20 -32
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -6
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
  109. package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
  111. package/lib/relay-hooks/useMemoVariables.js +15 -34
  112. package/lib/relay-hooks/useMutation.js +9 -27
  113. package/lib/relay-hooks/usePaginationFragment.js +73 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +13 -44
  115. package/lib/relay-hooks/useQueryLoader.js +24 -49
  116. package/lib/relay-hooks/useRefetchableFragment.js +19 -17
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -8
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
  121. package/lib/relay-hooks/useSubscription.js +5 -10
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
  135. package/relay-hooks/FragmentResource.js.flow +43 -19
  136. package/relay-hooks/HooksImplementation.js.flow +7 -9
  137. package/relay-hooks/InternalLogger.js.flow +1 -3
  138. package/relay-hooks/LRUCache.js.flow +1 -3
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
  140. package/relay-hooks/MatchContainer.js.flow +6 -8
  141. package/relay-hooks/ProfilerContext.js.flow +1 -3
  142. package/relay-hooks/QueryResource.js.flow +29 -11
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
  144. package/relay-hooks/SuspenseResource.js.flow +1 -3
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
  153. package/relay-hooks/__flowtests__/utils.js.flow +21 -12
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
  169. package/relay-hooks/useClientQuery.js.flow +39 -0
  170. package/relay-hooks/useEntryPointLoader.js.flow +16 -14
  171. package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
  172. package/relay-hooks/useFragment.js.flow +2 -4
  173. package/relay-hooks/useFragmentNode.js.flow +7 -8
  174. package/relay-hooks/useIsMountedRef.js.flow +2 -4
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
  179. package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
  181. package/relay-hooks/useMemoVariables.js.flow +13 -31
  182. package/relay-hooks/useMutation.js.flow +6 -8
  183. package/relay-hooks/usePaginationFragment.js.flow +75 -43
  184. package/relay-hooks/usePreloadedQuery.js.flow +49 -43
  185. package/relay-hooks/useQueryLoader.js.flow +89 -28
  186. package/relay-hooks/useRefetchableFragment.js.flow +83 -23
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -4
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
  191. package/relay-hooks/useSubscription.js.flow +1 -3
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -28
  194. package/readContext.js.flow +0 -31
@@ -6,82 +6,82 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
10
- // flowlint ambiguous-object-type:error
11
- 'use strict';
12
11
 
13
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
12
+ 'use strict';
14
13
 
14
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
15
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
-
17
16
  var invariant = require('invariant');
18
-
19
17
  var _require = require('relay-runtime'),
20
- fetchQuery = _require.__internal.fetchQuery,
21
- createOperationDescriptor = _require.createOperationDescriptor,
22
- isRelayModernEnvironment = _require.isRelayModernEnvironment;
23
-
18
+ fetchQuery = _require.__internal.fetchQuery,
19
+ createOperationDescriptor = _require.createOperationDescriptor,
20
+ isRelayModernEnvironment = _require.isRelayModernEnvironment;
24
21
  var ReactRelayQueryFetcher = /*#__PURE__*/function () {
25
22
  function ReactRelayQueryFetcher(args) {
26
23
  (0, _defineProperty2["default"])(this, "_selectionReferences", []);
27
- (0, _defineProperty2["default"])(this, "_callOnDataChangeWhenSet", false);
28
-
24
+ (0, _defineProperty2["default"])(this, "_didFetchFinish", false);
29
25
  if (args != null) {
30
26
  this._cacheSelectionReference = args.cacheSelectionReference;
31
27
  this._selectionReferences = args.selectionReferences;
32
28
  }
33
29
  }
34
-
35
30
  var _proto = ReactRelayQueryFetcher.prototype;
36
-
37
31
  _proto.getSelectionReferences = function getSelectionReferences() {
38
32
  return {
39
33
  cacheSelectionReference: this._cacheSelectionReference,
40
34
  selectionReferences: this._selectionReferences
41
35
  };
42
36
  };
43
-
44
37
  _proto.lookupInStore = function lookupInStore(environment, operation, fetchPolicy) {
45
38
  if (fetchPolicy === 'store-and-network' || fetchPolicy === 'store-or-network') {
46
39
  if (environment.check(operation).status === 'available') {
47
40
  this._retainCachedOperation(environment, operation);
48
-
49
41
  return environment.lookup(operation.fragment);
50
42
  }
51
43
  }
52
-
53
44
  return null;
54
45
  };
55
-
46
+ _proto.getFetchResult = function getFetchResult() {
47
+ if (this._didFetchFinish) {
48
+ // We don't reset '_didFetchFinish' because another callback may be set
49
+ if (this._error != null) {
50
+ return {
51
+ error: this._error
52
+ };
53
+ } else if (this._snapshot != null) {
54
+ return {
55
+ snapshot: this._snapshot
56
+ };
57
+ }
58
+ } else {
59
+ return null;
60
+ }
61
+ };
56
62
  _proto.execute = function execute(_ref) {
57
63
  var _this = this;
58
-
59
64
  var environment = _ref.environment,
60
- operation = _ref.operation,
61
- _ref$preservePrevious = _ref.preservePreviousReferences,
62
- preservePreviousReferences = _ref$preservePrevious === void 0 ? false : _ref$preservePrevious;
65
+ operation = _ref.operation,
66
+ _ref$preservePrevious = _ref.preservePreviousReferences,
67
+ preservePreviousReferences = _ref$preservePrevious === void 0 ? false : _ref$preservePrevious;
63
68
  var reference = environment.retain(operation);
64
-
65
69
  var error = function error() {
66
70
  // We may have partially fulfilled the request, so let the next request
67
71
  // or the unmount dispose of the references.
68
72
  _this._selectionReferences = _this._selectionReferences.concat(reference);
69
73
  };
70
-
71
74
  var complete = function complete() {
72
75
  if (!preservePreviousReferences) {
73
76
  _this.disposeSelectionReferences();
74
77
  }
75
-
76
78
  _this._selectionReferences = _this._selectionReferences.concat(reference);
77
79
  };
78
-
79
80
  var unsubscribe = function unsubscribe() {
80
81
  // Let the next request or the unmount code dispose of the references.
81
82
  // We may have partially fulfilled the request.
82
83
  _this._selectionReferences = _this._selectionReferences.concat(reference);
83
84
  };
84
-
85
85
  if (!isRelayModernEnvironment(environment)) {
86
86
  return environment.execute({
87
87
  operation: operation
@@ -91,26 +91,21 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
91
91
  unsubscribe: unsubscribe
92
92
  });
93
93
  }
94
-
95
94
  return fetchQuery(environment, operation)["do"]({
96
95
  error: error,
97
96
  complete: complete,
98
97
  unsubscribe: unsubscribe
99
98
  });
100
99
  };
101
-
102
100
  _proto.setOnDataChange = function setOnDataChange(onDataChange) {
103
101
  !this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `setOnDataChange` should have been called after having called `fetch`') : invariant(false) : void 0;
104
-
105
102
  if (typeof onDataChange === 'function') {
106
103
  // Mutate the most recent fetchOptions in place,
107
104
  // So that in-progress requests can access the updated callback.
108
105
  this._fetchOptions.onDataChangeCallbacks = this._fetchOptions.onDataChangeCallbacks || [];
109
-
110
106
  this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
111
-
112
- if (this._callOnDataChangeWhenSet) {
113
- // We don't reset '_callOnDataChangeWhenSet' because another callback may be set
107
+ if (this._didFetchFinish) {
108
+ // We don't reset '_didFetchFinish' because another callback may be set
114
109
  if (this._error != null) {
115
110
  onDataChange({
116
111
  error: this._error
@@ -123,6 +118,7 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
123
118
  }
124
119
  }
125
120
  }
121
+
126
122
  /**
127
123
  * `fetch` fetches the data for the given operation.
128
124
  * If a result is immediately available synchronously, it will be synchronously
@@ -131,19 +127,14 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
131
127
  * Otherwise, the fetched result will be communicated via the `onDataChange` callback.
132
128
  * `onDataChange` will be called with the first result (**if it wasn't returned synchronously**),
133
129
  * and then subsequently whenever the data changes.
134
- */
135
- ;
136
-
130
+ */;
137
131
  _proto.fetch = function fetch(fetchOptions, cacheConfigOverride) {
138
132
  var _this2 = this;
139
-
140
133
  var environment = fetchOptions.environment,
141
- operation = fetchOptions.operation,
142
- onDataChange = fetchOptions.onDataChange;
134
+ operation = fetchOptions.operation,
135
+ onDataChange = fetchOptions.onDataChange;
143
136
  var fetchHasReturned = false;
144
-
145
137
  var _error;
146
-
147
138
  this.disposeRequest();
148
139
  var oldOnDataChangeCallbacks = this._fetchOptions && this._fetchOptions.onDataChangeCallbacks;
149
140
  this._fetchOptions = {
@@ -151,12 +142,10 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
151
142
  onDataChangeCallbacks: oldOnDataChangeCallbacks || [],
152
143
  operation: operation
153
144
  };
154
-
155
145
  if (onDataChange && this._fetchOptions.onDataChangeCallbacks.indexOf(onDataChange) === -1) {
156
146
  // $FlowFixMe[incompatible-use]
157
147
  this._fetchOptions.onDataChangeCallbacks.push(onDataChange);
158
148
  }
159
-
160
149
  var operationOverride = cacheConfigOverride ? createOperationDescriptor(operation.request.node, operation.request.variables, cacheConfigOverride) : operation;
161
150
  var request = this.execute({
162
151
  environment: environment,
@@ -167,10 +156,11 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
167
156
  next: function next() {
168
157
  // If we received a response,
169
158
  // Make a note that to notify the callback when it's later added.
170
- _this2._callOnDataChangeWhenSet = true;
171
- _this2._error = null; // Only notify of the first result if `next` is being called **asynchronously**
172
- // (i.e. after `fetch` has returned).
159
+ _this2._didFetchFinish = true;
160
+ _this2._error = null;
173
161
 
162
+ // Only notify of the first result if `next` is being called **asynchronously**
163
+ // (i.e. after `fetch` has returned).
174
164
  _this2._onQueryDataAvailable({
175
165
  notifyFirstResult: fetchHasReturned
176
166
  });
@@ -178,12 +168,13 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
178
168
  error: function error(err) {
179
169
  // If we received a response when we didn't have a change callback,
180
170
  // Make a note that to notify the callback when it's later added.
181
- _this2._callOnDataChangeWhenSet = true;
171
+ _this2._didFetchFinish = true;
182
172
  _this2._error = err;
183
173
  _this2._snapshot = null;
184
- var onDataChangeCallbacks = _this2._fetchOptions && _this2._fetchOptions.onDataChangeCallbacks; // Only notify of error if `error` is being called **asynchronously**
185
- // (i.e. after `fetch` has returned).
174
+ var onDataChangeCallbacks = _this2._fetchOptions && _this2._fetchOptions.onDataChangeCallbacks;
186
175
 
176
+ // Only notify of error if `error` is being called **asynchronously**
177
+ // (i.e. after `fetch` has returned).
187
178
  if (fetchHasReturned) {
188
179
  if (onDataChangeCallbacks) {
189
180
  onDataChangeCallbacks.forEach(function (onDataChange) {
@@ -203,88 +194,73 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
203
194
  }
204
195
  };
205
196
  fetchHasReturned = true;
206
-
207
197
  if (_error) {
208
198
  throw _error;
209
199
  }
210
-
211
200
  return this._snapshot;
212
201
  };
213
-
214
202
  _proto.retry = function retry(cacheConfigOverride) {
215
203
  !this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `retry` should be called after having called `fetch`') : invariant(false) : void 0;
216
204
  return this.fetch({
217
205
  environment: this._fetchOptions.environment,
218
206
  operation: this._fetchOptions.operation,
219
207
  onDataChange: null // If there are onDataChangeCallbacks they will be reused
220
-
221
208
  }, cacheConfigOverride);
222
209
  };
223
-
224
210
  _proto.dispose = function dispose() {
225
211
  this.disposeRequest();
226
212
  this.disposeSelectionReferences();
227
213
  };
228
-
229
214
  _proto.disposeRequest = function disposeRequest() {
230
215
  this._error = null;
231
- this._snapshot = null; // order is important, dispose of pendingFetch before selectionReferences
216
+ this._snapshot = null;
232
217
 
218
+ // order is important, dispose of pendingFetch before selectionReferences
233
219
  if (this._pendingRequest) {
234
220
  this._pendingRequest.dispose();
235
221
  }
236
-
237
222
  if (this._rootSubscription) {
238
223
  this._rootSubscription.dispose();
239
-
240
224
  this._rootSubscription = null;
241
225
  }
242
226
  };
243
-
244
227
  _proto._retainCachedOperation = function _retainCachedOperation(environment, operation) {
245
228
  this._disposeCacheSelectionReference();
246
-
247
229
  this._cacheSelectionReference = environment.retain(operation);
248
230
  };
249
-
250
231
  _proto._disposeCacheSelectionReference = function _disposeCacheSelectionReference() {
251
232
  this._cacheSelectionReference && this._cacheSelectionReference.dispose();
252
233
  this._cacheSelectionReference = null;
253
234
  };
254
-
255
235
  _proto.disposeSelectionReferences = function disposeSelectionReferences() {
256
236
  this._disposeCacheSelectionReference();
257
-
258
237
  this._selectionReferences.forEach(function (r) {
259
238
  return r.dispose();
260
239
  });
261
-
262
240
  this._selectionReferences = [];
263
241
  };
264
-
265
242
  _proto._onQueryDataAvailable = function _onQueryDataAvailable(_ref2) {
266
243
  var _this3 = this;
267
-
268
244
  var notifyFirstResult = _ref2.notifyFirstResult;
269
245
  !this._fetchOptions ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayQueryFetcher: `_onQueryDataAvailable` should have been called after having called `fetch`') : invariant(false) : void 0;
270
246
  var _this$_fetchOptions = this._fetchOptions,
271
- environment = _this$_fetchOptions.environment,
272
- onDataChangeCallbacks = _this$_fetchOptions.onDataChangeCallbacks,
273
- operation = _this$_fetchOptions.operation; // `_onQueryDataAvailable` can be called synchronously the first time and can be called
247
+ environment = _this$_fetchOptions.environment,
248
+ onDataChangeCallbacks = _this$_fetchOptions.onDataChangeCallbacks,
249
+ operation = _this$_fetchOptions.operation;
250
+
251
+ // `_onQueryDataAvailable` can be called synchronously the first time and can be called
274
252
  // multiple times by network layers that support data subscriptions.
275
253
  // Wait until the first payload to call `onDataChange` and subscribe for data updates.
276
-
277
254
  if (this._snapshot) {
278
255
  return;
279
256
  }
257
+ this._snapshot = environment.lookup(operation.fragment);
280
258
 
281
- this._snapshot = environment.lookup(operation.fragment); // Subscribe to changes in the data of the root fragment
282
-
259
+ // Subscribe to changes in the data of the root fragment
283
260
  this._rootSubscription = environment.subscribe(this._snapshot, function (snapshot) {
284
261
  // Read from this._fetchOptions in case onDataChange() was lazily added.
285
262
  if (_this3._fetchOptions != null) {
286
263
  var maybeNewOnDataChangeCallbacks = _this3._fetchOptions.onDataChangeCallbacks;
287
-
288
264
  if (Array.isArray(maybeNewOnDataChangeCallbacks)) {
289
265
  maybeNewOnDataChangeCallbacks.forEach(function (onDataChange) {
290
266
  return onDataChange({
@@ -294,7 +270,6 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
294
270
  }
295
271
  }
296
272
  });
297
-
298
273
  if (this._snapshot && notifyFirstResult && Array.isArray(onDataChangeCallbacks)) {
299
274
  var snapshot = this._snapshot;
300
275
  onDataChangeCallbacks.forEach(function (onDataChange) {
@@ -304,8 +279,6 @@ var ReactRelayQueryFetcher = /*#__PURE__*/function () {
304
279
  });
305
280
  }
306
281
  };
307
-
308
282
  return ReactRelayQueryFetcher;
309
283
  }();
310
-
311
284
  module.exports = ReactRelayQueryFetcher;