relay-runtime 11.0.0 → 13.0.0-rc.0
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/handlers/RelayDefaultHandlerProvider.js.flow +2 -2
- package/handlers/connection/ConnectionHandler.js.flow +8 -10
- package/handlers/connection/MutationHandlers.js.flow +31 -7
- package/index.js +1 -1
- package/index.js.flow +60 -36
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +8 -8
- package/lib/handlers/connection/MutationHandlers.js +61 -5
- package/lib/index.js +58 -43
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +152 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +419 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +4 -1
- package/lib/mutations/RelayRecordProxy.js +3 -2
- package/lib/mutations/RelayRecordSourceMutator.js +3 -2
- package/lib/mutations/RelayRecordSourceProxy.js +12 -4
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +18 -5
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +14 -10
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +12 -5
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayQueryResponseCache.js +21 -4
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +141 -60
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +532 -195
- package/lib/store/RelayConcreteVariables.js +24 -4
- package/lib/store/RelayModernEnvironment.js +175 -234
- package/lib/store/RelayModernFragmentSpecResolver.js +52 -26
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +47 -12
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +58 -29
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +41 -13
- package/lib/store/RelayReader.js +287 -46
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +55 -31
- package/lib/store/RelayResponseNormalizer.js +250 -108
- package/lib/store/RelayStoreReactFlightUtils.js +8 -12
- package/lib/store/RelayStoreSubscriptions.js +14 -9
- package/lib/store/RelayStoreUtils.js +11 -5
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +61 -0
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +4 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +35 -9
- package/lib/util/RelayConcreteNode.js +4 -0
- package/lib/util/RelayFeatureFlags.js +11 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +0 -6
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getFragmentIdentifier.js +15 -7
- package/lib/util/getOperation.js +2 -1
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +66 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +225 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +506 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +261 -0
- package/multi-actor-environment/index.js.flow +26 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +32 -26
- package/mutations/RelayRecordProxy.js.flow +4 -5
- package/mutations/RelayRecordSourceMutator.js.flow +4 -6
- package/mutations/RelayRecordSourceProxy.js.flow +19 -10
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +22 -7
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -46
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +28 -16
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +34 -20
- package/network/wrapNetworkWithLogObserver.js.flow +100 -0
- package/package.json +3 -2
- package/query/GraphQLTag.js.flow +9 -9
- package/query/PreloadableQueryRegistry.js.flow +2 -1
- package/query/fetchQuery.js.flow +11 -13
- package/query/fetchQueryInternal.js.flow +6 -9
- package/query/fetchQuery_DEPRECATED.js.flow +6 -6
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +14 -3
- package/store/DataChecker.js.flow +162 -67
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +616 -283
- package/store/RelayConcreteVariables.js.flow +27 -5
- package/store/RelayModernEnvironment.js.flow +176 -235
- package/store/RelayModernFragmentSpecResolver.js.flow +55 -31
- package/store/RelayModernOperationDescriptor.js.flow +12 -7
- package/store/RelayModernRecord.js.flow +67 -11
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +72 -36
- package/store/RelayOperationTracker.js.flow +59 -43
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +79 -34
- package/store/RelayReader.js.flow +351 -72
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +60 -33
- package/store/RelayResponseNormalizer.js.flow +288 -102
- package/store/RelayStoreReactFlightUtils.js.flow +9 -13
- package/store/RelayStoreSubscriptions.js.flow +19 -11
- package/store/RelayStoreTypes.js.flow +210 -44
- package/store/RelayStoreUtils.js.flow +25 -11
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +121 -0
- package/store/StoreInspector.js.flow +2 -2
- package/store/TypeID.js.flow +1 -1
- package/store/ViewerPattern.js.flow +2 -2
- package/store/cloneRelayHandleSourceField.js.flow +5 -6
- package/store/cloneRelayScalarHandleSourceField.js.flow +5 -6
- package/store/createFragmentSpecResolver.js.flow +3 -4
- package/store/createRelayContext.js.flow +3 -3
- package/store/defaultGetDataID.js.flow +3 -1
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +54 -27
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +38 -2
- package/util/RelayConcreteNode.js.flow +4 -0
- package/util/RelayFeatureFlags.js.flow +24 -8
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +9 -9
- package/util/RelayRuntimeTypes.js.flow +73 -4
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/deepFreeze.js.flow +2 -1
- package/util/getFragmentIdentifier.js.flow +27 -15
- package/util/getOperation.js.flow +2 -2
- package/util/getPaginationMetadata.js.flow +72 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +79 -0
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/resolveImmediate.js.flow +1 -1
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+relay
|
|
8
|
+
* @flow strict-local
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// flowlint ambiguous-object-type:error
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const invariant = require('invariant');
|
|
17
|
+
|
|
18
|
+
function getValueAtPath(
|
|
19
|
+
data: mixed,
|
|
20
|
+
path: $ReadOnlyArray<string | number>,
|
|
21
|
+
): mixed {
|
|
22
|
+
let result = data;
|
|
23
|
+
for (const key of path) {
|
|
24
|
+
if (result == null) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (typeof key === 'number') {
|
|
28
|
+
invariant(
|
|
29
|
+
Array.isArray(result),
|
|
30
|
+
'Relay: Expected an array when extracting value at path. ' +
|
|
31
|
+
"If you're seeing this, this is likely a bug in Relay.",
|
|
32
|
+
);
|
|
33
|
+
result = result[key];
|
|
34
|
+
} else {
|
|
35
|
+
invariant(
|
|
36
|
+
typeof result === 'object' && !Array.isArray(result),
|
|
37
|
+
'Relay: Expected an object when extracting value at path. ' +
|
|
38
|
+
"If you're seeing this, this is likely a bug in Relay.",
|
|
39
|
+
);
|
|
40
|
+
result = result[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = getValueAtPath;
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
14
15
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
15
16
|
|
|
16
|
-
function isEmptyObject(obj: {+[key: string]: mixed}): boolean {
|
|
17
|
+
function isEmptyObject(obj: interface {+[key: string]: mixed}): boolean {
|
|
17
18
|
for (const key in obj) {
|
|
18
19
|
if (hasOwnProperty.call(obj, key)) {
|
|
19
20
|
return false;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// flowlint ambiguous-object-type:error
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
import type {IEnvironment} from '../store/RelayStoreTypes';
|
|
17
|
+
|
|
18
|
+
function registerEnvironmentWithDevTools(environment: IEnvironment): void {
|
|
19
|
+
// Register this Relay Environment with Relay DevTools if it exists.
|
|
20
|
+
// Note: this must always be the last step in the constructor.
|
|
21
|
+
const _global =
|
|
22
|
+
typeof global !== 'undefined'
|
|
23
|
+
? global
|
|
24
|
+
: typeof window !== 'undefined'
|
|
25
|
+
? window
|
|
26
|
+
: undefined;
|
|
27
|
+
const devToolsHook = _global && _global.__RELAY_DEVTOOLS_HOOK__;
|
|
28
|
+
if (devToolsHook) {
|
|
29
|
+
devToolsHook.registerEnvironment(environment);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = registerEnvironmentWithDevTools;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const isPerformanceNowAvailable =
|
|
16
|
+
typeof window !== 'undefined' &&
|
|
17
|
+
typeof window?.performance?.now === 'function';
|
|
18
|
+
|
|
19
|
+
function currentTimestamp(): number {
|
|
20
|
+
if (isPerformanceNowAvailable) {
|
|
21
|
+
return window.performance.now();
|
|
22
|
+
}
|
|
23
|
+
return Date.now();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function withDuration<T>(cb: () => T): [number, T] {
|
|
27
|
+
const startTime = currentTimestamp();
|
|
28
|
+
const result = cb();
|
|
29
|
+
return [currentTimestamp() - startTime, result];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = withDuration;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
// flowlint ambiguous-object-type:error
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
-
|
|
15
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
16
|
-
|
|
17
|
-
var RelayRecordState = require('./RelayRecordState');
|
|
18
|
-
|
|
19
|
-
var EXISTENT = RelayRecordState.EXISTENT,
|
|
20
|
-
NONEXISTENT = RelayRecordState.NONEXISTENT,
|
|
21
|
-
UNKNOWN = RelayRecordState.UNKNOWN;
|
|
22
|
-
/**
|
|
23
|
-
* An implementation of the `MutableRecordSource` interface (defined in
|
|
24
|
-
* `RelayStoreTypes`) that holds all records in memory (JS Map).
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
var RelayMapRecordSourceMapImpl = /*#__PURE__*/function () {
|
|
28
|
-
function RelayMapRecordSourceMapImpl(records) {
|
|
29
|
-
var _this = this;
|
|
30
|
-
|
|
31
|
-
this._records = new Map();
|
|
32
|
-
|
|
33
|
-
if (records != null) {
|
|
34
|
-
Object.keys(records).forEach(function (key) {
|
|
35
|
-
_this._records.set(key, records[key]);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var _proto = RelayMapRecordSourceMapImpl.prototype;
|
|
41
|
-
|
|
42
|
-
_proto.clear = function clear() {
|
|
43
|
-
this._records = new Map();
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
_proto["delete"] = function _delete(dataID) {
|
|
47
|
-
this._records.set(dataID, null);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
_proto.get = function get(dataID) {
|
|
51
|
-
return this._records.get(dataID);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
_proto.getRecordIDs = function getRecordIDs() {
|
|
55
|
-
return Array.from(this._records.keys());
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
_proto.getStatus = function getStatus(dataID) {
|
|
59
|
-
if (!this._records.has(dataID)) {
|
|
60
|
-
return UNKNOWN;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
_proto.has = function has(dataID) {
|
|
67
|
-
return this._records.has(dataID);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
_proto.remove = function remove(dataID) {
|
|
71
|
-
this._records["delete"](dataID);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
_proto.set = function set(dataID, record) {
|
|
75
|
-
this._records.set(dataID, record);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
_proto.size = function size() {
|
|
79
|
-
return this._records.size;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
_proto.toJSON = function toJSON() {
|
|
83
|
-
var obj = {};
|
|
84
|
-
|
|
85
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(this._records),
|
|
86
|
-
_step;
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
90
|
-
var _step$value = _step.value,
|
|
91
|
-
key = _step$value[0],
|
|
92
|
-
value = _step$value[1];
|
|
93
|
-
obj[key] = value;
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
_iterator.e(err);
|
|
97
|
-
} finally {
|
|
98
|
-
_iterator.f();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return obj;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return RelayMapRecordSourceMapImpl;
|
|
105
|
-
}();
|
|
106
|
-
|
|
107
|
-
module.exports = RelayMapRecordSourceMapImpl;
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
// flowlint ambiguous-object-type:error
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
|
-
|
|
15
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
16
|
-
|
|
17
|
-
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
18
|
-
|
|
19
|
-
var RelayReader = require('./RelayReader');
|
|
20
|
-
|
|
21
|
-
var deepFreeze = require('../util/deepFreeze');
|
|
22
|
-
|
|
23
|
-
var recycleNodesInto = require('../util/recycleNodesInto');
|
|
24
|
-
|
|
25
|
-
var RelayStoreSubscriptionsUsingMapByID = /*#__PURE__*/function () {
|
|
26
|
-
function RelayStoreSubscriptionsUsingMapByID(log) {
|
|
27
|
-
this._notifiedRevision = 0;
|
|
28
|
-
this._snapshotRevision = 0;
|
|
29
|
-
this._subscriptionsByDataId = new Map();
|
|
30
|
-
this._staleSubscriptions = new Set();
|
|
31
|
-
this.__log = log;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var _proto = RelayStoreSubscriptionsUsingMapByID.prototype;
|
|
35
|
-
|
|
36
|
-
_proto.subscribe = function subscribe(snapshot, callback) {
|
|
37
|
-
var _this = this;
|
|
38
|
-
|
|
39
|
-
var subscription = {
|
|
40
|
-
backup: null,
|
|
41
|
-
callback: callback,
|
|
42
|
-
notifiedRevision: this._notifiedRevision,
|
|
43
|
-
snapshotRevision: this._snapshotRevision,
|
|
44
|
-
snapshot: snapshot
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
var dispose = function dispose() {
|
|
48
|
-
var _iterator = (0, _createForOfIteratorHelper2["default"])(snapshot.seenRecords),
|
|
49
|
-
_step;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
-
var dataId = _step.value;
|
|
54
|
-
|
|
55
|
-
var subscriptionsForDataId = _this._subscriptionsByDataId.get(dataId);
|
|
56
|
-
|
|
57
|
-
if (subscriptionsForDataId != null) {
|
|
58
|
-
subscriptionsForDataId["delete"](subscription);
|
|
59
|
-
|
|
60
|
-
if (subscriptionsForDataId.size === 0) {
|
|
61
|
-
_this._subscriptionsByDataId["delete"](dataId);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
} catch (err) {
|
|
66
|
-
_iterator.e(err);
|
|
67
|
-
} finally {
|
|
68
|
-
_iterator.f();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(snapshot.seenRecords),
|
|
73
|
-
_step2;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
77
|
-
var dataId = _step2.value;
|
|
78
|
-
|
|
79
|
-
var subscriptionsForDataId = this._subscriptionsByDataId.get(dataId);
|
|
80
|
-
|
|
81
|
-
if (subscriptionsForDataId != null) {
|
|
82
|
-
subscriptionsForDataId.add(subscription);
|
|
83
|
-
} else {
|
|
84
|
-
this._subscriptionsByDataId.set(dataId, new Set([subscription]));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
} catch (err) {
|
|
88
|
-
_iterator2.e(err);
|
|
89
|
-
} finally {
|
|
90
|
-
_iterator2.f();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
dispose: dispose
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
_proto.snapshotSubscriptions = function snapshotSubscriptions(source) {
|
|
99
|
-
var _this2 = this;
|
|
100
|
-
|
|
101
|
-
this._snapshotRevision++;
|
|
102
|
-
|
|
103
|
-
this._subscriptionsByDataId.forEach(function (subscriptions) {
|
|
104
|
-
subscriptions.forEach(function (subscription) {
|
|
105
|
-
if (subscription.snapshotRevision === _this2._snapshotRevision) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
subscription.snapshotRevision = _this2._snapshotRevision; // Backup occurs after writing a new "final" payload(s) and before (re)applying
|
|
110
|
-
// optimistic changes. Each subscription's `snapshot` represents what was *last
|
|
111
|
-
// published to the subscriber*, which notably may include previous optimistic
|
|
112
|
-
// updates. Therefore a subscription can be in any of the following states:
|
|
113
|
-
// - stale=true: This subscription was restored to a different value than
|
|
114
|
-
// `snapshot`. That means this subscription has changes relative to its base,
|
|
115
|
-
// but its base has changed (we just applied a final payload): recompute
|
|
116
|
-
// a backup so that we can later restore to the state the subscription
|
|
117
|
-
// should be in.
|
|
118
|
-
// - stale=false: This subscription was restored to the same value than
|
|
119
|
-
// `snapshot`. That means this subscription does *not* have changes relative
|
|
120
|
-
// to its base, so the current `snapshot` is valid to use as a backup.
|
|
121
|
-
|
|
122
|
-
if (!_this2._staleSubscriptions.has(subscription)) {
|
|
123
|
-
subscription.backup = subscription.snapshot;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
var snapshot = subscription.snapshot;
|
|
128
|
-
var backup = RelayReader.read(source, snapshot.selector);
|
|
129
|
-
var nextData = recycleNodesInto(snapshot.data, backup.data);
|
|
130
|
-
backup.data = nextData; // backup owns the snapshot and can safely mutate
|
|
131
|
-
|
|
132
|
-
subscription.backup = backup;
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
_proto.restoreSubscriptions = function restoreSubscriptions() {
|
|
138
|
-
var _this3 = this;
|
|
139
|
-
|
|
140
|
-
this._snapshotRevision++;
|
|
141
|
-
|
|
142
|
-
this._subscriptionsByDataId.forEach(function (subscriptions) {
|
|
143
|
-
subscriptions.forEach(function (subscription) {
|
|
144
|
-
if (subscription.snapshotRevision === _this3._snapshotRevision) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
subscription.snapshotRevision = _this3._snapshotRevision;
|
|
149
|
-
var backup = subscription.backup;
|
|
150
|
-
subscription.backup = null;
|
|
151
|
-
|
|
152
|
-
if (backup) {
|
|
153
|
-
if (backup.data !== subscription.snapshot.data) {
|
|
154
|
-
_this3._staleSubscriptions.add(subscription);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
var prevSeenRecords = subscription.snapshot.seenRecords;
|
|
158
|
-
subscription.snapshot = {
|
|
159
|
-
data: subscription.snapshot.data,
|
|
160
|
-
isMissingData: backup.isMissingData,
|
|
161
|
-
seenRecords: backup.seenRecords,
|
|
162
|
-
selector: backup.selector,
|
|
163
|
-
missingRequiredFields: backup.missingRequiredFields
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
_this3._updateSubscriptionsMap(subscription, prevSeenRecords);
|
|
167
|
-
} else {
|
|
168
|
-
_this3._staleSubscriptions.add(subscription);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
_proto.updateSubscriptions = function updateSubscriptions(source, updatedRecordIDs, updatedOwners, sourceOperation) {
|
|
175
|
-
var _this4 = this;
|
|
176
|
-
|
|
177
|
-
this._notifiedRevision++;
|
|
178
|
-
updatedRecordIDs.forEach(function (updatedRecordId) {
|
|
179
|
-
var subcriptionsForDataId = _this4._subscriptionsByDataId.get(updatedRecordId);
|
|
180
|
-
|
|
181
|
-
if (subcriptionsForDataId == null) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
subcriptionsForDataId.forEach(function (subscription) {
|
|
186
|
-
if (subscription.notifiedRevision === _this4._notifiedRevision) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
var owner = _this4._updateSubscription(source, subscription, false, sourceOperation);
|
|
191
|
-
|
|
192
|
-
if (owner != null) {
|
|
193
|
-
updatedOwners.push(owner);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
this._staleSubscriptions.forEach(function (subscription) {
|
|
199
|
-
if (subscription.notifiedRevision === _this4._notifiedRevision) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
var owner = _this4._updateSubscription(source, subscription, true, sourceOperation);
|
|
204
|
-
|
|
205
|
-
if (owner != null) {
|
|
206
|
-
updatedOwners.push(owner);
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
this._staleSubscriptions.clear();
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Notifies the callback for the subscription if the data for the associated
|
|
214
|
-
* snapshot has changed.
|
|
215
|
-
* Additionally, updates the subscription snapshot with the latest snapshot,
|
|
216
|
-
* amarks it as not stale, and updates the subscription tracking for any
|
|
217
|
-
* any new ids observed in the latest data snapshot.
|
|
218
|
-
* Returns the owner (RequestDescriptor) if the subscription was affected by the
|
|
219
|
-
* latest update, or null if it was not affected.
|
|
220
|
-
*/
|
|
221
|
-
;
|
|
222
|
-
|
|
223
|
-
_proto._updateSubscription = function _updateSubscription(source, subscription, stale, sourceOperation) {
|
|
224
|
-
var backup = subscription.backup,
|
|
225
|
-
callback = subscription.callback,
|
|
226
|
-
snapshot = subscription.snapshot;
|
|
227
|
-
var nextSnapshot = stale && backup != null ? backup : RelayReader.read(source, snapshot.selector);
|
|
228
|
-
var nextData = recycleNodesInto(snapshot.data, nextSnapshot.data);
|
|
229
|
-
nextSnapshot = {
|
|
230
|
-
data: nextData,
|
|
231
|
-
isMissingData: nextSnapshot.isMissingData,
|
|
232
|
-
seenRecords: nextSnapshot.seenRecords,
|
|
233
|
-
selector: nextSnapshot.selector,
|
|
234
|
-
missingRequiredFields: nextSnapshot.missingRequiredFields
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
if (process.env.NODE_ENV !== "production") {
|
|
238
|
-
deepFreeze(nextSnapshot);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
var prevSeenRecords = subscription.snapshot.seenRecords;
|
|
242
|
-
subscription.snapshot = nextSnapshot;
|
|
243
|
-
subscription.notifiedRevision = this._notifiedRevision;
|
|
244
|
-
|
|
245
|
-
this._updateSubscriptionsMap(subscription, prevSeenRecords);
|
|
246
|
-
|
|
247
|
-
if (nextSnapshot.data !== snapshot.data) {
|
|
248
|
-
if (this.__log && RelayFeatureFlags.ENABLE_NOTIFY_SUBSCRIPTION) {
|
|
249
|
-
this.__log({
|
|
250
|
-
name: 'store.notify.subscription',
|
|
251
|
-
sourceOperation: sourceOperation,
|
|
252
|
-
snapshot: snapshot,
|
|
253
|
-
nextSnapshot: nextSnapshot
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
callback(nextSnapshot);
|
|
258
|
-
return snapshot.selector.owner;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Updates the Map that tracks subscriptions by id.
|
|
263
|
-
* Given an updated subscription and the records that where seen
|
|
264
|
-
* on the previous subscription snapshot, updates our tracking
|
|
265
|
-
* to track the subscription for the newly and no longer seen ids.
|
|
266
|
-
*/
|
|
267
|
-
;
|
|
268
|
-
|
|
269
|
-
_proto._updateSubscriptionsMap = function _updateSubscriptionsMap(subscription, prevSeenRecords) {
|
|
270
|
-
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(prevSeenRecords),
|
|
271
|
-
_step3;
|
|
272
|
-
|
|
273
|
-
try {
|
|
274
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
275
|
-
var dataId = _step3.value;
|
|
276
|
-
|
|
277
|
-
var subscriptionsForDataId = this._subscriptionsByDataId.get(dataId);
|
|
278
|
-
|
|
279
|
-
if (subscriptionsForDataId != null) {
|
|
280
|
-
subscriptionsForDataId["delete"](subscription);
|
|
281
|
-
|
|
282
|
-
if (subscriptionsForDataId.size === 0) {
|
|
283
|
-
this._subscriptionsByDataId["delete"](dataId);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
} catch (err) {
|
|
288
|
-
_iterator3.e(err);
|
|
289
|
-
} finally {
|
|
290
|
-
_iterator3.f();
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
var _iterator4 = (0, _createForOfIteratorHelper2["default"])(subscription.snapshot.seenRecords),
|
|
294
|
-
_step4;
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
298
|
-
var _dataId = _step4.value;
|
|
299
|
-
|
|
300
|
-
var _subscriptionsForDataId = this._subscriptionsByDataId.get(_dataId);
|
|
301
|
-
|
|
302
|
-
if (_subscriptionsForDataId != null) {
|
|
303
|
-
_subscriptionsForDataId.add(subscription);
|
|
304
|
-
} else {
|
|
305
|
-
this._subscriptionsByDataId.set(_dataId, new Set([subscription]));
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
} catch (err) {
|
|
309
|
-
_iterator4.e(err);
|
|
310
|
-
} finally {
|
|
311
|
-
_iterator4.f();
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
return RelayStoreSubscriptionsUsingMapByID;
|
|
316
|
-
}();
|
|
317
|
-
|
|
318
|
-
module.exports = RelayStoreSubscriptionsUsingMapByID;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// flowlint ambiguous-object-type:error
|
|
12
|
-
|
|
13
|
-
'use strict';
|
|
14
|
-
|
|
15
|
-
const RelayRecordState = require('./RelayRecordState');
|
|
16
|
-
|
|
17
|
-
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
18
|
-
import type {RecordState} from './RelayRecordState';
|
|
19
|
-
import type {
|
|
20
|
-
MutableRecordSource,
|
|
21
|
-
Record,
|
|
22
|
-
RecordObjectMap,
|
|
23
|
-
} from './RelayStoreTypes';
|
|
24
|
-
|
|
25
|
-
const {EXISTENT, NONEXISTENT, UNKNOWN} = RelayRecordState;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* An implementation of the `MutableRecordSource` interface (defined in
|
|
29
|
-
* `RelayStoreTypes`) that holds all records in memory (JS Map).
|
|
30
|
-
*/
|
|
31
|
-
class RelayMapRecordSourceMapImpl implements MutableRecordSource {
|
|
32
|
-
_records: Map<DataID, ?Record>;
|
|
33
|
-
|
|
34
|
-
constructor(records?: RecordObjectMap) {
|
|
35
|
-
this._records = new Map();
|
|
36
|
-
if (records != null) {
|
|
37
|
-
Object.keys(records).forEach(key => {
|
|
38
|
-
this._records.set(key, records[key]);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
clear(): void {
|
|
44
|
-
this._records = new Map();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
delete(dataID: DataID): void {
|
|
48
|
-
this._records.set(dataID, null);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get(dataID: DataID): ?Record {
|
|
52
|
-
return this._records.get(dataID);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getRecordIDs(): Array<DataID> {
|
|
56
|
-
return Array.from(this._records.keys());
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getStatus(dataID: DataID): RecordState {
|
|
60
|
-
if (!this._records.has(dataID)) {
|
|
61
|
-
return UNKNOWN;
|
|
62
|
-
}
|
|
63
|
-
return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
has(dataID: DataID): boolean {
|
|
67
|
-
return this._records.has(dataID);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
remove(dataID: DataID): void {
|
|
71
|
-
this._records.delete(dataID);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
set(dataID: DataID, record: Record): void {
|
|
75
|
-
this._records.set(dataID, record);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
size(): number {
|
|
79
|
-
return this._records.size;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
toJSON(): {[DataID]: ?Record, ...} {
|
|
83
|
-
const obj = {};
|
|
84
|
-
for (const [key, value] of this._records) {
|
|
85
|
-
obj[key] = value;
|
|
86
|
-
}
|
|
87
|
-
return obj;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = RelayMapRecordSourceMapImpl;
|