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.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -6,60 +6,49 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
|
-
// flowlint ambiguous-object-type:error
|
11
|
-
'use strict';
|
12
11
|
|
13
|
-
|
12
|
+
'use strict';
|
14
13
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
|
17
16
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
18
|
-
|
19
17
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
20
|
-
|
21
18
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
22
|
-
|
23
19
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
24
|
-
|
20
|
+
var _excluded = ["componentRef", "__relayContext", "__rootIsQueryRenderer"];
|
25
21
|
var buildReactRelayContainer = require('./buildReactRelayContainer');
|
26
|
-
|
27
22
|
var _require = require('./ReactRelayContainerUtils'),
|
28
|
-
|
29
|
-
|
23
|
+
getContainerName = _require.getContainerName;
|
30
24
|
var _require2 = require('./RelayContext'),
|
31
|
-
|
32
|
-
|
25
|
+
assertRelayContext = _require2.assertRelayContext;
|
33
26
|
var areEqual = require("fbjs/lib/areEqual");
|
34
|
-
|
35
27
|
var React = require('react');
|
36
|
-
|
37
28
|
var _require3 = require('relay-runtime'),
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
createFragmentSpecResolver = _require3.createFragmentSpecResolver,
|
30
|
+
getDataIDsFromObject = _require3.getDataIDsFromObject,
|
31
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
42
32
|
/**
|
43
33
|
* Composes a React component class, returning a new class that intercepts
|
44
34
|
* props, resolving them with the provided fragments and subscribing for
|
45
35
|
* updates.
|
46
36
|
*/
|
47
37
|
function createContainerWithFragments(Component, fragments) {
|
48
|
-
var _class
|
49
|
-
|
38
|
+
var _class;
|
50
39
|
var containerName = getContainerName(Component);
|
51
|
-
return
|
40
|
+
return _class = /*#__PURE__*/function (_React$Component) {
|
52
41
|
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
42
|
+
// $FlowFixMe[missing-local-annot]
|
53
43
|
|
54
44
|
function _class(props) {
|
55
45
|
var _props$__rootIsQueryR, _this;
|
56
|
-
|
57
46
|
_this = _React$Component.call(this, props) || this;
|
58
47
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
59
48
|
var resolverFromThisUpdate = _this.state.resolver;
|
60
|
-
|
61
49
|
_this.setState(function (updatedState) {
|
62
|
-
return (
|
50
|
+
return (
|
51
|
+
// If this event belongs to the current data source, update.
|
63
52
|
// Otherwise we should ignore it.
|
64
53
|
resolverFromThisUpdate === updatedState.resolver ? {
|
65
54
|
data: updatedState.resolver.resolve(),
|
@@ -69,11 +58,11 @@ function createContainerWithFragments(Component, fragments) {
|
|
69
58
|
});
|
70
59
|
});
|
71
60
|
var relayContext = assertRelayContext(props.__relayContext);
|
72
|
-
var rootIsQueryRenderer = (_props$__rootIsQueryR = props.__rootIsQueryRenderer) !== null && _props$__rootIsQueryR !== void 0 ? _props$__rootIsQueryR : false;
|
61
|
+
var rootIsQueryRenderer = (_props$__rootIsQueryR = props.__rootIsQueryRenderer) !== null && _props$__rootIsQueryR !== void 0 ? _props$__rootIsQueryR : false;
|
62
|
+
// Do not provide a subscription/callback here.
|
73
63
|
// It is possible for this render to be interrupted or aborted,
|
74
64
|
// In which case the subscription would cause a leak.
|
75
65
|
// We will add the subscription in componentDidMount().
|
76
|
-
|
77
66
|
var resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
|
78
67
|
_this.state = {
|
79
68
|
data: resolver.resolve(),
|
@@ -84,16 +73,14 @@ function createContainerWithFragments(Component, fragments) {
|
|
84
73
|
};
|
85
74
|
return _this;
|
86
75
|
}
|
76
|
+
|
87
77
|
/**
|
88
78
|
* When new props are received, read data for the new props and subscribe
|
89
79
|
* for updates. Props may be the same in which case previous data and
|
90
80
|
* subscriptions can be reused.
|
91
81
|
*/
|
92
|
-
|
93
|
-
|
94
82
|
_class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
95
83
|
var _nextProps$__rootIsQu;
|
96
|
-
|
97
84
|
// Any props change could impact the query, so we mirror props in state.
|
98
85
|
// This is an unusual pattern, but necessary for this container usecase.
|
99
86
|
var prevProps = prevState.prevProps;
|
@@ -101,12 +88,13 @@ function createContainerWithFragments(Component, fragments) {
|
|
101
88
|
var rootIsQueryRenderer = (_nextProps$__rootIsQu = nextProps.__rootIsQueryRenderer) !== null && _nextProps$__rootIsQu !== void 0 ? _nextProps$__rootIsQu : false;
|
102
89
|
var prevIDs = getDataIDsFromObject(fragments, prevProps);
|
103
90
|
var nextIDs = getDataIDsFromObject(fragments, nextProps);
|
104
|
-
var resolver = prevState.resolver;
|
91
|
+
var resolver = prevState.resolver;
|
92
|
+
|
93
|
+
// If the environment has changed or props point to new records then
|
105
94
|
// previously fetched data and any pending fetches no longer apply:
|
106
95
|
// - Existing references are on the old environment.
|
107
96
|
// - Existing references are based on old variables.
|
108
97
|
// - Pending fetches are for the previous records.
|
109
|
-
|
110
98
|
if (prevState.prevPropsContext.environment !== relayContext.environment || !areEqual(prevIDs, nextIDs)) {
|
111
99
|
// Do not provide a subscription/callback here.
|
112
100
|
// It is possible for this render to be interrupted or aborted,
|
@@ -123,7 +111,6 @@ function createContainerWithFragments(Component, fragments) {
|
|
123
111
|
} else {
|
124
112
|
resolver.setProps(nextProps);
|
125
113
|
var data = resolver.resolve();
|
126
|
-
|
127
114
|
if (data !== prevState.data) {
|
128
115
|
return {
|
129
116
|
data: data,
|
@@ -133,114 +120,104 @@ function createContainerWithFragments(Component, fragments) {
|
|
133
120
|
};
|
134
121
|
}
|
135
122
|
}
|
136
|
-
|
137
123
|
return null;
|
138
124
|
};
|
139
|
-
|
140
125
|
var _proto = _class.prototype;
|
141
|
-
|
142
126
|
_proto.componentDidMount = function componentDidMount() {
|
143
127
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
144
128
|
};
|
145
|
-
|
146
129
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
147
130
|
if (this.state.resolver !== prevState.resolver) {
|
148
131
|
prevState.resolver.dispose();
|
149
|
-
|
150
132
|
this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
|
151
133
|
} else {
|
152
134
|
this._rerenderIfStoreHasChanged();
|
153
135
|
}
|
154
136
|
};
|
155
|
-
|
156
137
|
_proto.componentWillUnmount = function componentWillUnmount() {
|
157
138
|
this.state.resolver.dispose();
|
158
139
|
};
|
159
|
-
|
160
140
|
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
|
161
141
|
// Short-circuit if any Relay-related data has changed
|
162
142
|
if (nextState.data !== this.state.data) {
|
163
143
|
return true;
|
164
|
-
}
|
144
|
+
}
|
145
|
+
// Otherwise, for convenience short-circuit if all non-Relay props
|
165
146
|
// are scalar and equal
|
166
|
-
|
167
|
-
|
168
147
|
var keys = Object.keys(nextProps);
|
169
|
-
|
170
148
|
for (var ii = 0; ii < keys.length; ii++) {
|
171
|
-
var
|
172
|
-
|
173
|
-
if (_key === '__relayContext') {
|
149
|
+
var key = keys[ii];
|
150
|
+
if (key === '__relayContext') {
|
174
151
|
if (nextState.prevPropsContext.environment !== this.state.prevPropsContext.environment) {
|
175
152
|
return true;
|
176
153
|
}
|
177
154
|
} else {
|
178
|
-
if (!fragments.hasOwnProperty(
|
155
|
+
if (!fragments.hasOwnProperty(key) && !isScalarAndEqual(nextProps[key], this.props[key])) {
|
179
156
|
return true;
|
180
157
|
}
|
181
158
|
}
|
182
159
|
}
|
183
|
-
|
184
160
|
return false;
|
185
161
|
}
|
162
|
+
|
186
163
|
/**
|
187
164
|
* Render new data for the existing props/context.
|
188
|
-
|
189
|
-
;
|
190
|
-
|
165
|
+
*/;
|
191
166
|
_proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
|
192
167
|
var _this$state = this.state,
|
193
|
-
|
194
|
-
|
168
|
+
data = _this$state.data,
|
169
|
+
resolver = _this$state.resolver;
|
170
|
+
// External values could change between render and commit.
|
195
171
|
// Check for this case, even though it requires an extra store read.
|
196
|
-
|
197
172
|
var maybeNewData = resolver.resolve();
|
198
|
-
|
199
173
|
if (data !== maybeNewData) {
|
200
174
|
this.setState({
|
201
175
|
data: maybeNewData
|
202
176
|
});
|
203
177
|
}
|
204
178
|
};
|
205
|
-
|
206
179
|
_proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
|
207
180
|
var _this$state2 = this.state,
|
208
|
-
|
209
|
-
|
210
|
-
var maybeNewData = resolver.resolve();
|
181
|
+
data = _this$state2.data,
|
182
|
+
resolver = _this$state2.resolver;
|
183
|
+
var maybeNewData = resolver.resolve();
|
184
|
+
|
185
|
+
// Event listeners are only safe to add during the commit phase,
|
211
186
|
// So they won't leak if render is interrupted or errors.
|
187
|
+
resolver.setCallback(this.props, this._handleFragmentDataUpdate);
|
212
188
|
|
213
|
-
|
189
|
+
// External values could change between render and commit.
|
214
190
|
// Check for this case, even though it requires an extra store read.
|
215
|
-
|
216
191
|
if (data !== maybeNewData) {
|
217
192
|
this.setState({
|
218
193
|
data: maybeNewData
|
219
194
|
});
|
220
195
|
}
|
221
|
-
}
|
196
|
+
}
|
222
197
|
|
198
|
+
// $FlowFixMe[missing-local-annot]
|
199
|
+
;
|
223
200
|
_proto.render = function render() {
|
201
|
+
// eslint-disable-next-line no-unused-vars
|
224
202
|
var _this$props = this.props,
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
203
|
+
componentRef = _this$props.componentRef,
|
204
|
+
__relayContext = _this$props.__relayContext,
|
205
|
+
__rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
|
206
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
|
229
207
|
return React.createElement(Component, (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, props), this.state.data), {}, {
|
230
208
|
ref: componentRef,
|
231
209
|
relay: this.state.relayProp
|
232
210
|
}));
|
233
211
|
};
|
234
|
-
|
235
212
|
return _class;
|
236
|
-
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName),
|
213
|
+
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _class;
|
237
214
|
}
|
238
|
-
|
239
215
|
function getRelayProp(environment) {
|
240
216
|
return {
|
241
217
|
environment: environment
|
242
218
|
};
|
243
219
|
}
|
220
|
+
|
244
221
|
/**
|
245
222
|
* Wrap the basic `createContainer()` function with logic to adapt to the
|
246
223
|
* `context.relay.environment` in which it is rendered. Specifically, the
|
@@ -248,13 +225,10 @@ function getRelayProp(environment) {
|
|
248
225
|
* `fragmentSpec` is memoized once per environment, rather than once per
|
249
226
|
* instance of the container constructed/rendered.
|
250
227
|
*/
|
251
|
-
|
252
|
-
|
253
228
|
function createContainer(Component, fragmentSpec) {
|
254
229
|
// $FlowFixMe[incompatible-return]
|
255
230
|
return buildReactRelayContainer(Component, fragmentSpec, createContainerWithFragments);
|
256
231
|
}
|
257
|
-
|
258
232
|
module.exports = {
|
259
233
|
createContainer: createContainer
|
260
234
|
};
|
@@ -6,14 +6,13 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
|
-
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var ReactRelayContext = require('./ReactRelayContext');
|
14
|
-
|
15
15
|
var React = require('react');
|
16
|
-
|
17
16
|
function ReactRelayFragmentMockRenderer(props) {
|
18
17
|
return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
|
19
18
|
value: {
|
@@ -21,5 +20,4 @@ function ReactRelayFragmentMockRenderer(props) {
|
|
21
20
|
}
|
22
21
|
}, props.render());
|
23
22
|
}
|
24
|
-
|
25
23
|
module.exports = ReactRelayFragmentMockRenderer;
|
@@ -6,50 +6,41 @@
|
|
6
6
|
*
|
7
7
|
*
|
8
8
|
* @format
|
9
|
+
* @oncall relay
|
9
10
|
*/
|
10
|
-
|
11
|
+
|
11
12
|
'use strict';
|
12
13
|
|
13
14
|
var ReactRelayContext = require('./ReactRelayContext');
|
14
|
-
|
15
15
|
var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
|
16
|
-
|
17
16
|
var areEqual = require("fbjs/lib/areEqual");
|
18
|
-
|
19
17
|
var React = require('react');
|
20
|
-
|
21
18
|
var _require = require('relay-runtime'),
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
createOperationDescriptor = _require.createOperationDescriptor,
|
20
|
+
deepFreeze = _require.deepFreeze,
|
21
|
+
getRequest = _require.getRequest;
|
26
22
|
var useLayoutEffect = React.useLayoutEffect,
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
useState = React.useState,
|
24
|
+
useRef = React.useRef,
|
25
|
+
useMemo = React.useMemo;
|
30
26
|
var queryRendererContext = {
|
31
27
|
rootIsQueryRenderer: true
|
32
28
|
};
|
33
|
-
|
34
29
|
function useDeepCompare(value) {
|
35
30
|
var latestValue = React.useRef(value);
|
36
|
-
|
37
31
|
if (!areEqual(latestValue.current, value)) {
|
38
32
|
if (process.env.NODE_ENV !== "production") {
|
39
33
|
deepFreeze(value);
|
40
34
|
}
|
41
|
-
|
42
35
|
latestValue.current = value;
|
43
36
|
}
|
44
|
-
|
45
37
|
return latestValue.current;
|
46
38
|
}
|
47
|
-
|
48
39
|
function ReactRelayLocalQueryRenderer(props) {
|
49
40
|
var environment = props.environment,
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
query = props.query,
|
42
|
+
variables = props.variables,
|
43
|
+
render = props.render;
|
53
44
|
var latestVariables = useDeepCompare(variables);
|
54
45
|
var operation = useMemo(function () {
|
55
46
|
var request = getRequest(query);
|
@@ -59,28 +50,27 @@ function ReactRelayLocalQueryRenderer(props) {
|
|
59
50
|
return {
|
60
51
|
environment: environment
|
61
52
|
};
|
62
|
-
}, [environment]);
|
63
|
-
// because of props change
|
53
|
+
}, [environment]);
|
64
54
|
|
55
|
+
// Use a ref to prevent rendering twice when data changes
|
56
|
+
// because of props change
|
65
57
|
var dataRef = useRef(null);
|
66
|
-
|
67
58
|
var _useState = useState(null),
|
68
|
-
|
69
|
-
|
59
|
+
forceUpdate = _useState[1];
|
70
60
|
var cleanupFnRef = useRef(null);
|
71
61
|
var snapshot = useMemo(function () {
|
72
62
|
environment.check(operation);
|
73
63
|
var res = environment.lookup(operation.fragment);
|
74
|
-
dataRef.current = res.data;
|
75
|
-
// and subscribed before the component commits
|
64
|
+
dataRef.current = res.data;
|
76
65
|
|
66
|
+
// Run effects here so that the data can be retained
|
67
|
+
// and subscribed before the component commits
|
77
68
|
var retainDisposable = environment.retain(operation);
|
78
69
|
var subscribeDisposable = environment.subscribe(res, function (newSnapshot) {
|
79
70
|
dataRef.current = newSnapshot.data;
|
80
71
|
forceUpdate(dataRef.current);
|
81
72
|
});
|
82
73
|
var disposed = false;
|
83
|
-
|
84
74
|
function nextCleanupFn() {
|
85
75
|
if (!disposed) {
|
86
76
|
disposed = true;
|
@@ -89,11 +79,9 @@ function ReactRelayLocalQueryRenderer(props) {
|
|
89
79
|
subscribeDisposable.dispose();
|
90
80
|
}
|
91
81
|
}
|
92
|
-
|
93
82
|
if (cleanupFnRef.current) {
|
94
83
|
cleanupFnRef.current();
|
95
84
|
}
|
96
|
-
|
97
85
|
cleanupFnRef.current = nextCleanupFn;
|
98
86
|
return res;
|
99
87
|
}, [environment, operation]);
|
@@ -111,5 +99,4 @@ function ReactRelayLocalQueryRenderer(props) {
|
|
111
99
|
props: dataRef.current
|
112
100
|
})));
|
113
101
|
}
|
114
|
-
|
115
102
|
module.exports = ReactRelayLocalQueryRenderer;
|