relay-runtime 1.7.0-rc.1 → 2.0.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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/index.js +1 -1
  3. package/lib/ConvertToExecuteFunction.js +12 -75
  4. package/lib/DataChecker.js +400 -0
  5. package/lib/NormalizationNode.js +14 -0
  6. package/lib/ReaderNode.js +10 -0
  7. package/lib/RelayCombinedEnvironmentTypes.js +10 -0
  8. package/lib/RelayConcreteNode.js +12 -29
  9. package/lib/RelayConcreteVariables.js +17 -11
  10. package/lib/RelayConnectionHandler.js +98 -42
  11. package/lib/RelayConnectionInterface.js +5 -13
  12. package/lib/RelayCore.js +17 -14
  13. package/lib/RelayDeclarativeMutationConfig.js +69 -34
  14. package/lib/RelayDefaultHandleKey.js +1 -2
  15. package/lib/RelayDefaultHandlerProvider.js +6 -5
  16. package/lib/RelayError.js +6 -9
  17. package/lib/RelayInMemoryRecordSource.js +20 -22
  18. package/lib/RelayModernEnvironment.js +140 -229
  19. package/lib/RelayModernFragmentSpecResolver.js +110 -102
  20. package/lib/RelayModernGraphQLTag.js +53 -15
  21. package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
  22. package/lib/RelayModernQueryExecutor.js +172 -0
  23. package/lib/RelayModernRecord.js +97 -38
  24. package/lib/RelayModernSelector.js +89 -33
  25. package/lib/RelayModernStore.js +301 -0
  26. package/lib/RelayNetwork.js +16 -28
  27. package/lib/RelayNetworkLogger.js +2 -3
  28. package/lib/RelayNetworkLoggerTransaction.js +32 -30
  29. package/lib/RelayNetworkTypes.js +1 -2
  30. package/lib/RelayObservable.js +127 -155
  31. package/lib/RelayProfiler.js +35 -22
  32. package/lib/RelayPublishQueue.js +144 -96
  33. package/lib/RelayQueryResponseCache.js +37 -21
  34. package/lib/RelayReader.js +194 -61
  35. package/lib/RelayRecordProxy.js +50 -31
  36. package/lib/RelayRecordSourceMutator.js +92 -51
  37. package/lib/RelayRecordSourceProxy.js +43 -35
  38. package/lib/RelayRecordSourceSelectorProxy.js +22 -21
  39. package/lib/RelayRecordState.js +1 -3
  40. package/lib/RelayReferenceMarker.js +110 -37
  41. package/lib/RelayResponseNormalizer.js +248 -82
  42. package/lib/RelayRuntimeTypes.js +1 -3
  43. package/lib/RelayStoreTypes.js +1 -2
  44. package/lib/RelayStoreUtils.js +37 -19
  45. package/lib/RelayViewerHandler.js +14 -10
  46. package/lib/applyRelayModernOptimisticMutation.js +8 -8
  47. package/lib/cloneRelayHandleSourceField.js +8 -9
  48. package/lib/commitLocalUpdate.js +1 -2
  49. package/lib/commitRelayModernMutation.js +21 -14
  50. package/lib/createRelayNetworkLogger.js +11 -9
  51. package/lib/deepFreeze.js +2 -3
  52. package/lib/fetchRelayModernQuery.js +10 -12
  53. package/lib/generateRelayClientID.js +4 -2
  54. package/lib/getRelayHandleKey.js +5 -6
  55. package/lib/hasOverlappingIDs.js +3 -2
  56. package/lib/index.js +59 -62
  57. package/lib/isPromise.js +1 -2
  58. package/lib/isRelayModernEnvironment.js +1 -3
  59. package/lib/isScalarAndEqual.js +1 -3
  60. package/lib/normalizePayload.js +17 -15
  61. package/lib/normalizeRelayPayload.js +9 -9
  62. package/lib/recycleNodesInto.js +25 -9
  63. package/lib/requestRelaySubscription.js +25 -58
  64. package/lib/simpleClone.js +2 -3
  65. package/lib/stableCopy.js +5 -3
  66. package/lib/validateMutation.js +146 -0
  67. package/package.json +3 -3
  68. package/relay-runtime.js +4 -0
  69. package/relay-runtime.min.js +9 -0
  70. package/lib/RelayDataLoader.js +0 -302
  71. package/lib/RelayMarkSweepStore.js +0 -242
  72. package/lib/deferrableFragmentKey.js +0 -20
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  var aggregateHandlersByName = {
@@ -16,16 +15,18 @@ var aggregateHandlersByName = {
16
15
  var profileHandlersByName = {
17
16
  '*': []
18
17
  };
19
-
20
18
  var NOT_INVOKED = {};
21
- var defaultProfiler = { stop: require('fbjs/lib/emptyFunction') };
19
+ var defaultProfiler = {
20
+ stop: require("fbjs/lib/emptyFunction")
21
+ };
22
+
22
23
  var shouldInstrument = function shouldInstrument(name) {
23
- if (process.env.NODE_ENV !== 'production') {
24
+ if (process.env.NODE_ENV !== "production") {
24
25
  return true;
25
26
  }
27
+
26
28
  return name.charAt(0) !== '@';
27
29
  };
28
-
29
30
  /**
30
31
  * @public
31
32
  *
@@ -58,6 +59,8 @@ var shouldInstrument = function shouldInstrument(name) {
58
59
  * methods and profilers with names that begin with `@` will only be measured
59
60
  * if `__DEV__` is true. This should be used for very hot functions.
60
61
  */
62
+
63
+
61
64
  var RelayProfiler = {
62
65
  /**
63
66
  * Instruments methods on a class or object. This re-assigns the method in
@@ -84,7 +87,6 @@ var RelayProfiler = {
84
87
  }
85
88
  },
86
89
 
87
-
88
90
  /**
89
91
  * Wraps the supplied function with one that provides the `attachHandler` and
90
92
  * `detachHandler` methods. Example usage:
@@ -99,19 +101,23 @@ var RelayProfiler = {
99
101
  */
100
102
  instrument: function instrument(name, originalFunction) {
101
103
  if (!shouldInstrument(name)) {
102
- originalFunction.attachHandler = require('fbjs/lib/emptyFunction');
103
- originalFunction.detachHandler = require('fbjs/lib/emptyFunction');
104
+ originalFunction.attachHandler = require("fbjs/lib/emptyFunction");
105
+ originalFunction.detachHandler = require("fbjs/lib/emptyFunction");
104
106
  return originalFunction;
105
107
  }
108
+
106
109
  if (!aggregateHandlersByName.hasOwnProperty(name)) {
107
110
  aggregateHandlersByName[name] = [];
108
111
  }
112
+
109
113
  var catchallHandlers = aggregateHandlersByName['*'];
110
114
  var aggregateHandlers = aggregateHandlersByName[name];
111
115
  var handlers = [];
112
116
  var contexts = [];
117
+
113
118
  var invokeHandlers = function invokeHandlers() {
114
119
  var context = contexts[contexts.length - 1];
120
+
115
121
  if (context[0]) {
116
122
  context[0]--;
117
123
  catchallHandlers[context[0]](name, invokeHandlers);
@@ -125,8 +131,10 @@ var RelayProfiler = {
125
131
  context[5] = originalFunction.apply(context[3], context[4]);
126
132
  }
127
133
  };
134
+
128
135
  var instrumentedCallback = function instrumentedCallback() {
129
- var returnValue = void 0;
136
+ var returnValue;
137
+
130
138
  if (aggregateHandlers.length === 0 && handlers.length === 0 && catchallHandlers.length === 0) {
131
139
  returnValue = originalFunction.apply(this, arguments);
132
140
  } else {
@@ -134,23 +142,27 @@ var RelayProfiler = {
134
142
  invokeHandlers();
135
143
  var context = contexts.pop();
136
144
  returnValue = context[5];
145
+
137
146
  if (returnValue === NOT_INVOKED) {
138
147
  throw new Error('RelayProfiler: Handler did not invoke original function.');
139
148
  }
140
149
  }
150
+
141
151
  return returnValue;
142
152
  };
153
+
143
154
  instrumentedCallback.attachHandler = function (handler) {
144
155
  handlers.push(handler);
145
156
  };
157
+
146
158
  instrumentedCallback.detachHandler = function (handler) {
147
- require('fbjs/lib/removeFromArray')(handlers, handler);
159
+ require("fbjs/lib/removeFromArray")(handlers, handler);
148
160
  };
161
+
149
162
  instrumentedCallback.displayName = '(instrumented ' + name + ')';
150
163
  return instrumentedCallback;
151
164
  },
152
165
 
153
-
154
166
  /**
155
167
  * Attaches a handler to all methods instrumented with the supplied name.
156
168
  *
@@ -172,23 +184,22 @@ var RelayProfiler = {
172
184
  if (!aggregateHandlersByName.hasOwnProperty(name)) {
173
185
  aggregateHandlersByName[name] = [];
174
186
  }
187
+
175
188
  aggregateHandlersByName[name].push(handler);
176
189
  }
177
190
  },
178
191
 
179
-
180
192
  /**
181
193
  * Detaches a handler attached via `attachAggregateHandler`.
182
194
  */
183
195
  detachAggregateHandler: function detachAggregateHandler(name, handler) {
184
196
  if (shouldInstrument(name)) {
185
197
  if (aggregateHandlersByName.hasOwnProperty(name)) {
186
- require('fbjs/lib/removeFromArray')(aggregateHandlersByName[name], handler);
198
+ require("fbjs/lib/removeFromArray")(aggregateHandlersByName[name], handler);
187
199
  }
188
200
  }
189
201
  },
190
202
 
191
-
192
203
  /**
193
204
  * Instruments profiling for arbitrarily asynchronous code by a name.
194
205
  *
@@ -205,29 +216,32 @@ var RelayProfiler = {
205
216
  profile: function profile(name, state) {
206
217
  var hasCatchAllHandlers = profileHandlersByName['*'].length > 0;
207
218
  var hasNamedHandlers = profileHandlersByName.hasOwnProperty(name);
219
+
208
220
  if (hasNamedHandlers || hasCatchAllHandlers) {
209
221
  var profileHandlers = hasNamedHandlers && hasCatchAllHandlers ? profileHandlersByName[name].concat(profileHandlersByName['*']) : hasNamedHandlers ? profileHandlersByName[name] : profileHandlersByName['*'];
210
- var stopHandlers = void 0;
222
+ var stopHandlers;
223
+
211
224
  for (var ii = profileHandlers.length - 1; ii >= 0; ii--) {
212
225
  var profileHandler = profileHandlers[ii];
213
226
  var stopHandler = profileHandler(name, state);
214
227
  stopHandlers = stopHandlers || [];
215
228
  stopHandlers.unshift(stopHandler);
216
229
  }
230
+
217
231
  return {
218
- stop: function stop() {
232
+ stop: function stop(error) {
219
233
  if (stopHandlers) {
220
234
  stopHandlers.forEach(function (stopHandler) {
221
- return stopHandler();
235
+ return stopHandler(error);
222
236
  });
223
237
  }
224
238
  }
225
239
  };
226
240
  }
241
+
227
242
  return defaultProfiler;
228
243
  },
229
244
 
230
-
231
245
  /**
232
246
  * Attaches a handler to profiles with the supplied name. You can also
233
247
  * attach to the special name '*' which is a catch all.
@@ -237,21 +251,20 @@ var RelayProfiler = {
237
251
  if (!profileHandlersByName.hasOwnProperty(name)) {
238
252
  profileHandlersByName[name] = [];
239
253
  }
254
+
240
255
  profileHandlersByName[name].push(handler);
241
256
  }
242
257
  },
243
258
 
244
-
245
259
  /**
246
260
  * Detaches a handler attached via `attachProfileHandler`.
247
261
  */
248
262
  detachProfileHandler: function detachProfileHandler(name, handler) {
249
263
  if (shouldInstrument(name)) {
250
264
  if (profileHandlersByName.hasOwnProperty(name)) {
251
- require('fbjs/lib/removeFromArray')(profileHandlersByName[name], handler);
265
+ require("fbjs/lib/removeFromArray")(profileHandlersByName[name], handler);
252
266
  }
253
267
  }
254
268
  }
255
269
  };
256
-
257
270
  module.exports = RelayProfiler;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,13 +7,8 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
- var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
16
-
17
12
  /**
18
13
  * Coordinates the concurrent modification of a `Store` due to optimistic and
19
14
  * non-revertable client updates and server payloads:
@@ -25,18 +20,22 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
25
20
  * - Executes handlers for "handle" fields.
26
21
  * - Reverts and reapplies pending optimistic updates.
27
22
  */
28
- var RelayPublishQueue = function () {
29
- // Optimistic updaters to add with the next `run()`.
30
-
31
- // Payloads to apply or Sources to publish to the store with the next `run()`.
32
-
33
-
23
+ var RelayPublishQueue =
24
+ /*#__PURE__*/
25
+ function () {
34
26
  // A "negative" of all applied updaters. It can be published to the store to
35
27
  // undo them in order to re-apply some of them for a rebase.
28
+ // True if the next `run()` should apply the backup and rerun all optimistic
29
+ // updates performing a rebase.
30
+ // Payloads to apply or Sources to publish to the store with the next `run()`.
31
+ // Updaters to apply with the next `run()`. These mutate the store and should
32
+ // typically only mutate client schema extensions.
33
+ // Optimistic updaters to add with the next `run()`.
34
+ // Optimistic updaters that are already added and might be rerun in order to
35
+ // rebase them.
36
+ // Garbage collection hold, should rerun gc on dispose
36
37
  function RelayPublishQueue(store, handlerProvider) {
37
- (0, _classCallCheck3['default'])(this, RelayPublishQueue);
38
-
39
- this._backup = new (require('./RelayInMemoryRecordSource'))();
38
+ this._backup = new (require("./RelayInMemoryRecordSource"))();
40
39
  this._handlerProvider = handlerProvider || null;
41
40
  this._pendingBackupRebase = false;
42
41
  this._pendingUpdaters = new Set();
@@ -44,80 +43,94 @@ var RelayPublishQueue = function () {
44
43
  this._pendingOptimisticUpdates = new Set();
45
44
  this._store = store;
46
45
  this._appliedOptimisticUpdates = new Set();
46
+ this._gcHold = null;
47
47
  }
48
-
49
48
  /**
50
49
  * Schedule applying an optimistic updates on the next `run()`.
51
50
  */
52
51
 
53
- // Optimistic updaters that are already added and might be rerun in order to
54
- // rebase them.
55
-
56
- // Updaters to apply with the next `run()`. These mutate the store and should
57
- // typically only mutate client schema extensions.
58
52
 
59
- // True if the next `run()` should apply the backup and rerun all optimistic
60
- // updates performing a rebase.
53
+ var _proto = RelayPublishQueue.prototype;
61
54
 
55
+ _proto.applyUpdate = function applyUpdate(updater) {
56
+ !(!this._appliedOptimisticUpdates.has(updater) && !this._pendingOptimisticUpdates.has(updater)) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayPublishQueue: Cannot apply the same update function more than ' + 'once concurrently.') : require("fbjs/lib/invariant")(false) : void 0;
62
57
 
63
- RelayPublishQueue.prototype.applyUpdate = function applyUpdate(updater) {
64
- !(!this._appliedOptimisticUpdates.has(updater) && !this._pendingOptimisticUpdates.has(updater)) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayPublishQueue: Cannot apply the same update function more than ' + 'once concurrently.') : require('fbjs/lib/invariant')(false) : void 0;
65
58
  this._pendingOptimisticUpdates.add(updater);
66
59
  };
67
-
68
60
  /**
69
61
  * Schedule reverting an optimistic updates on the next `run()`.
70
62
  */
71
63
 
72
64
 
73
- RelayPublishQueue.prototype.revertUpdate = function revertUpdate(updater) {
65
+ _proto.revertUpdate = function revertUpdate(updater) {
74
66
  if (this._pendingOptimisticUpdates.has(updater)) {
75
67
  // Reverted before it was applied
76
- this._pendingOptimisticUpdates['delete'](updater);
68
+ this._pendingOptimisticUpdates["delete"](updater);
77
69
  } else if (this._appliedOptimisticUpdates.has(updater)) {
78
70
  this._pendingBackupRebase = true;
79
- this._appliedOptimisticUpdates['delete'](updater);
71
+
72
+ this._appliedOptimisticUpdates["delete"](updater);
80
73
  }
81
74
  };
82
-
83
75
  /**
84
76
  * Schedule a revert of all optimistic updates on the next `run()`.
85
77
  */
86
78
 
87
79
 
88
- RelayPublishQueue.prototype.revertAll = function revertAll() {
80
+ _proto.revertAll = function revertAll() {
89
81
  this._pendingBackupRebase = true;
82
+
90
83
  this._pendingOptimisticUpdates.clear();
84
+
91
85
  this._appliedOptimisticUpdates.clear();
92
86
  };
93
-
94
87
  /**
95
88
  * Schedule applying a payload to the store on the next `run()`.
96
89
  */
97
90
 
98
91
 
99
- RelayPublishQueue.prototype.commitPayload = function commitPayload(operation, _ref, updater) {
92
+ _proto.commitPayload = function commitPayload(operation, _ref, updater) {
100
93
  var fieldPayloads = _ref.fieldPayloads,
101
94
  source = _ref.source;
102
-
103
95
  this._pendingBackupRebase = true;
96
+
104
97
  this._pendingData.add({
105
98
  kind: 'payload',
106
- payload: { fieldPayloads: fieldPayloads, operation: operation, source: source, updater: updater }
99
+ payload: {
100
+ fieldPayloads: fieldPayloads,
101
+ operation: operation,
102
+ source: source,
103
+ updater: updater
104
+ }
107
105
  });
108
106
  };
109
107
 
108
+ _proto.commitRelayPayload = function commitRelayPayload(_ref2) {
109
+ var fieldPayloads = _ref2.fieldPayloads,
110
+ source = _ref2.source;
111
+ this._pendingBackupRebase = true;
112
+
113
+ this._pendingData.add({
114
+ kind: 'payload',
115
+ payload: {
116
+ fieldPayloads: fieldPayloads,
117
+ operation: null,
118
+ source: source,
119
+ updater: null
120
+ }
121
+ });
122
+ };
110
123
  /**
111
124
  * Schedule an updater to mutate the store on the next `run()` typically to
112
125
  * update client schema fields.
113
126
  */
114
127
 
115
128
 
116
- RelayPublishQueue.prototype.commitUpdate = function commitUpdate(updater) {
129
+ _proto.commitUpdate = function commitUpdate(updater) {
117
130
  this._pendingBackupRebase = true;
131
+
118
132
  this._pendingUpdaters.add(updater);
119
133
  };
120
-
121
134
  /**
122
135
  * Schedule a publish to the store from the provided source on the next
123
136
  * `run()`. As an example, to update the store with substituted fields that
@@ -125,160 +138,192 @@ var RelayPublishQueue = function () {
125
138
  */
126
139
 
127
140
 
128
- RelayPublishQueue.prototype.commitSource = function commitSource(source) {
141
+ _proto.commitSource = function commitSource(source) {
129
142
  this._pendingBackupRebase = true;
130
- this._pendingData.add({ kind: 'source', source: source });
131
- };
132
143
 
144
+ this._pendingData.add({
145
+ kind: 'source',
146
+ source: source
147
+ });
148
+ };
133
149
  /**
134
150
  * Execute all queued up operations from the other public methods.
135
151
  */
136
152
 
137
153
 
138
- RelayPublishQueue.prototype.run = function run() {
154
+ _proto.run = function run() {
139
155
  if (this._pendingBackupRebase && this._backup.size()) {
140
156
  this._store.publish(this._backup);
141
- this._backup = new (require('./RelayInMemoryRecordSource'))();
157
+
158
+ this._backup = new (require("./RelayInMemoryRecordSource"))();
142
159
  }
160
+
143
161
  this._commitData();
162
+
144
163
  this._commitUpdaters();
164
+
145
165
  this._applyUpdates();
166
+
146
167
  this._pendingBackupRebase = false;
168
+
169
+ if (this._appliedOptimisticUpdates.size > 0) {
170
+ if (!this._gcHold) {
171
+ this._gcHold = this._store.holdGC();
172
+ }
173
+ } else {
174
+ if (this._gcHold) {
175
+ this._gcHold.dispose();
176
+
177
+ this._gcHold = null;
178
+ }
179
+ }
180
+
147
181
  this._store.notify();
148
182
  };
149
183
 
150
- RelayPublishQueue.prototype._getSourceFromPayload = function _getSourceFromPayload(payload) {
184
+ _proto._getSourceFromPayload = function _getSourceFromPayload(payload) {
151
185
  var _this = this;
152
186
 
153
187
  var fieldPayloads = payload.fieldPayloads,
154
188
  operation = payload.operation,
155
189
  source = payload.source,
156
190
  updater = payload.updater;
191
+ var mutator = new (require("./RelayRecordSourceMutator"))(this._store.getSource(), source);
192
+ var store = new (require("./RelayRecordSourceProxy"))(mutator);
157
193
 
158
- var mutator = new (require('./RelayRecordSourceMutator'))(this._store.getSource(), source);
159
- var store = new (require('./RelayRecordSourceProxy'))(mutator);
160
- var selectorStore = new (require('./RelayRecordSourceSelectorProxy'))(store, operation.fragment);
161
194
  if (fieldPayloads && fieldPayloads.length) {
162
195
  fieldPayloads.forEach(function (fieldPayload) {
163
196
  var handler = _this._handlerProvider && _this._handlerProvider(fieldPayload.handle);
164
- !handler ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernEnvironment: Expected a handler to be provided for ' + 'handle `%s`.', fieldPayload.handle) : require('fbjs/lib/invariant')(false) : void 0;
197
+
198
+ !handler ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernEnvironment: Expected a handler to be provided for ' + 'handle `%s`.', fieldPayload.handle) : require("fbjs/lib/invariant")(false) : void 0;
165
199
  handler.update(store, fieldPayload);
166
200
  });
167
201
  }
202
+
168
203
  if (updater) {
169
- var selectorData = lookupSelector(source, operation.fragment);
204
+ var selector = operation === null || operation === void 0 ? void 0 : operation.fragment;
205
+ !(selector != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernEnvironment: Expected a selector to be provided with updater function.') : require("fbjs/lib/invariant")(false) : void 0;
206
+ var selectorStore = new (require("./RelayRecordSourceSelectorProxy"))(store, selector);
207
+ var selectorData = lookupSelector(source, selector, operation);
170
208
  updater(selectorStore, selectorData);
171
209
  }
210
+
172
211
  return source;
173
212
  };
174
213
 
175
- RelayPublishQueue.prototype._commitData = function _commitData() {
214
+ _proto._commitData = function _commitData() {
176
215
  var _this2 = this;
177
216
 
178
217
  if (!this._pendingData.size) {
179
218
  return;
180
219
  }
220
+
181
221
  this._pendingData.forEach(function (data) {
182
- var source = void 0;
222
+ var source;
223
+
183
224
  if (data.kind === 'payload') {
184
225
  source = _this2._getSourceFromPayload(data.payload);
185
226
  } else {
186
227
  source = data.source;
187
228
  }
229
+
188
230
  _this2._store.publish(source);
189
231
  });
232
+
190
233
  this._pendingData.clear();
191
234
  };
192
235
 
193
- RelayPublishQueue.prototype._commitUpdaters = function _commitUpdaters() {
236
+ _proto._commitUpdaters = function _commitUpdaters() {
194
237
  var _this3 = this;
195
238
 
196
239
  if (!this._pendingUpdaters.size) {
197
240
  return;
198
241
  }
199
- var sink = new (require('./RelayInMemoryRecordSource'))();
242
+
243
+ var sink = new (require("./RelayInMemoryRecordSource"))();
244
+
200
245
  this._pendingUpdaters.forEach(function (updater) {
201
- var mutator = new (require('./RelayRecordSourceMutator'))(_this3._store.getSource(), sink);
202
- var store = new (require('./RelayRecordSourceProxy'))(mutator);
203
- require('fbjs/lib/ErrorUtils').applyWithGuard(updater, null, [store], null, 'RelayPublishQueue:commitUpdaters');
246
+ var mutator = new (require("./RelayRecordSourceMutator"))(_this3._store.getSource(), sink);
247
+ var store = new (require("./RelayRecordSourceProxy"))(mutator);
248
+
249
+ require("fbjs/lib/ErrorUtils").applyWithGuard(updater, null, [store], null, 'RelayPublishQueue:commitUpdaters');
204
250
  });
251
+
205
252
  this._store.publish(sink);
253
+
206
254
  this._pendingUpdaters.clear();
207
255
  };
208
256
 
209
- RelayPublishQueue.prototype._applyUpdates = function _applyUpdates() {
257
+ _proto._applyUpdates = function _applyUpdates() {
210
258
  var _this4 = this;
211
259
 
212
260
  if (this._pendingOptimisticUpdates.size || this._pendingBackupRebase && this._appliedOptimisticUpdates.size) {
213
- var sink = new (require('./RelayInMemoryRecordSource'))();
214
- var mutator = new (require('./RelayRecordSourceMutator'))(this._store.getSource(), sink, this._backup);
215
- var store = new (require('./RelayRecordSourceProxy'))(mutator, this._handlerProvider);
261
+ var sink = new (require("./RelayInMemoryRecordSource"))();
262
+ var mutator = new (require("./RelayRecordSourceMutator"))(this._store.getSource(), sink, this._backup);
263
+ var store = new (require("./RelayRecordSourceProxy"))(mutator, this._handlerProvider); // rerun all updaters in case we are running a rebase
216
264
 
217
- // rerun all updaters in case we are running a rebase
218
265
  if (this._pendingBackupRebase && this._appliedOptimisticUpdates.size) {
219
266
  this._appliedOptimisticUpdates.forEach(function (optimisticUpdate) {
220
267
  if (optimisticUpdate.operation) {
221
268
  var selectorStoreUpdater = optimisticUpdate.selectorStoreUpdater,
222
- _operation = optimisticUpdate.operation,
269
+ operation = optimisticUpdate.operation,
223
270
  response = optimisticUpdate.response;
271
+ var selectorStore = store.commitPayload(operation, response); // TODO: Fix commitPayload so we don't have to run normalize twice
224
272
 
225
- var selectorStore = store.commitPayload(_operation, response);
226
- // TODO: Fix commitPayload so we don't have to run normalize twice
227
- var selectorData = void 0,
228
- _source = void 0;
229
- if (response) {
230
- var _normalizeRelayPayloa = require('./normalizeRelayPayload')(_operation.root, response);
273
+ var selectorData, source;
231
274
 
232
- _source = _normalizeRelayPayloa.source;
275
+ if (response) {
276
+ var _normalizeRelayPayloa = require("./normalizeRelayPayload")(operation.root, response);
233
277
 
234
- selectorData = lookupSelector(_source, _operation.fragment);
278
+ source = _normalizeRelayPayloa.source;
279
+ selectorData = lookupSelector(source, operation.fragment, operation);
235
280
  }
236
- selectorStoreUpdater && require('fbjs/lib/ErrorUtils').applyWithGuard(selectorStoreUpdater, null, [selectorStore, selectorData], null, 'RelayPublishQueue:applyUpdates');
281
+
282
+ selectorStoreUpdater && require("fbjs/lib/ErrorUtils").applyWithGuard(selectorStoreUpdater, null, [selectorStore, selectorData], null, 'RelayPublishQueue:applyUpdates');
237
283
  } else if (optimisticUpdate.storeUpdater) {
238
284
  var storeUpdater = optimisticUpdate.storeUpdater;
239
285
 
240
- require('fbjs/lib/ErrorUtils').applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
286
+ require("fbjs/lib/ErrorUtils").applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
241
287
  } else {
242
- var _source2 = optimisticUpdate.source,
243
- _fieldPayloads = optimisticUpdate.fieldPayloads;
244
-
245
- store.publishSource(_source2, _fieldPayloads);
288
+ var _source = optimisticUpdate.source,
289
+ fieldPayloads = optimisticUpdate.fieldPayloads;
290
+ store.publishSource(_source, fieldPayloads);
246
291
  }
247
292
  });
248
- }
293
+ } // apply any new updaters
294
+
249
295
 
250
- // apply any new updaters
251
296
  if (this._pendingOptimisticUpdates.size) {
252
297
  this._pendingOptimisticUpdates.forEach(function (optimisticUpdate) {
253
298
  if (optimisticUpdate.operation) {
254
299
  var selectorStoreUpdater = optimisticUpdate.selectorStoreUpdater,
255
- _operation2 = optimisticUpdate.operation,
300
+ operation = optimisticUpdate.operation,
256
301
  response = optimisticUpdate.response;
302
+ var selectorStore = store.commitPayload(operation, response); // TODO: Fix commitPayload so we don't have to run normalize twice
257
303
 
258
- var selectorStore = store.commitPayload(_operation2, response);
259
- // TODO: Fix commitPayload so we don't have to run normalize twice
260
- var selectorData = void 0,
261
- _source3 = void 0;
262
- if (response) {
263
- var _normalizeRelayPayloa2 = require('./normalizeRelayPayload')(_operation2.root, response);
304
+ var selectorData, source;
264
305
 
265
- _source3 = _normalizeRelayPayloa2.source;
306
+ if (response) {
307
+ var _normalizeRelayPayloa2 = require("./normalizeRelayPayload")(operation.root, response);
266
308
 
267
- selectorData = lookupSelector(_source3, _operation2.fragment);
309
+ source = _normalizeRelayPayloa2.source;
310
+ selectorData = lookupSelector(source, operation.fragment, operation);
268
311
  }
269
- selectorStoreUpdater && require('fbjs/lib/ErrorUtils').applyWithGuard(selectorStoreUpdater, null, [selectorStore, selectorData], null, 'RelayPublishQueue:applyUpdates');
312
+
313
+ selectorStoreUpdater && require("fbjs/lib/ErrorUtils").applyWithGuard(selectorStoreUpdater, null, [selectorStore, selectorData], null, 'RelayPublishQueue:applyUpdates');
270
314
  } else if (optimisticUpdate.storeUpdater) {
271
315
  var storeUpdater = optimisticUpdate.storeUpdater;
272
316
 
273
- require('fbjs/lib/ErrorUtils').applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
317
+ require("fbjs/lib/ErrorUtils").applyWithGuard(storeUpdater, null, [store], null, 'RelayPublishQueue:applyUpdates');
274
318
  } else {
275
- var _source4 = optimisticUpdate.source,
276
- _fieldPayloads2 = optimisticUpdate.fieldPayloads;
277
-
278
- store.publishSource(_source4, _fieldPayloads2);
319
+ var _source2 = optimisticUpdate.source,
320
+ fieldPayloads = optimisticUpdate.fieldPayloads;
321
+ store.publishSource(_source2, fieldPayloads);
279
322
  }
323
+
280
324
  _this4._appliedOptimisticUpdates.add(optimisticUpdate);
281
325
  });
326
+
282
327
  this._pendingOptimisticUpdates.clear();
283
328
  }
284
329
 
@@ -289,14 +334,17 @@ var RelayPublishQueue = function () {
289
334
  return RelayPublishQueue;
290
335
  }();
291
336
 
292
- function lookupSelector(source, selector) {
293
- var selectorData = require('./RelayReader').read(source, selector).data;
294
- if (process.env.NODE_ENV !== 'production') {
295
- var deepFreeze = require('./deepFreeze');
337
+ function lookupSelector(source, selector, owner) {
338
+ var selectorData = require("./RelayReader").read(source, selector, owner).data;
339
+
340
+ if (process.env.NODE_ENV !== "production") {
341
+ var deepFreeze = require("./deepFreeze");
342
+
296
343
  if (selectorData) {
297
344
  deepFreeze(selectorData);
298
345
  }
299
346
  }
347
+
300
348
  return selectorData;
301
349
  }
302
350