react-relay 0.0.0-main-91f84912 → 0.0.0-main-80a4ff5f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactRelayContext.js +1 -1
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/relay-hooks/useMutation.js +6 -14
- package/package.json +2 -2
- package/relay-hooks/useMutation.js.flow +6 -14
package/ReactRelayContext.js
CHANGED
package/hooks.js
CHANGED
package/index.js
CHANGED
package/legacy.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
5
|
-
var useIsMountedRef = require('./useIsMountedRef');
|
|
6
5
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
|
7
6
|
var React = require('react');
|
|
8
7
|
var _require = require('relay-runtime'),
|
|
@@ -14,7 +13,6 @@ var useState = React.useState,
|
|
|
14
13
|
function useMutation(mutation) {
|
|
15
14
|
var commitMutationFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCommitMutation;
|
|
16
15
|
var environment = useRelayEnvironment();
|
|
17
|
-
var isMountedRef = useIsMountedRef();
|
|
18
16
|
var environmentRef = useRef(environment);
|
|
19
17
|
var mutationRef = useRef(mutation);
|
|
20
18
|
var inFlightMutationsRef = useRef(new Set());
|
|
@@ -24,25 +22,19 @@ function useMutation(mutation) {
|
|
|
24
22
|
var cleanup = useCallback(function (disposable) {
|
|
25
23
|
if (environmentRef.current === environment && mutationRef.current === mutation) {
|
|
26
24
|
inFlightMutationsRef.current["delete"](disposable);
|
|
27
|
-
|
|
28
|
-
setMutationInFlight(inFlightMutationsRef.current.size > 0);
|
|
29
|
-
}
|
|
25
|
+
setMutationInFlight(inFlightMutationsRef.current.size > 0);
|
|
30
26
|
}
|
|
31
|
-
}, [environment,
|
|
27
|
+
}, [environment, mutation]);
|
|
32
28
|
useEffect(function () {
|
|
33
29
|
if (environmentRef.current !== environment || mutationRef.current !== mutation) {
|
|
34
30
|
inFlightMutationsRef.current = new Set();
|
|
35
|
-
|
|
36
|
-
setMutationInFlight(false);
|
|
37
|
-
}
|
|
31
|
+
setMutationInFlight(false);
|
|
38
32
|
environmentRef.current = environment;
|
|
39
33
|
mutationRef.current = mutation;
|
|
40
34
|
}
|
|
41
|
-
}, [environment,
|
|
35
|
+
}, [environment, mutation]);
|
|
42
36
|
var commit = useCallback(function (config) {
|
|
43
|
-
|
|
44
|
-
setMutationInFlight(true);
|
|
45
|
-
}
|
|
37
|
+
setMutationInFlight(true);
|
|
46
38
|
var disposable = commitMutationFn(environment, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, config), {}, {
|
|
47
39
|
mutation: mutation,
|
|
48
40
|
onCompleted: function onCompleted(response, errors) {
|
|
@@ -67,7 +59,7 @@ function useMutation(mutation) {
|
|
|
67
59
|
}));
|
|
68
60
|
inFlightMutationsRef.current.add(disposable);
|
|
69
61
|
return disposable;
|
|
70
|
-
}, [cleanup, commitMutationFn, environment,
|
|
62
|
+
}, [cleanup, commitMutationFn, environment, mutation]);
|
|
71
63
|
return [commit, isMutationInFlight];
|
|
72
64
|
}
|
|
73
65
|
module.exports = useMutation;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-relay",
|
|
3
3
|
"description": "A framework for building GraphQL-driven React applications.",
|
|
4
|
-
"version": "0.0.0-main-
|
|
4
|
+
"version": "0.0.0-main-80a4ff5f",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"fbjs": "^3.0.2",
|
|
21
21
|
"invariant": "^2.2.4",
|
|
22
22
|
"nullthrows": "^1.1.1",
|
|
23
|
-
"relay-runtime": "0.0.0-main-
|
|
23
|
+
"relay-runtime": "0.0.0-main-80a4ff5f"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^16.9.0 || ^17 || ^18 || ^19"
|
|
@@ -24,7 +24,6 @@ import type {
|
|
|
24
24
|
Variables,
|
|
25
25
|
} from 'relay-runtime';
|
|
26
26
|
|
|
27
|
-
const useIsMountedRef = require('./useIsMountedRef');
|
|
28
27
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
|
29
28
|
const React = require('react');
|
|
30
29
|
const {commitMutation: defaultCommitMutation} = require('relay-runtime');
|
|
@@ -75,7 +74,6 @@ hook useMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
75
74
|
boolean,
|
|
76
75
|
] {
|
|
77
76
|
const environment = useRelayEnvironment();
|
|
78
|
-
const isMountedRef = useIsMountedRef();
|
|
79
77
|
const environmentRef = useRef(environment);
|
|
80
78
|
const mutationRef = useRef(mutation);
|
|
81
79
|
const inFlightMutationsRef = useRef(new Set<Disposable>());
|
|
@@ -88,12 +86,10 @@ hook useMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
88
86
|
mutationRef.current === mutation
|
|
89
87
|
) {
|
|
90
88
|
inFlightMutationsRef.current.delete(disposable);
|
|
91
|
-
|
|
92
|
-
setMutationInFlight(inFlightMutationsRef.current.size > 0);
|
|
93
|
-
}
|
|
89
|
+
setMutationInFlight(inFlightMutationsRef.current.size > 0);
|
|
94
90
|
}
|
|
95
91
|
},
|
|
96
|
-
[environment,
|
|
92
|
+
[environment, mutation],
|
|
97
93
|
);
|
|
98
94
|
|
|
99
95
|
useEffect(() => {
|
|
@@ -102,19 +98,15 @@ hook useMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
102
98
|
mutationRef.current !== mutation
|
|
103
99
|
) {
|
|
104
100
|
inFlightMutationsRef.current = new Set();
|
|
105
|
-
|
|
106
|
-
setMutationInFlight(false);
|
|
107
|
-
}
|
|
101
|
+
setMutationInFlight(false);
|
|
108
102
|
environmentRef.current = environment;
|
|
109
103
|
mutationRef.current = mutation;
|
|
110
104
|
}
|
|
111
|
-
}, [environment,
|
|
105
|
+
}, [environment, mutation]);
|
|
112
106
|
|
|
113
107
|
const commit = useCallback(
|
|
114
108
|
(config: UseMutationConfigInternal<TVariables, TData, TRawResponse>) => {
|
|
115
|
-
|
|
116
|
-
setMutationInFlight(true);
|
|
117
|
-
}
|
|
109
|
+
setMutationInFlight(true);
|
|
118
110
|
const disposable: Disposable = commitMutationFn(environment, {
|
|
119
111
|
...config,
|
|
120
112
|
mutation,
|
|
@@ -137,7 +129,7 @@ hook useMutation<TVariables: Variables, TData, TRawResponse = {...}>(
|
|
|
137
129
|
inFlightMutationsRef.current.add(disposable);
|
|
138
130
|
return disposable;
|
|
139
131
|
},
|
|
140
|
-
[cleanup, commitMutationFn, environment,
|
|
132
|
+
[cleanup, commitMutationFn, environment, mutation],
|
|
141
133
|
);
|
|
142
134
|
|
|
143
135
|
return [commit, isMutationInFlight];
|