1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
14 |
|
15 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
16 |
|
17 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
18 |
|
19 | var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
20 |
|
21 | var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
22 |
|
23 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
24 |
|
25 | var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
26 |
|
27 | var React = require('react');
|
28 |
|
29 | var ReactRelayContext = require('./ReactRelayContext');
|
30 |
|
31 | var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
|
32 |
|
33 | var areEqual = require("fbjs/lib/areEqual");
|
34 |
|
35 | var buildReactRelayContainer = require('./buildReactRelayContainer');
|
36 |
|
37 | var getRootVariablesForFragments = require('./getRootVariablesForFragments');
|
38 |
|
39 | var invariant = require("fbjs/lib/invariant");
|
40 |
|
41 | var warning = require("fbjs/lib/warning");
|
42 |
|
43 | var _require = require('./ReactRelayContainerUtils'),
|
44 | getComponentName = _require.getComponentName,
|
45 | getContainerName = _require.getContainerName;
|
46 |
|
47 | var _require2 = require('./RelayContext'),
|
48 | assertRelayContext = _require2.assertRelayContext;
|
49 |
|
50 | var _require3 = require('relay-runtime'),
|
51 | ConnectionInterface = _require3.ConnectionInterface,
|
52 | Observable = _require3.Observable,
|
53 | createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
54 | createOperationDescriptor = _require3.createOperationDescriptor,
|
55 | getDataIDsFromObject = _require3.getDataIDsFromObject,
|
56 | getRequest = _require3.getRequest,
|
57 | getSelector = _require3.getSelector,
|
58 | getVariablesFromObject = _require3.getVariablesFromObject,
|
59 | isScalarAndEqual = _require3.isScalarAndEqual;
|
60 |
|
61 | var FORWARD = 'forward';
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | function createGetConnectionFromProps(metadata) {
|
195 | var path = metadata.path;
|
196 | !path ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getConnectionFromProps function.') : invariant(false) : void 0;
|
197 | return function (props) {
|
198 | var data = props[metadata.fragmentName];
|
199 |
|
200 | for (var i = 0; i < path.length; i++) {
|
201 | if (!data || typeof data !== 'object') {
|
202 | return null;
|
203 | }
|
204 |
|
205 | data = data[path[i]];
|
206 | }
|
207 |
|
208 | return data;
|
209 | };
|
210 | }
|
211 |
|
212 | function createGetFragmentVariables(metadata) {
|
213 | var countVariable = metadata.count;
|
214 | !countVariable ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getFragmentVariables function.') : invariant(false) : void 0;
|
215 | return function (prevVars, totalCount) {
|
216 | return (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, prevVars), {}, (0, _defineProperty2["default"])({}, countVariable, totalCount));
|
217 | };
|
218 | }
|
219 |
|
220 | function findConnectionMetadata(fragments) {
|
221 | var foundConnectionMetadata = null;
|
222 | var isRelayModern = false;
|
223 |
|
224 | for (var fragmentName in fragments) {
|
225 | var fragment = fragments[fragmentName];
|
226 | var connectionMetadata = fragment.metadata && fragment.metadata.connection;
|
227 |
|
228 |
|
229 |
|
230 | if (fragment.metadata !== undefined) {
|
231 | isRelayModern = true;
|
232 | }
|
233 |
|
234 | if (connectionMetadata) {
|
235 | !(connectionMetadata.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Only a single @connection is ' + 'supported, `%s` has %s.', fragmentName, connectionMetadata.length) : invariant(false) : void 0;
|
236 | !!foundConnectionMetadata ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Only a single fragment with ' + '@connection is supported.') : invariant(false) : void 0;
|
237 | foundConnectionMetadata = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, connectionMetadata[0]), {}, {
|
238 | fragmentName: fragmentName
|
239 | });
|
240 | }
|
241 | }
|
242 |
|
243 | !(!isRelayModern || foundConnectionMetadata !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: A @connection directive must be present.') : invariant(false) : void 0;
|
244 | return foundConnectionMetadata || {};
|
245 | }
|
246 |
|
247 | function toObserver(observerOrCallback) {
|
248 | return typeof observerOrCallback === 'function' ? {
|
249 | error: observerOrCallback,
|
250 | complete: observerOrCallback,
|
251 | unsubscribe: function unsubscribe(subscription) {
|
252 | typeof observerOrCallback === 'function' && observerOrCallback();
|
253 | }
|
254 | } : observerOrCallback || {};
|
255 | }
|
256 |
|
257 | function createContainerWithFragments(Component, fragments, connectionConfig) {
|
258 | var _class, _temp;
|
259 |
|
260 | var componentName = getComponentName(Component);
|
261 | var containerName = getContainerName(Component);
|
262 | var metadata = findConnectionMetadata(fragments);
|
263 | var getConnectionFromProps = connectionConfig.getConnectionFromProps || createGetConnectionFromProps(metadata);
|
264 | var direction = connectionConfig.direction || metadata.direction;
|
265 | !direction ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to infer direction of the ' + 'connection, possibly because both first and last are provided.') : invariant(false) : void 0;
|
266 | var getFragmentVariables = connectionConfig.getFragmentVariables || createGetFragmentVariables(metadata);
|
267 | return _temp = _class = function (_React$Component) {
|
268 | (0, _inheritsLoose2["default"])(_class, _React$Component);
|
269 |
|
270 | function _class(props) {
|
271 | var _this;
|
272 |
|
273 | _this = _React$Component.call(this, props) || this;
|
274 | (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
275 | _this.setState({
|
276 | data: _this._resolver.resolve()
|
277 | });
|
278 | });
|
279 | (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_hasMore", function () {
|
280 | var connectionData = _this._getConnectionData();
|
281 |
|
282 | return !!(connectionData && connectionData.hasMore && connectionData.cursor);
|
283 | });
|
284 | (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_isLoading", function () {
|
285 | return !!_this._refetchSubscription;
|
286 | });
|
287 | (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_refetchConnection", function (totalCount, observerOrCallback, refetchVariables) {
|
288 | if (!_this._canFetchPage('refetchConnection')) {
|
289 | return {
|
290 | dispose: function dispose() {}
|
291 | };
|
292 | }
|
293 |
|
294 | _this._refetchVariables = refetchVariables;
|
295 | var paginatingVariables = {
|
296 | count: totalCount,
|
297 | cursor: null,
|
298 | totalCount: totalCount
|
299 | };
|
300 |
|
301 | var fetch = _this._fetchPage(paginatingVariables, toObserver(observerOrCallback), {
|
302 | force: true
|
303 | });
|
304 |
|
305 | return {
|
306 | dispose: fetch.unsubscribe
|
307 | };
|
308 | });
|
309 | (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_loadMore", function (pageSize, observerOrCallback, options) {
|
310 | if (!_this._canFetchPage('loadMore')) {
|
311 | return {
|
312 | dispose: function dispose() {}
|
313 | };
|
314 | }
|
315 |
|
316 | var observer = toObserver(observerOrCallback);
|
317 |
|
318 | var connectionData = _this._getConnectionData();
|
319 |
|
320 | if (!connectionData) {
|
321 | Observable.create(function (sink) {
|
322 | return sink.complete();
|
323 | }).subscribe(observer);
|
324 | return null;
|
325 | }
|
326 |
|
327 | var totalCount = connectionData.edgeCount + pageSize;
|
328 |
|
329 | if (options && options.force) {
|
330 | return _this._refetchConnection(totalCount, observerOrCallback);
|
331 | }
|
332 |
|
333 | var _ConnectionInterface$ = ConnectionInterface.get(),
|
334 | END_CURSOR = _ConnectionInterface$.END_CURSOR,
|
335 | START_CURSOR = _ConnectionInterface$.START_CURSOR;
|
336 |
|
337 | var cursor = connectionData.cursor;
|
338 | process.env.NODE_ENV !== "production" ? warning(cursor != null && cursor !== '', 'ReactRelayPaginationContainer: Cannot `loadMore` without valid `%s` (got `%s`)', direction === FORWARD ? END_CURSOR : START_CURSOR, cursor) : void 0;
|
339 | var paginatingVariables = {
|
340 | count: pageSize,
|
341 | cursor: cursor,
|
342 | totalCount: totalCount
|
343 | };
|
344 |
|
345 | var fetch = _this._fetchPage(paginatingVariables, observer, options);
|
346 |
|
347 | return {
|
348 | dispose: fetch.unsubscribe
|
349 | };
|
350 | });
|
351 | var relayContext = assertRelayContext(props.__relayContext);
|
352 | _this._isARequestInFlight = false;
|
353 | _this._refetchSubscription = null;
|
354 | _this._refetchVariables = null;
|
355 | _this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, _this._handleFragmentDataUpdate);
|
356 | _this.state = {
|
357 | data: _this._resolver.resolve(),
|
358 | prevContext: relayContext,
|
359 | contextForChildren: relayContext,
|
360 | relayProp: _this._buildRelayProp(relayContext)
|
361 | };
|
362 | _this._isUnmounted = false;
|
363 | _this._hasFetched = false;
|
364 | return _this;
|
365 | }
|
366 | |
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | var _proto = _class.prototype;
|
374 |
|
375 | _proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
376 | var relayContext = assertRelayContext(nextProps.__relayContext);
|
377 | var prevIDs = getDataIDsFromObject(fragments, this.props);
|
378 | var nextIDs = getDataIDsFromObject(fragments, nextProps);
|
379 | var prevRootVariables = getRootVariablesForFragments(fragments, this.props);
|
380 | var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 | if (relayContext.environment !== this.state.prevContext.environment || !areEqual(prevRootVariables, nextRootVariables) || !areEqual(prevIDs, nextIDs)) {
|
387 | this._cleanup();
|
388 |
|
389 |
|
390 | this._resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, this._handleFragmentDataUpdate);
|
391 | this.setState({
|
392 | prevContext: relayContext,
|
393 | contextForChildren: relayContext,
|
394 | relayProp: this._buildRelayProp(relayContext)
|
395 | });
|
396 | } else if (!this._hasFetched) {
|
397 | this._resolver.setProps(nextProps);
|
398 | }
|
399 |
|
400 | var data = this._resolver.resolve();
|
401 |
|
402 | if (data !== this.state.data) {
|
403 | this.setState({
|
404 | data: data
|
405 | });
|
406 | }
|
407 | };
|
408 |
|
409 | _proto.componentWillUnmount = function componentWillUnmount() {
|
410 | this._isUnmounted = true;
|
411 |
|
412 | this._cleanup();
|
413 | };
|
414 |
|
415 | _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
416 |
|
417 | if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp) {
|
418 | return true;
|
419 | }
|
420 |
|
421 |
|
422 |
|
423 | var keys = Object.keys(nextProps);
|
424 |
|
425 | for (var ii = 0; ii < keys.length; ii++) {
|
426 | var _key = keys[ii];
|
427 |
|
428 | if (_key === '__relayContext') {
|
429 | if (nextState.prevContext.environment !== this.state.prevContext.environment) {
|
430 | return true;
|
431 | }
|
432 | } else {
|
433 | if (!fragments.hasOwnProperty(_key) && !isScalarAndEqual(nextProps[_key], this.props[_key])) {
|
434 | return true;
|
435 | }
|
436 | }
|
437 | }
|
438 |
|
439 | return false;
|
440 | };
|
441 |
|
442 | _proto._buildRelayProp = function _buildRelayProp(relayContext) {
|
443 | return {
|
444 | hasMore: this._hasMore,
|
445 | isLoading: this._isLoading,
|
446 | loadMore: this._loadMore,
|
447 | refetchConnection: this._refetchConnection,
|
448 | environment: relayContext.environment
|
449 | };
|
450 | }
|
451 | |
452 |
|
453 |
|
454 | ;
|
455 |
|
456 | _proto._getConnectionData = function _getConnectionData() {
|
457 |
|
458 | var _this$props = this.props,
|
459 | _ = _this$props.componentRef,
|
460 | restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, ["componentRef"]);
|
461 | var props = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, restProps), this.state.data);
|
462 | var connectionData = getConnectionFromProps(props);
|
463 |
|
464 | if (connectionData == null) {
|
465 | return null;
|
466 | }
|
467 |
|
468 | var _ConnectionInterface$2 = ConnectionInterface.get(),
|
469 | EDGES = _ConnectionInterface$2.EDGES,
|
470 | PAGE_INFO = _ConnectionInterface$2.PAGE_INFO,
|
471 | HAS_NEXT_PAGE = _ConnectionInterface$2.HAS_NEXT_PAGE,
|
472 | HAS_PREV_PAGE = _ConnectionInterface$2.HAS_PREV_PAGE,
|
473 | END_CURSOR = _ConnectionInterface$2.END_CURSOR,
|
474 | START_CURSOR = _ConnectionInterface$2.START_CURSOR;
|
475 |
|
476 | !(typeof connectionData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return `null` or a plain object with %s and %s properties, got `%s`.', componentName, EDGES, PAGE_INFO, connectionData) : invariant(false) : void 0;
|
477 | var edges = connectionData[EDGES];
|
478 | var pageInfo = connectionData[PAGE_INFO];
|
479 |
|
480 | if (edges == null || pageInfo == null) {
|
481 | return null;
|
482 | }
|
483 |
|
484 | !Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return an object with %s: Array, got `%s`.', componentName, EDGES, edges) : invariant(false) : void 0;
|
485 | !(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return an object with %s: Object, got `%s`.', componentName, PAGE_INFO, pageInfo) : invariant(false) : void 0;
|
486 | var hasMore = direction === FORWARD ? pageInfo[HAS_NEXT_PAGE] : pageInfo[HAS_PREV_PAGE];
|
487 | var cursor = direction === FORWARD ? pageInfo[END_CURSOR] : pageInfo[START_CURSOR];
|
488 |
|
489 | if (typeof hasMore !== 'boolean' || edges.length !== 0 && typeof cursor === 'undefined') {
|
490 | process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayPaginationContainer: Cannot paginate without %s fields in `%s`. ' + 'Be sure to fetch %s (got `%s`) and %s (got `%s`).', PAGE_INFO, componentName, direction === FORWARD ? HAS_NEXT_PAGE : HAS_PREV_PAGE, hasMore, direction === FORWARD ? END_CURSOR : START_CURSOR, cursor) : void 0;
|
491 | return null;
|
492 | }
|
493 |
|
494 | return {
|
495 | cursor: cursor,
|
496 | edgeCount: edges.length,
|
497 | hasMore: hasMore
|
498 | };
|
499 | };
|
500 |
|
501 | _proto._getQueryFetcher = function _getQueryFetcher() {
|
502 | if (!this._queryFetcher) {
|
503 | this._queryFetcher = new ReactRelayQueryFetcher();
|
504 | }
|
505 |
|
506 | return this._queryFetcher;
|
507 | };
|
508 |
|
509 | _proto._canFetchPage = function _canFetchPage(method) {
|
510 | if (this._isUnmounted) {
|
511 | process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayPaginationContainer: Unexpected call of `%s` ' + 'on unmounted container `%s`. It looks like some instances ' + 'of your container still trying to fetch data but they already ' + 'unmounted. Please make sure you clear all timers, intervals, async ' + 'calls, etc that may trigger `%s` call.', method, containerName, method) : void 0;
|
512 | return false;
|
513 | }
|
514 |
|
515 | return true;
|
516 | };
|
517 |
|
518 | _proto._fetchPage = function _fetchPage(paginatingVariables, observer, options) {
|
519 | var _this2 = this;
|
520 |
|
521 | var _assertRelayContext = assertRelayContext(this.props.__relayContext),
|
522 | environment = _assertRelayContext.environment;
|
523 |
|
524 | var _this$props2 = this.props,
|
525 | _ = _this$props2.componentRef,
|
526 | __relayContext = _this$props2.__relayContext,
|
527 | restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props2, ["componentRef", "__relayContext"]);
|
528 | var props = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, restProps), this.state.data);
|
529 | var fragmentVariables;
|
530 | var rootVariables = getRootVariablesForFragments(fragments, restProps);
|
531 | fragmentVariables = getVariablesFromObject(fragments, restProps);
|
532 | fragmentVariables = (0, _objectSpread3["default"])((0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, rootVariables), fragmentVariables), this._refetchVariables);
|
533 | var fetchVariables = connectionConfig.getVariables(props, {
|
534 | count: paginatingVariables.count,
|
535 | cursor: paginatingVariables.cursor
|
536 | }, fragmentVariables);
|
537 | !(typeof fetchVariables === 'object' && fetchVariables !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getVariables()` to ' + 'return an object, got `%s` in `%s`.', fetchVariables, componentName) : invariant(false) : void 0;
|
538 | fetchVariables = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, fetchVariables), this._refetchVariables);
|
539 | fragmentVariables = (0, _objectSpread3["default"])((0, _objectSpread3["default"])({}, fetchVariables), fragmentVariables);
|
540 | var cacheConfig = options ? {
|
541 | force: !!options.force
|
542 | } : undefined;
|
543 |
|
544 | if (cacheConfig != null && (options === null || options === void 0 ? void 0 : options.metadata) != null) {
|
545 | cacheConfig.metadata = options === null || options === void 0 ? void 0 : options.metadata;
|
546 | }
|
547 |
|
548 | var request = getRequest(connectionConfig.query);
|
549 | var operation = createOperationDescriptor(request, fetchVariables, cacheConfig);
|
550 | var refetchSubscription = null;
|
551 |
|
552 | if (this._refetchSubscription) {
|
553 | this._refetchSubscription.unsubscribe();
|
554 | }
|
555 |
|
556 | this._hasFetched = true;
|
557 |
|
558 | var onNext = function onNext(payload, complete) {
|
559 | var prevData = _this2._resolver.resolve();
|
560 |
|
561 | _this2._resolver.setVariables(getFragmentVariables(fragmentVariables, paginatingVariables.totalCount), operation.request.node);
|
562 |
|
563 | var nextData = _this2._resolver.resolve();
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 | if (!areEqual(prevData, nextData)) {
|
575 | _this2.setState({
|
576 | data: nextData,
|
577 | contextForChildren: {
|
578 | environment: _this2.props.__relayContext.environment
|
579 | }
|
580 | }, complete);
|
581 | } else {
|
582 | complete();
|
583 | }
|
584 | };
|
585 |
|
586 | var cleanup = function cleanup() {
|
587 | if (_this2._refetchSubscription === refetchSubscription) {
|
588 | _this2._refetchSubscription = null;
|
589 | _this2._isARequestInFlight = false;
|
590 | }
|
591 | };
|
592 |
|
593 | this._isARequestInFlight = true;
|
594 | refetchSubscription = this._getQueryFetcher().execute({
|
595 | environment: environment,
|
596 | operation: operation,
|
597 | preservePreviousReferences: true
|
598 | }).mergeMap(function (payload) {
|
599 | return Observable.create(function (sink) {
|
600 | onNext(payload, function () {
|
601 | sink.next();
|
602 |
|
603 | sink.complete();
|
604 | });
|
605 | });
|
606 | })
|
607 | ["do"]({
|
608 | error: cleanup,
|
609 | complete: cleanup,
|
610 | unsubscribe: cleanup
|
611 | }).subscribe(observer || {});
|
612 | this._refetchSubscription = this._isARequestInFlight ? refetchSubscription : null;
|
613 | return refetchSubscription;
|
614 | };
|
615 |
|
616 | _proto._cleanup = function _cleanup() {
|
617 | this._resolver.dispose();
|
618 |
|
619 | this._refetchVariables = null;
|
620 | this._hasFetched = false;
|
621 |
|
622 | if (this._refetchSubscription) {
|
623 | this._refetchSubscription.unsubscribe();
|
624 |
|
625 | this._refetchSubscription = null;
|
626 | this._isARequestInFlight = false;
|
627 | }
|
628 |
|
629 | if (this._queryFetcher) {
|
630 | this._queryFetcher.dispose();
|
631 | }
|
632 | };
|
633 |
|
634 | _proto.render = function render() {
|
635 | var _this$props3 = this.props,
|
636 | componentRef = _this$props3.componentRef,
|
637 | __relayContext = _this$props3.__relayContext,
|
638 | props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props3, ["componentRef", "__relayContext"]);
|
639 | return React.createElement(ReactRelayContext.Provider, {
|
640 | value: this.state.contextForChildren
|
641 | }, React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
642 | ref: componentRef,
|
643 | relay: this.state.relayProp
|
644 | })));
|
645 | };
|
646 |
|
647 | return _class;
|
648 | }(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _temp;
|
649 | }
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 | function createContainer(Component, fragmentSpec, connectionConfig) {
|
660 |
|
661 | return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
|
662 | return createContainerWithFragments(ComponentClass, fragments, connectionConfig);
|
663 | });
|
664 | }
|
665 |
|
666 | module.exports = {
|
667 | createContainer: createContainer
|
668 | }; |
\ | No newline at end of file |