relay-runtime 0.0.0-main-d543a7a5 → 0.0.0-main-88093de0
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/index.js +1 -1
- package/lib/util/withProvidedVariables.js +23 -1
- package/package.json +1 -1
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/util/withProvidedVariables.js.flow +30 -1
package/index.js
CHANGED
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
var areEqual = require("fbjs/lib/areEqual");
|
|
15
|
+
|
|
16
|
+
var warning = require("fbjs/lib/warning");
|
|
17
|
+
|
|
18
|
+
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
19
|
+
var debugCache = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
|
20
|
+
|
|
14
21
|
function withProvidedVariables(userSuppliedVariables, parameters) {
|
|
15
22
|
var providedVariables = parameters.providedVariables;
|
|
16
23
|
|
|
@@ -18,7 +25,22 @@ function withProvidedVariables(userSuppliedVariables, parameters) {
|
|
|
18
25
|
var operationVariables = {};
|
|
19
26
|
Object.assign(operationVariables, userSuppliedVariables);
|
|
20
27
|
Object.keys(providedVariables).forEach(function (varName) {
|
|
21
|
-
|
|
28
|
+
var providerFunction = providedVariables[varName].get;
|
|
29
|
+
var providerResult = providerFunction(); // people like to ignore these warnings, so use the cache to
|
|
30
|
+
// enforce that we only compute the value the first time
|
|
31
|
+
|
|
32
|
+
if (!debugCache.has(providerFunction)) {
|
|
33
|
+
debugCache.set(providerFunction, providerResult);
|
|
34
|
+
operationVariables[varName] = providerResult;
|
|
35
|
+
} else {
|
|
36
|
+
var cachedResult = debugCache.get(providerFunction);
|
|
37
|
+
|
|
38
|
+
if (process.env.NODE_ENV !== "production") {
|
|
39
|
+
process.env.NODE_ENV !== "production" ? warning(areEqual(providerResult, cachedResult), 'Relay: Expected function `%s` for provider `%s` to be a pure function, ' + 'but got conflicting return values `%s` and `%s`', providerFunction.name, varName, providerResult, cachedResult) : void 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
operationVariables[varName] = cachedResult;
|
|
43
|
+
}
|
|
22
44
|
});
|
|
23
45
|
return operationVariables;
|
|
24
46
|
} else {
|