@airtable/blocks 1.7.0 → 1.9.0-experimental
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/CHANGELOG.md +29 -3
- package/dist/cjs/error_utils.js +17 -0
- package/dist/cjs/models/base.js +16 -11
- package/dist/cjs/models/cursor.js +2 -0
- package/dist/cjs/models/field.js +157 -36
- package/dist/cjs/models/grouped_record_query_result.js +5 -14
- package/dist/cjs/models/linked_records_query_result.js +75 -27
- package/dist/cjs/models/mutation_constants.js +3 -1
- package/dist/cjs/models/mutations.js +70 -178
- package/dist/cjs/models/query_manager.js +327 -0
- package/dist/cjs/models/record.js +308 -55
- package/dist/cjs/models/record_query_result.js +4 -1
- package/dist/cjs/models/record_store.js +554 -765
- package/dist/cjs/models/table.js +22 -19
- package/dist/cjs/models/table_or_view_query_result.js +480 -414
- package/dist/cjs/models/view_data_store.js +243 -269
- package/dist/cjs/private_utils.js +50 -0
- package/dist/cjs/sdk.js +12 -2
- package/dist/cjs/testing/{mock_airtable_interface.js → abstract_mock_airtable_interface.js} +71 -22
- package/dist/cjs/types/block_query_spec.js +85 -0
- package/dist/cjs/types/field.js +1 -0
- package/dist/cjs/types/mutations.js +1 -0
- package/dist/cjs/ui/icon_config.js +6 -2
- package/dist/cjs/ui/use_global_config.js +1 -1
- package/dist/cjs/ui/use_records.js +5 -1
- package/dist/cjs/unstable_testing_utils.js +2 -2
- package/dist/cjs/watchable.js +123 -71
- package/dist/types/src/models/base.d.ts +10 -9
- package/dist/types/src/models/base.d.ts.map +1 -1
- package/dist/types/src/models/cursor.d.ts +2 -0
- package/dist/types/src/models/cursor.d.ts.map +1 -1
- package/dist/types/src/models/field.d.ts +71 -9
- package/dist/types/src/models/field.d.ts.map +1 -1
- package/dist/types/src/models/grouped_record_query_result.d.ts +3 -3
- package/dist/types/src/models/grouped_record_query_result.d.ts.map +1 -1
- package/dist/types/src/models/linked_records_query_result.d.ts.map +1 -1
- package/dist/types/src/models/mutation_constants.d.ts +1 -0
- package/dist/types/src/models/mutation_constants.d.ts.map +1 -1
- package/dist/types/src/models/mutations.d.ts.map +1 -1
- package/dist/types/src/models/query_manager.d.ts +2 -0
- package/dist/types/src/models/query_manager.d.ts.map +1 -0
- package/dist/types/src/models/record.d.ts +12 -3
- package/dist/types/src/models/record.d.ts.map +1 -1
- package/dist/types/src/models/record_query_result.d.ts +3 -2
- package/dist/types/src/models/record_query_result.d.ts.map +1 -1
- package/dist/types/src/models/record_store.d.ts.map +1 -1
- package/dist/types/src/models/table.d.ts +8 -10
- package/dist/types/src/models/table.d.ts.map +1 -1
- package/dist/types/src/models/table_or_view_query_result.d.ts +3 -5
- package/dist/types/src/models/table_or_view_query_result.d.ts.map +1 -1
- package/dist/types/src/models/view_data_store.d.ts +0 -1
- package/dist/types/src/models/view_data_store.d.ts.map +1 -1
- package/dist/types/src/models/view_metadata_query_result.d.ts +1 -1
- package/dist/types/src/models/view_metadata_query_result.d.ts.map +1 -1
- package/dist/types/src/private_utils.d.ts +30 -1
- package/dist/types/src/private_utils.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/testing/{mock_airtable_interface.d.ts → abstract_mock_airtable_interface.d.ts} +20 -15
- package/dist/types/src/testing/abstract_mock_airtable_interface.d.ts.map +1 -0
- package/dist/types/src/types/airtable_interface.d.ts +45 -21
- package/dist/types/src/types/airtable_interface.d.ts.map +1 -1
- package/dist/types/src/types/block_query_spec.d.ts +139 -0
- package/dist/types/src/types/block_query_spec.d.ts.map +1 -0
- package/dist/types/src/types/field.d.ts +167 -51
- package/dist/types/src/types/field.d.ts.map +1 -1
- package/dist/types/src/types/mutations.d.ts +46 -3
- package/dist/types/src/types/mutations.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +0 -2
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/types/view.d.ts +3 -8
- package/dist/types/src/types/view.d.ts.map +1 -1
- package/dist/types/src/ui/icon_config.d.ts +7 -3
- package/dist/types/src/ui/icon_config.d.ts.map +1 -1
- package/dist/types/src/ui/link.d.ts +1 -1
- package/dist/types/src/ui/link.d.ts.map +1 -1
- package/dist/types/src/ui/use_global_config.d.ts +1 -1
- package/dist/types/src/unstable_testing_utils.d.ts +1 -1
- package/dist/types/src/unstable_testing_utils.d.ts.map +1 -1
- package/dist/types/src/watchable.d.ts.map +1 -1
- package/dist/types/stories/helpers/fake_cell_renderer.d.ts.map +1 -1
- package/dist/types/stories/helpers/field_type.d.ts.map +1 -1
- package/dist/types/stories/helpers/sync_source_options.d.ts +7 -0
- package/dist/types/stories/helpers/sync_source_options.d.ts.map +1 -0
- package/dist/types/test/airtable_interface_mocks/fixture_data.d.ts +121 -0
- package/dist/types/test/airtable_interface_mocks/fixture_data.d.ts.map +1 -0
- package/dist/types/test/airtable_interface_mocks/linked_records.d.ts +2 -2
- package/dist/types/test/airtable_interface_mocks/linked_records.d.ts.map +1 -1
- package/dist/types/test/airtable_interface_mocks/{mock_airtable_interface_internal.d.ts → mock_airtable_interface.d.ts} +26 -18
- package/dist/types/test/airtable_interface_mocks/mock_airtable_interface.d.ts.map +1 -0
- package/dist/types/test/airtable_interface_mocks/mock_base_data_stores.d.ts +51 -0
- package/dist/types/test/airtable_interface_mocks/mock_base_data_stores.d.ts.map +1 -0
- package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts +2 -2
- package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts.map +1 -1
- package/dist/types/test/test_helpers.d.ts +2 -0
- package/dist/types/test/test_helpers.d.ts.map +1 -1
- package/package.json +3 -1
- package/dist/types/src/testing/mock_airtable_interface.d.ts.map +0 -1
- package/dist/types/test/airtable_interface_mocks/mock_airtable_interface_internal.d.ts.map +0 -1
|
@@ -12,6 +12,8 @@ require("core-js/modules/es.array.concat");
|
|
|
12
12
|
|
|
13
13
|
require("core-js/modules/es.array.filter");
|
|
14
14
|
|
|
15
|
+
require("core-js/modules/es.array.includes");
|
|
16
|
+
|
|
15
17
|
require("core-js/modules/es.array.iterator");
|
|
16
18
|
|
|
17
19
|
require("core-js/modules/es.array.map");
|
|
@@ -24,6 +26,8 @@ require("core-js/modules/es.promise");
|
|
|
24
26
|
|
|
25
27
|
require("core-js/modules/es.set");
|
|
26
28
|
|
|
29
|
+
require("core-js/modules/es.string.includes");
|
|
30
|
+
|
|
27
31
|
require("core-js/modules/es.string.starts-with");
|
|
28
32
|
|
|
29
33
|
require("core-js/modules/web.dom-collections.for-each");
|
|
@@ -59,9 +63,13 @@ var _private_utils = require("../private_utils");
|
|
|
59
63
|
|
|
60
64
|
var _error_utils = require("../error_utils");
|
|
61
65
|
|
|
66
|
+
var _block_query_spec = require("../types/block_query_spec");
|
|
67
|
+
|
|
62
68
|
var _table = _interopRequireWildcard(require("./table"));
|
|
63
69
|
|
|
64
|
-
var
|
|
70
|
+
var _view = _interopRequireDefault(require("./view"));
|
|
71
|
+
|
|
72
|
+
var _record_query_result = _interopRequireWildcard(require("./record_query_result"));
|
|
65
73
|
|
|
66
74
|
var _record_coloring = require("./record_coloring");
|
|
67
75
|
|
|
@@ -97,6 +105,17 @@ function (_RecordQueryResult) {
|
|
|
97
105
|
|
|
98
106
|
/** @internal */
|
|
99
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Tracks a unique ID for each model query that has been loaded.
|
|
110
|
+
* Note that hyperbase may return a new model query ID even if the
|
|
111
|
+
* query itself is identical to a previous one. Having these unique
|
|
112
|
+
* IDs allows the SDK to maintain an accurate reference count of
|
|
113
|
+
* all model loads. _loadedSourceModelQueryIds must only be updated
|
|
114
|
+
* before unloading occurs.
|
|
115
|
+
*
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
|
|
100
119
|
/** @internal */
|
|
101
120
|
|
|
102
121
|
/** @internal */
|
|
@@ -124,17 +143,6 @@ function (_RecordQueryResult) {
|
|
|
124
143
|
/** @internal */
|
|
125
144
|
// lazily generated set of record ids
|
|
126
145
|
|
|
127
|
-
/** @internal */
|
|
128
|
-
// NOTE: when a cellValue key (cellValues or cellValuesInField:) is watched, we want
|
|
129
|
-
// to make sure we watch the associated key on the table. However, we need to make
|
|
130
|
-
// sure that we only watch the table once for each key. Otherwise, the callbacks
|
|
131
|
-
// for each key will get called more than once for each change event. This is because
|
|
132
|
-
// Watchable stores references to callbacks for each key, and on each _onChange event
|
|
133
|
-
// calls each callback for that key. If we watch the table more than once, then we'll
|
|
134
|
-
// call _onChange more than once, and each callback will be called more than once, which
|
|
135
|
-
// is undesirable. Instead, we'll store watch counts for each key to make sure we only
|
|
136
|
-
// watch the table once.
|
|
137
|
-
|
|
138
146
|
/** @internal */
|
|
139
147
|
|
|
140
148
|
/** @internal */
|
|
@@ -146,7 +154,8 @@ function (_RecordQueryResult) {
|
|
|
146
154
|
(0, _classCallCheck2.default)(this, TableOrViewQueryResult);
|
|
147
155
|
_this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(TableOrViewQueryResult).call(this, sdk, normalizedOpts));
|
|
148
156
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_sourceModel", void 0);
|
|
149
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "
|
|
157
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_mostRecentSourceModelLoadedPromise", void 0);
|
|
158
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_loadedSourceModelQueryIds", void 0);
|
|
150
159
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_table", void 0);
|
|
151
160
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_fieldIdsSetToLoadOrNullIfAllFields", void 0);
|
|
152
161
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_visList", void 0);
|
|
@@ -156,10 +165,145 @@ function (_RecordQueryResult) {
|
|
|
156
165
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_orderedGroups", void 0);
|
|
157
166
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_loadedGroupLevels", void 0);
|
|
158
167
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_recordIdsSet", null);
|
|
159
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_cellValueKeyWatchCounts", void 0);
|
|
160
168
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "__groupedRecordQueryResultPool", void 0);
|
|
169
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_watchConfigByWatchableKey", {
|
|
170
|
+
// Handles if this is a prefix
|
|
171
|
+
[_record_query_result.default.WatchableCellValuesInFieldKeyPrefix]: (key, functionToCallWithKey) => {
|
|
172
|
+
var fieldId = key.substring(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix.length);
|
|
173
|
+
|
|
174
|
+
if (_this._fieldIdsSetToLoadOrNullIfAllFields && !(0, _private_utils.has)(_this._fieldIdsSetToLoadOrNullIfAllFields, fieldId)) {
|
|
175
|
+
throw (0, _error_utils.spawnError)("Can't watch or unwatch field because it wasn't included in RecordQueryResult fields: %s", fieldId);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
functionToCallWithKey(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
|
|
179
|
+
},
|
|
180
|
+
[_record_query_result.default.WatchableKeys.cellValues]: (key, functionToCallWithKey) => {
|
|
181
|
+
if (_this._fieldIdsSetToLoadOrNullIfAllFields) {
|
|
182
|
+
for (var _i = 0, _Object$keys = Object.keys(_this._fieldIdsSetToLoadOrNullIfAllFields); _i < _Object$keys.length; _i++) {
|
|
183
|
+
var fieldId = _Object$keys[_i];
|
|
184
|
+
functionToCallWithKey(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
functionToCallWithKey(_record_query_result.default.WatchableKeys.cellValues);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_unloadDataAsync", () => {
|
|
192
|
+
var viewDataStore, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, sort, field;
|
|
193
|
+
|
|
194
|
+
return _regenerator.default.async(function _callee$(_context) {
|
|
195
|
+
while (1) {
|
|
196
|
+
switch (_context.prev = _context.next) {
|
|
197
|
+
case 0:
|
|
198
|
+
if (!_this._mostRecentSourceModelLoadedPromise) {
|
|
199
|
+
_context.next = 3;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
_context.next = 3;
|
|
204
|
+
return _regenerator.default.awrap(_this._mostRecentSourceModelLoadedPromise);
|
|
205
|
+
|
|
206
|
+
case 3:
|
|
207
|
+
// Unload all queries that were subscribed to the entire query
|
|
208
|
+
if (_this._sourceModel instanceof _table.default) {
|
|
209
|
+
_this._recordStore.unloadCellValuesForQueryIdsThatAreSubscribedToAllCells(_this._loadedSourceModelQueryIds);
|
|
210
|
+
} else {
|
|
211
|
+
// Even if the view is deleted, we can still unsubscribe from the cells
|
|
212
|
+
_this._recordStore.unloadViewDataStoreAndCellValuesWithQueryIds(_this._loadedSourceModelQueryIds);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
_this._mostRecentSourceModelLoadedPromise = null;
|
|
216
|
+
|
|
217
|
+
if (_this._sourceModel instanceof _table.default) {
|
|
218
|
+
_this._recordStore.unwatch(_record_store.WatchableRecordStoreKeys.records, _this._onRecordsChanged, (0, _assertThisInitialized2.default)(_this));
|
|
219
|
+
} else {
|
|
220
|
+
if (!_this._sourceModel.isDeleted) {
|
|
221
|
+
viewDataStore = _this._recordStore.getViewDataStore(_this._sourceModel.id);
|
|
222
|
+
viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.visibleRecords, _this._onRecordsChanged, (0, _assertThisInitialized2.default)(_this));
|
|
223
|
+
viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groups, _this._onGroupsChanged, (0, _assertThisInitialized2.default)(_this));
|
|
224
|
+
viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groupLevels, _this._onGroupLevelsChanged, (0, _assertThisInitialized2.default)(_this));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_this._recordStore.unwatch(_this._cellValuesForSortWatchKeys, _this._onCellValuesForSortChanged, (0, _assertThisInitialized2.default)(_this));
|
|
229
|
+
|
|
230
|
+
_this._recordStore.unwatch(_this._cellValuesForGroupWatchKeys, _this._onCellValuesForGroupChanged, (0, _assertThisInitialized2.default)(_this));
|
|
231
|
+
|
|
232
|
+
_this._table.unwatch(_table.WatchableTableKeys.fields, _this._onTableFieldsChanged, (0, _assertThisInitialized2.default)(_this)); // If the table is deleted, can't call getFieldById on it below.
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
if (!(!_this._table.isDeleted && _this._sorts)) {
|
|
236
|
+
_context.next = 29;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
_iteratorNormalCompletion = true;
|
|
241
|
+
_didIteratorError = false;
|
|
242
|
+
_iteratorError = undefined;
|
|
243
|
+
_context.prev = 13;
|
|
244
|
+
|
|
245
|
+
for (_iterator = _this._sorts[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
246
|
+
sort = _step.value;
|
|
247
|
+
field = _this._table.getFieldByIdIfExists(sort.fieldId);
|
|
248
|
+
|
|
249
|
+
if (field) {
|
|
250
|
+
field.unwatch('type', _this._onFieldConfigChanged, (0, _assertThisInitialized2.default)(_this));
|
|
251
|
+
field.unwatch('options', _this._onFieldConfigChanged, (0, _assertThisInitialized2.default)(_this));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
_context.next = 21;
|
|
256
|
+
break;
|
|
257
|
+
|
|
258
|
+
case 17:
|
|
259
|
+
_context.prev = 17;
|
|
260
|
+
_context.t0 = _context["catch"](13);
|
|
261
|
+
_didIteratorError = true;
|
|
262
|
+
_iteratorError = _context.t0;
|
|
263
|
+
|
|
264
|
+
case 21:
|
|
265
|
+
_context.prev = 21;
|
|
266
|
+
_context.prev = 22;
|
|
267
|
+
|
|
268
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
269
|
+
_iterator.return();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
case 24:
|
|
273
|
+
_context.prev = 24;
|
|
274
|
+
|
|
275
|
+
if (!_didIteratorError) {
|
|
276
|
+
_context.next = 27;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
throw _iteratorError;
|
|
281
|
+
|
|
282
|
+
case 27:
|
|
283
|
+
return _context.finish(24);
|
|
284
|
+
|
|
285
|
+
case 28:
|
|
286
|
+
return _context.finish(21);
|
|
287
|
+
|
|
288
|
+
case 29:
|
|
289
|
+
_this._unloadOrderedGroupsIfNeeded();
|
|
290
|
+
|
|
291
|
+
_this._visList = null;
|
|
292
|
+
_this._orderedRecordIds = null;
|
|
293
|
+
_this._recordIdsSet = null;
|
|
294
|
+
|
|
295
|
+
_this._table.__tableOrViewQueryResultPool.unregisterObjectForReuseStrong((0, _assertThisInitialized2.default)(_this));
|
|
296
|
+
|
|
297
|
+
case 34:
|
|
298
|
+
case "end":
|
|
299
|
+
return _context.stop();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}, null, null, [[13, 17, 21, 29], [22,, 24, 28]]);
|
|
303
|
+
});
|
|
161
304
|
_this._sourceModel = sourceModel;
|
|
162
|
-
_this.
|
|
305
|
+
_this._mostRecentSourceModelLoadedPromise = null;
|
|
306
|
+
_this._loadedSourceModelQueryIds = [];
|
|
163
307
|
_this._table = normalizedOpts.table;
|
|
164
308
|
var sorts = _this._normalizedOpts.sorts;
|
|
165
309
|
_this._sorts = sorts !== null && sorts !== void 0 ? sorts : null; // TODO (SeanKeenan): Placeholder until we support groups from normalizedOpts
|
|
@@ -169,58 +313,57 @@ function (_RecordQueryResult) {
|
|
|
169
313
|
_this._orderedRecordIds = null;
|
|
170
314
|
_this._orderedGroups = null;
|
|
171
315
|
_this._loadedGroupLevels = null;
|
|
172
|
-
_this._cellValueKeyWatchCounts = {};
|
|
173
316
|
var fieldIdsSetToLoadOrNullIfAllFields = null;
|
|
174
317
|
|
|
175
318
|
if (_this._normalizedOpts.fieldIdsOrNullIfAllFields) {
|
|
176
319
|
fieldIdsSetToLoadOrNullIfAllFields = {};
|
|
177
|
-
var
|
|
178
|
-
var
|
|
179
|
-
var
|
|
320
|
+
var _iteratorNormalCompletion2 = true;
|
|
321
|
+
var _didIteratorError2 = false;
|
|
322
|
+
var _iteratorError2 = undefined;
|
|
180
323
|
|
|
181
324
|
try {
|
|
182
|
-
for (var
|
|
183
|
-
var fieldId =
|
|
325
|
+
for (var _iterator2 = _this._normalizedOpts.fieldIdsOrNullIfAllFields[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
326
|
+
var fieldId = _step2.value;
|
|
184
327
|
fieldIdsSetToLoadOrNullIfAllFields[fieldId] = true;
|
|
185
328
|
} // Need to load data for fields we're sorting by, even if
|
|
186
329
|
// they're not explicitly requested in the `fields` opt.
|
|
187
330
|
|
|
188
331
|
} catch (err) {
|
|
189
|
-
|
|
190
|
-
|
|
332
|
+
_didIteratorError2 = true;
|
|
333
|
+
_iteratorError2 = err;
|
|
191
334
|
} finally {
|
|
192
335
|
try {
|
|
193
|
-
if (!
|
|
194
|
-
|
|
336
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
337
|
+
_iterator2.return();
|
|
195
338
|
}
|
|
196
339
|
} finally {
|
|
197
|
-
if (
|
|
198
|
-
throw
|
|
340
|
+
if (_didIteratorError2) {
|
|
341
|
+
throw _iteratorError2;
|
|
199
342
|
}
|
|
200
343
|
}
|
|
201
344
|
}
|
|
202
345
|
|
|
203
346
|
if (_this._sorts !== null) {
|
|
204
|
-
var
|
|
205
|
-
var
|
|
206
|
-
var
|
|
347
|
+
var _iteratorNormalCompletion3 = true;
|
|
348
|
+
var _didIteratorError3 = false;
|
|
349
|
+
var _iteratorError3 = undefined;
|
|
207
350
|
|
|
208
351
|
try {
|
|
209
|
-
for (var
|
|
210
|
-
var sort =
|
|
352
|
+
for (var _iterator3 = _this._sorts[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
353
|
+
var sort = _step3.value;
|
|
211
354
|
fieldIdsSetToLoadOrNullIfAllFields[sort.fieldId] = true;
|
|
212
355
|
}
|
|
213
356
|
} catch (err) {
|
|
214
|
-
|
|
215
|
-
|
|
357
|
+
_didIteratorError3 = true;
|
|
358
|
+
_iteratorError3 = err;
|
|
216
359
|
} finally {
|
|
217
360
|
try {
|
|
218
|
-
if (!
|
|
219
|
-
|
|
361
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
362
|
+
_iterator3.return();
|
|
220
363
|
}
|
|
221
364
|
} finally {
|
|
222
|
-
if (
|
|
223
|
-
throw
|
|
365
|
+
if (_didIteratorError3) {
|
|
366
|
+
throw _iteratorError3;
|
|
224
367
|
}
|
|
225
368
|
}
|
|
226
369
|
}
|
|
@@ -260,26 +403,26 @@ function (_RecordQueryResult) {
|
|
|
260
403
|
value: function _getOrGenerateRecordIdsSet() {
|
|
261
404
|
if (!this._recordIdsSet) {
|
|
262
405
|
var recordIdsSet = {};
|
|
263
|
-
var
|
|
264
|
-
var
|
|
265
|
-
var
|
|
406
|
+
var _iteratorNormalCompletion4 = true;
|
|
407
|
+
var _didIteratorError4 = false;
|
|
408
|
+
var _iteratorError4 = undefined;
|
|
266
409
|
|
|
267
410
|
try {
|
|
268
|
-
for (var
|
|
269
|
-
var recordId =
|
|
411
|
+
for (var _iterator4 = this.recordIds[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
412
|
+
var recordId = _step4.value;
|
|
270
413
|
recordIdsSet[recordId] = true;
|
|
271
414
|
}
|
|
272
415
|
} catch (err) {
|
|
273
|
-
|
|
274
|
-
|
|
416
|
+
_didIteratorError4 = true;
|
|
417
|
+
_iteratorError4 = err;
|
|
275
418
|
} finally {
|
|
276
419
|
try {
|
|
277
|
-
if (!
|
|
278
|
-
|
|
420
|
+
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
421
|
+
_iterator4.return();
|
|
279
422
|
}
|
|
280
423
|
} finally {
|
|
281
|
-
if (
|
|
282
|
-
throw
|
|
424
|
+
if (_didIteratorError4) {
|
|
425
|
+
throw _iteratorError4;
|
|
283
426
|
}
|
|
284
427
|
}
|
|
285
428
|
}
|
|
@@ -296,85 +439,59 @@ function (_RecordQueryResult) {
|
|
|
296
439
|
*/
|
|
297
440
|
|
|
298
441
|
}, {
|
|
299
|
-
key: "
|
|
300
|
-
|
|
301
|
-
/** @internal */
|
|
302
|
-
value: function _incrementCellValueKeyWatchCountAndWatchIfNecessary(key, watchCallback) {
|
|
303
|
-
if (!this._cellValueKeyWatchCounts[key]) {
|
|
304
|
-
this._cellValueKeyWatchCounts[key] = 0;
|
|
305
|
-
|
|
306
|
-
this._recordStore.watch(key, watchCallback, this);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
this._cellValueKeyWatchCounts[key]++;
|
|
310
|
-
}
|
|
311
|
-
/** @internal */
|
|
312
|
-
|
|
313
|
-
}, {
|
|
314
|
-
key: "_decrementCellValueKeyWatchCountAndUnwatchIfPossible",
|
|
315
|
-
value: function _decrementCellValueKeyWatchCountAndUnwatchIfPossible(key, watchCallback) {
|
|
316
|
-
if (!this._cellValueKeyWatchCounts[key]) {
|
|
317
|
-
// Key isn't watched, so just skip it. This matches behavior of Watchable,
|
|
318
|
-
// where calling unwatch on a key that isn't watched just no-ops.
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
this._cellValueKeyWatchCounts[key]--;
|
|
323
|
-
|
|
324
|
-
if (this._cellValueKeyWatchCounts[key] === 0) {
|
|
325
|
-
// We're down to zero watches for this key, so we can actually unwatch it now.
|
|
326
|
-
this._recordStore.unwatch(key, watchCallback, this);
|
|
442
|
+
key: "watch",
|
|
327
443
|
|
|
328
|
-
delete this._cellValueKeyWatchCounts[key];
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
444
|
/** @inheritdoc */
|
|
332
|
-
|
|
333
|
-
}, {
|
|
334
|
-
key: "watch",
|
|
335
445
|
value: function watch(keys, callback, context) {
|
|
336
446
|
var validKeys = (0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "watch", this).call(this, keys, callback, context);
|
|
337
|
-
var _iteratorNormalCompletion4 = true;
|
|
338
|
-
var _didIteratorError4 = false;
|
|
339
|
-
var _iteratorError4 = undefined;
|
|
340
|
-
|
|
341
|
-
try {
|
|
342
|
-
for (var _iterator4 = validKeys[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
343
|
-
var _key2 = _step4.value;
|
|
344
|
-
|
|
345
|
-
if (_key2.startsWith(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix)) {
|
|
346
|
-
var fieldId = _key2.substring(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix.length);
|
|
347
447
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
448
|
+
var callWatchOnRecordStoreWithKeys = keysToWatch => {
|
|
449
|
+
this._recordStore.watchWithRecordQueryResult({
|
|
450
|
+
recordQueryResult: this,
|
|
451
|
+
keys: keysToWatch,
|
|
452
|
+
callbackForRegistration: callback,
|
|
453
|
+
context
|
|
454
|
+
});
|
|
455
|
+
};
|
|
351
456
|
|
|
352
|
-
|
|
353
|
-
|
|
457
|
+
var _iteratorNormalCompletion5 = true;
|
|
458
|
+
var _didIteratorError5 = false;
|
|
459
|
+
var _iteratorError5 = undefined;
|
|
354
460
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
461
|
+
try {
|
|
462
|
+
for (var _iterator5 = validKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
463
|
+
var _key2 = _step5.value;
|
|
464
|
+
|
|
465
|
+
// There are two watch systems:
|
|
466
|
+
// 1) the query-based watch
|
|
467
|
+
// 2) the non-query-based watch (through super)
|
|
468
|
+
// Depending on the key, we may use one or both of the systems.
|
|
469
|
+
// The non-query based watch system is used when when:
|
|
470
|
+
// - watching: records, recordIds
|
|
471
|
+
// - _loadDataAsync calls all watch keys on initial load
|
|
472
|
+
// - Support for _watchRecordColorsIfNeeded
|
|
473
|
+
// For all changes to the remaining keys - the query-based system is used.
|
|
474
|
+
if (_key2.startsWith(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix)) {
|
|
475
|
+
this._watchConfigByWatchableKey[_record_query_result.default.WatchableCellValuesInFieldKeyPrefix](_key2, callWatchOnRecordStoreWithKeys);
|
|
476
|
+
} else {
|
|
477
|
+
var _functionToCallWithKey = this._watchConfigByWatchableKey[_key2];
|
|
359
478
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
} else {
|
|
363
|
-
this._incrementCellValueKeyWatchCountAndWatchIfNecessary(_key2, this._onCellValuesChanged);
|
|
479
|
+
if (_functionToCallWithKey) {
|
|
480
|
+
_functionToCallWithKey(_key2, callWatchOnRecordStoreWithKeys);
|
|
364
481
|
}
|
|
365
482
|
}
|
|
366
483
|
}
|
|
367
484
|
} catch (err) {
|
|
368
|
-
|
|
369
|
-
|
|
485
|
+
_didIteratorError5 = true;
|
|
486
|
+
_iteratorError5 = err;
|
|
370
487
|
} finally {
|
|
371
488
|
try {
|
|
372
|
-
if (!
|
|
373
|
-
|
|
489
|
+
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
|
490
|
+
_iterator5.return();
|
|
374
491
|
}
|
|
375
492
|
} finally {
|
|
376
|
-
if (
|
|
377
|
-
throw
|
|
493
|
+
if (_didIteratorError5) {
|
|
494
|
+
throw _iteratorError5;
|
|
378
495
|
}
|
|
379
496
|
}
|
|
380
497
|
}
|
|
@@ -387,41 +504,41 @@ function (_RecordQueryResult) {
|
|
|
387
504
|
key: "unwatch",
|
|
388
505
|
value: function unwatch(keys, callback, context) {
|
|
389
506
|
var validKeys = (0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "unwatch", this).call(this, keys, callback, context);
|
|
390
|
-
|
|
391
|
-
var
|
|
392
|
-
|
|
507
|
+
|
|
508
|
+
var callUnwatchOnRecordStoreWithKeys = keysToUnwatch => {
|
|
509
|
+
this._recordStore.unwatch(keysToUnwatch, callback, context);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
var _iteratorNormalCompletion6 = true;
|
|
513
|
+
var _didIteratorError6 = false;
|
|
514
|
+
var _iteratorError6 = undefined;
|
|
393
515
|
|
|
394
516
|
try {
|
|
395
|
-
for (var
|
|
396
|
-
var _key3 =
|
|
517
|
+
for (var _iterator6 = validKeys[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
518
|
+
var _key3 = _step6.value;
|
|
397
519
|
|
|
520
|
+
// This is the inverse of the watch logic
|
|
398
521
|
if (_key3.startsWith(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix)) {
|
|
399
|
-
this.
|
|
400
|
-
}
|
|
522
|
+
this._watchConfigByWatchableKey[_record_query_result.default.WatchableCellValuesInFieldKeyPrefix](_key3, callUnwatchOnRecordStoreWithKeys);
|
|
523
|
+
} else {
|
|
524
|
+
var _functionToCallWithKey2 = this._watchConfigByWatchableKey[_key3];
|
|
401
525
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
for (var _i2 = 0, _Object$keys2 = Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields); _i2 < _Object$keys2.length; _i2++) {
|
|
405
|
-
var fieldId = _Object$keys2[_i2];
|
|
406
|
-
|
|
407
|
-
this._decrementCellValueKeyWatchCountAndUnwatchIfPossible(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId, this._onCellValuesChanged);
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
this._decrementCellValueKeyWatchCountAndUnwatchIfPossible(_key3, this._onCellValuesChanged);
|
|
526
|
+
if (_functionToCallWithKey2) {
|
|
527
|
+
_functionToCallWithKey2(_key3, callUnwatchOnRecordStoreWithKeys);
|
|
411
528
|
}
|
|
412
529
|
}
|
|
413
530
|
}
|
|
414
531
|
} catch (err) {
|
|
415
|
-
|
|
416
|
-
|
|
532
|
+
_didIteratorError6 = true;
|
|
533
|
+
_iteratorError6 = err;
|
|
417
534
|
} finally {
|
|
418
535
|
try {
|
|
419
|
-
if (!
|
|
420
|
-
|
|
536
|
+
if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
|
|
537
|
+
_iterator6.return();
|
|
421
538
|
}
|
|
422
539
|
} finally {
|
|
423
|
-
if (
|
|
424
|
-
throw
|
|
540
|
+
if (_didIteratorError6) {
|
|
541
|
+
throw _iteratorError6;
|
|
425
542
|
}
|
|
426
543
|
}
|
|
427
544
|
}
|
|
@@ -433,45 +550,54 @@ function (_RecordQueryResult) {
|
|
|
433
550
|
}, {
|
|
434
551
|
key: "loadDataAsync",
|
|
435
552
|
value: function loadDataAsync() {
|
|
436
|
-
var sourceModelLoadPromise,
|
|
437
|
-
return _regenerator.default.async(function loadDataAsync$(
|
|
553
|
+
var sourceModelLoadPromise, fieldIdsToLoadOrNullIfAllFields, allFieldsToQuery, metadataFieldId, sourceModelLoadedPromise;
|
|
554
|
+
return _regenerator.default.async(function loadDataAsync$(_context2) {
|
|
438
555
|
while (1) {
|
|
439
|
-
switch (
|
|
556
|
+
switch (_context2.prev = _context2.next) {
|
|
440
557
|
case 0:
|
|
441
558
|
if (!this._sourceModel.isDeleted) {
|
|
442
|
-
|
|
559
|
+
_context2.next = 2;
|
|
443
560
|
break;
|
|
444
561
|
}
|
|
445
562
|
|
|
446
563
|
throw this._spawnErrorForDeletion();
|
|
447
564
|
|
|
448
565
|
case 2:
|
|
449
|
-
|
|
450
|
-
cellValuesInFieldsLoadPromise = this._recordStore.loadCellValuesInFieldIdsAsync(Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields));
|
|
451
|
-
} else {
|
|
452
|
-
// Load all fields.
|
|
453
|
-
cellValuesInFieldsLoadPromise = this._recordStore.loadDataAsync();
|
|
454
|
-
}
|
|
566
|
+
fieldIdsToLoadOrNullIfAllFields = this._fieldIdsSetToLoadOrNullIfAllFields ? Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields) : null;
|
|
455
567
|
|
|
456
568
|
if (this._sourceModel instanceof _table.default) {
|
|
457
|
-
if (
|
|
458
|
-
|
|
569
|
+
if (fieldIdsToLoadOrNullIfAllFields) {
|
|
570
|
+
// TODO: (#proj-blocks-sdk-record-limits) Do we need to load the recordData metadata field
|
|
571
|
+
// in order to load any record data? If we do - this should be encapsulated entirely
|
|
572
|
+
// inside of the RecordStore in publicAirtableInterface.
|
|
573
|
+
// (should the queryModel be able to specify metadata requirements?)
|
|
574
|
+
allFieldsToQuery = fieldIdsToLoadOrNullIfAllFields;
|
|
575
|
+
metadataFieldId = this._recordStore._getFieldIdForCausingRecordMetadataToLoad();
|
|
576
|
+
|
|
577
|
+
if (!allFieldsToQuery.includes(metadataFieldId)) {
|
|
578
|
+
allFieldsToQuery = [...allFieldsToQuery, metadataFieldId];
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
sourceModelLoadPromise = this._recordStore.loadAllCellValuesInFieldIdsAsync(allFieldsToQuery);
|
|
459
582
|
} else {
|
|
460
|
-
//
|
|
461
|
-
|
|
462
|
-
sourceModelLoadPromise = null;
|
|
583
|
+
// Load all fields.
|
|
584
|
+
sourceModelLoadPromise = this._recordStore.loadAllCellValuesAsync();
|
|
463
585
|
}
|
|
464
586
|
} else {
|
|
465
|
-
sourceModelLoadPromise = this._recordStore.
|
|
466
|
-
}
|
|
587
|
+
sourceModelLoadPromise = this._recordStore.loadViewDataStoreAndCellValuesForFieldIdsAsync(this._sourceModel.id, fieldIdsToLoadOrNullIfAllFields);
|
|
588
|
+
} // See comment on _loadedSourceModelQueryIds declaration for details
|
|
467
589
|
|
|
468
|
-
|
|
469
|
-
|
|
590
|
+
|
|
591
|
+
sourceModelLoadedPromise = sourceModelLoadPromise.then(sourceModelQueryId => {
|
|
592
|
+
this._loadedSourceModelQueryIds.push(sourceModelQueryId);
|
|
593
|
+
});
|
|
594
|
+
this._mostRecentSourceModelLoadedPromise = Promise.all([sourceModelLoadedPromise, this._loadRecordColorsAsync()]);
|
|
595
|
+
_context2.next = 8;
|
|
470
596
|
return _regenerator.default.awrap((0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "loadDataAsync", this).call(this));
|
|
471
597
|
|
|
472
|
-
case
|
|
598
|
+
case 8:
|
|
473
599
|
case "end":
|
|
474
|
-
return
|
|
600
|
+
return _context2.stop();
|
|
475
601
|
}
|
|
476
602
|
}
|
|
477
603
|
}, null, this);
|
|
@@ -487,26 +613,26 @@ function (_RecordQueryResult) {
|
|
|
487
613
|
|
|
488
614
|
var fieldIds = this._normalizedOpts.fieldIdsOrNullIfAllFields || this._table.fields.map(field => field.id);
|
|
489
615
|
|
|
490
|
-
var
|
|
491
|
-
var
|
|
492
|
-
var
|
|
616
|
+
var _iteratorNormalCompletion7 = true;
|
|
617
|
+
var _didIteratorError7 = false;
|
|
618
|
+
var _iteratorError7 = undefined;
|
|
493
619
|
|
|
494
620
|
try {
|
|
495
|
-
for (var
|
|
496
|
-
var fieldId =
|
|
621
|
+
for (var _iterator7 = fieldIds[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
|
|
622
|
+
var fieldId = _step7.value;
|
|
497
623
|
changedKeys.push(_record_query_result.default.WatchableCellValuesInFieldKeyPrefix + fieldId);
|
|
498
624
|
}
|
|
499
625
|
} catch (err) {
|
|
500
|
-
|
|
501
|
-
|
|
626
|
+
_didIteratorError7 = true;
|
|
627
|
+
_iteratorError7 = err;
|
|
502
628
|
} finally {
|
|
503
629
|
try {
|
|
504
|
-
if (!
|
|
505
|
-
|
|
630
|
+
if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
|
|
631
|
+
_iterator7.return();
|
|
506
632
|
}
|
|
507
633
|
} finally {
|
|
508
|
-
if (
|
|
509
|
-
throw
|
|
634
|
+
if (_didIteratorError7) {
|
|
635
|
+
throw _iteratorError7;
|
|
510
636
|
}
|
|
511
637
|
}
|
|
512
638
|
}
|
|
@@ -518,55 +644,72 @@ function (_RecordQueryResult) {
|
|
|
518
644
|
}, {
|
|
519
645
|
key: "_loadDataAsync",
|
|
520
646
|
value: function _loadDataAsync() {
|
|
521
|
-
var viewDataStore,
|
|
647
|
+
var viewDataStore, _iteratorNormalCompletion8, _didIteratorError8, _iteratorError8, _iterator8, _step8, sort, field;
|
|
522
648
|
|
|
523
|
-
return _regenerator.default.async(function _loadDataAsync$(
|
|
649
|
+
return _regenerator.default.async(function _loadDataAsync$(_context3) {
|
|
524
650
|
while (1) {
|
|
525
|
-
switch (
|
|
651
|
+
switch (_context3.prev = _context3.next) {
|
|
526
652
|
case 0:
|
|
527
653
|
this._table.__tableOrViewQueryResultPool.registerObjectForReuseStrong(this);
|
|
528
654
|
|
|
529
|
-
(0, _error_utils.invariant)(this.
|
|
530
|
-
|
|
531
|
-
return _regenerator.default.awrap(this.
|
|
655
|
+
(0, _error_utils.invariant)(this._mostRecentSourceModelLoadedPromise, 'No source model load promises');
|
|
656
|
+
_context3.next = 4;
|
|
657
|
+
return _regenerator.default.awrap(this._mostRecentSourceModelLoadedPromise);
|
|
532
658
|
|
|
533
659
|
case 4:
|
|
534
660
|
if (this._sorts) {
|
|
535
661
|
this._replaceVisList();
|
|
536
662
|
}
|
|
537
663
|
|
|
538
|
-
this._orderedRecordIds = this._generateOrderedRecordIds();
|
|
539
|
-
this._orderedGroups = this._generateAndLoadOrderedGroups(); // The server provided value and developer supplied value are the same, no conversion needed
|
|
664
|
+
this._orderedRecordIds = this._generateOrderedRecordIds(); // Ensure that groups are not loaded
|
|
540
665
|
|
|
541
|
-
this.
|
|
666
|
+
this._orderedGroups = null; // The server provided value and developer supplied value are the same, no conversion needed
|
|
667
|
+
|
|
668
|
+
this._loadedGroupLevels = null;
|
|
542
669
|
|
|
543
670
|
if (this._sourceModel instanceof _table.default) {
|
|
544
|
-
this._recordStore.
|
|
671
|
+
this._recordStore.watchWithRecordQueryResult({
|
|
672
|
+
recordQueryResult: this,
|
|
673
|
+
keys: _record_store.WatchableRecordStoreKeys.records,
|
|
674
|
+
callbackForRegistration: this._onRecordsChanged,
|
|
675
|
+
context: this
|
|
676
|
+
});
|
|
545
677
|
} else {
|
|
546
678
|
viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id);
|
|
547
679
|
viewDataStore.watch(_view_data_store.WatchableViewDataStoreKeys.visibleRecords, this._onRecordsChanged, this);
|
|
548
680
|
viewDataStore.watch(_view_data_store.WatchableViewDataStoreKeys.groups, this._onGroupsChanged, this);
|
|
549
681
|
viewDataStore.watch(_view_data_store.WatchableViewDataStoreKeys.groupLevels, this._onGroupLevelsChanged, this);
|
|
550
|
-
}
|
|
682
|
+
} // This only watches cell values if a sort is specified
|
|
551
683
|
|
|
552
|
-
this._recordStore.watch(this._cellValuesForSortWatchKeys, this._onCellValuesForSortChanged, this);
|
|
553
684
|
|
|
554
|
-
this._recordStore.
|
|
685
|
+
this._recordStore.watchWithRecordQueryResult({
|
|
686
|
+
recordQueryResult: this,
|
|
687
|
+
keys: this._cellValuesForSortWatchKeys,
|
|
688
|
+
callbackForRegistration: this._onCellValuesForSortChanged,
|
|
689
|
+
context: this
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
this._recordStore.watchWithRecordQueryResult({
|
|
693
|
+
recordQueryResult: this,
|
|
694
|
+
keys: this._cellValuesForGroupWatchKeys,
|
|
695
|
+
callbackForRegistration: this._onCellValuesForGroupChanged,
|
|
696
|
+
context: this
|
|
697
|
+
});
|
|
555
698
|
|
|
556
699
|
this._table.watch(_table.WatchableTableKeys.fields, this._onTableFieldsChanged, this);
|
|
557
700
|
|
|
558
701
|
if (!this._sorts) {
|
|
559
|
-
|
|
702
|
+
_context3.next = 32;
|
|
560
703
|
break;
|
|
561
704
|
}
|
|
562
705
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
706
|
+
_iteratorNormalCompletion8 = true;
|
|
707
|
+
_didIteratorError8 = false;
|
|
708
|
+
_iteratorError8 = undefined;
|
|
709
|
+
_context3.prev = 16;
|
|
567
710
|
|
|
568
|
-
for (
|
|
569
|
-
sort =
|
|
711
|
+
for (_iterator8 = this._sorts[Symbol.iterator](); !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
|
712
|
+
sort = _step8.value;
|
|
570
713
|
field = this._table.getFieldByIdIfExists(sort.fieldId);
|
|
571
714
|
|
|
572
715
|
if (field) {
|
|
@@ -575,45 +718,45 @@ function (_RecordQueryResult) {
|
|
|
575
718
|
}
|
|
576
719
|
}
|
|
577
720
|
|
|
578
|
-
|
|
721
|
+
_context3.next = 24;
|
|
579
722
|
break;
|
|
580
723
|
|
|
581
724
|
case 20:
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
725
|
+
_context3.prev = 20;
|
|
726
|
+
_context3.t0 = _context3["catch"](16);
|
|
727
|
+
_didIteratorError8 = true;
|
|
728
|
+
_iteratorError8 = _context3.t0;
|
|
586
729
|
|
|
587
730
|
case 24:
|
|
588
|
-
|
|
589
|
-
|
|
731
|
+
_context3.prev = 24;
|
|
732
|
+
_context3.prev = 25;
|
|
590
733
|
|
|
591
|
-
if (!
|
|
592
|
-
|
|
734
|
+
if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
|
|
735
|
+
_iterator8.return();
|
|
593
736
|
}
|
|
594
737
|
|
|
595
738
|
case 27:
|
|
596
|
-
|
|
739
|
+
_context3.prev = 27;
|
|
597
740
|
|
|
598
|
-
if (!
|
|
599
|
-
|
|
741
|
+
if (!_didIteratorError8) {
|
|
742
|
+
_context3.next = 30;
|
|
600
743
|
break;
|
|
601
744
|
}
|
|
602
745
|
|
|
603
|
-
throw
|
|
746
|
+
throw _iteratorError8;
|
|
604
747
|
|
|
605
748
|
case 30:
|
|
606
|
-
return
|
|
749
|
+
return _context3.finish(27);
|
|
607
750
|
|
|
608
751
|
case 31:
|
|
609
|
-
return
|
|
752
|
+
return _context3.finish(24);
|
|
610
753
|
|
|
611
754
|
case 32:
|
|
612
|
-
return
|
|
755
|
+
return _context3.abrupt("return", this._getChangedKeysOnLoad());
|
|
613
756
|
|
|
614
757
|
case 33:
|
|
615
758
|
case "end":
|
|
616
|
-
return
|
|
759
|
+
return _context3.stop();
|
|
617
760
|
}
|
|
618
761
|
}
|
|
619
762
|
}, null, this, [[16, 20, 24, 32], [25,, 27, 31]]);
|
|
@@ -625,21 +768,9 @@ function (_RecordQueryResult) {
|
|
|
625
768
|
value: function unloadData() {
|
|
626
769
|
(0, _get2.default)((0, _getPrototypeOf2.default)(TableOrViewQueryResult.prototype), "unloadData", this).call(this);
|
|
627
770
|
|
|
628
|
-
if (this.
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
} else {
|
|
632
|
-
this._recordStore.unloadData();
|
|
633
|
-
}
|
|
634
|
-
} else {
|
|
635
|
-
// If the view is deleted, we can't get a data store for it.
|
|
636
|
-
if (!this._sourceModel.isDeleted) {
|
|
637
|
-
this._recordStore.getViewDataStore(this._sourceModel.id).unloadData();
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
if (this._fieldIdsSetToLoadOrNullIfAllFields) {
|
|
642
|
-
this._recordStore.unloadCellValuesInFieldIds(Object.keys(this._fieldIdsSetToLoadOrNullIfAllFields));
|
|
771
|
+
if (this._loadedSourceModelQueryIds.length === 0) {
|
|
772
|
+
// Source model must have loaded a queryId to unload
|
|
773
|
+
return;
|
|
643
774
|
}
|
|
644
775
|
|
|
645
776
|
this._unloadRecordColors();
|
|
@@ -649,119 +780,34 @@ function (_RecordQueryResult) {
|
|
|
649
780
|
}, {
|
|
650
781
|
key: "_unloadData",
|
|
651
782
|
value: function _unloadData() {
|
|
652
|
-
this.
|
|
653
|
-
|
|
654
|
-
if (this._sourceModel instanceof _table.default) {
|
|
655
|
-
this._recordStore.unwatch(_record_store.WatchableRecordStoreKeys.records, this._onRecordsChanged, this);
|
|
656
|
-
} else {
|
|
657
|
-
if (!this._sourceModel.isDeleted) {
|
|
658
|
-
var viewDataStore = this._recordStore.getViewDataStore(this._sourceModel.id);
|
|
659
|
-
|
|
660
|
-
viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.visibleRecords, this._onRecordsChanged, this);
|
|
661
|
-
viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groups, this._onGroupsChanged, this);
|
|
662
|
-
viewDataStore.unwatch(_view_data_store.WatchableViewDataStoreKeys.groupLevels, this._onGroupLevelsChanged, this);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
this._recordStore.unwatch(this._cellValuesForSortWatchKeys, this._onCellValuesForSortChanged, this);
|
|
667
|
-
|
|
668
|
-
this._recordStore.unwatch(this._cellValuesForGroupWatchKeys, this._onCellValuesForGroupChanged, this);
|
|
669
|
-
|
|
670
|
-
this._table.unwatch(_table.WatchableTableKeys.fields, this._onTableFieldsChanged, this); // If the table is deleted, can't call getFieldById on it below.
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if (!this._table.isDeleted && this._sorts) {
|
|
674
|
-
var _iteratorNormalCompletion8 = true;
|
|
675
|
-
var _didIteratorError8 = false;
|
|
676
|
-
var _iteratorError8 = undefined;
|
|
677
|
-
|
|
678
|
-
try {
|
|
679
|
-
for (var _iterator8 = this._sorts[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
|
680
|
-
var sort = _step8.value;
|
|
681
|
-
|
|
682
|
-
var field = this._table.getFieldByIdIfExists(sort.fieldId);
|
|
683
|
-
|
|
684
|
-
if (field) {
|
|
685
|
-
field.unwatch('type', this._onFieldConfigChanged, this);
|
|
686
|
-
field.unwatch('options', this._onFieldConfigChanged, this);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
} catch (err) {
|
|
690
|
-
_didIteratorError8 = true;
|
|
691
|
-
_iteratorError8 = err;
|
|
692
|
-
} finally {
|
|
693
|
-
try {
|
|
694
|
-
if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
|
|
695
|
-
_iterator8.return();
|
|
696
|
-
}
|
|
697
|
-
} finally {
|
|
698
|
-
if (_didIteratorError8) {
|
|
699
|
-
throw _iteratorError8;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
this._unloadOrderedGroupsIfNeeded();
|
|
706
|
-
|
|
707
|
-
this._visList = null;
|
|
708
|
-
this._orderedRecordIds = null;
|
|
709
|
-
this._recordIdsSet = null;
|
|
710
|
-
|
|
711
|
-
this._table.__tableOrViewQueryResultPool.unregisterObjectForReuseStrong(this);
|
|
783
|
+
(0, _private_utils.fireAndForgetPromise)(this._unloadDataAsync);
|
|
712
784
|
}
|
|
713
|
-
/** @internal */
|
|
714
|
-
|
|
715
785
|
}, {
|
|
716
786
|
key: "_addRecordIdsToVisList",
|
|
787
|
+
|
|
788
|
+
/** @internal */
|
|
717
789
|
value: function _addRecordIdsToVisList(recordIds) {
|
|
718
790
|
var visList = this._visList;
|
|
719
791
|
(0, _error_utils.invariant)(visList, 'No vis list');
|
|
720
|
-
|
|
721
|
-
var _didIteratorError9 = false;
|
|
722
|
-
var _iteratorError9 = undefined;
|
|
723
|
-
|
|
724
|
-
try {
|
|
725
|
-
for (var _iterator9 = recordIds[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
|
|
726
|
-
var recordId = _step9.value;
|
|
727
|
-
|
|
728
|
-
var record = this._recordStore.getRecordByIdIfExists(recordId);
|
|
729
|
-
|
|
730
|
-
(0, _error_utils.invariant)(record, 'Record missing in table');
|
|
731
|
-
visList.addRecordData(record._data);
|
|
732
|
-
}
|
|
733
|
-
} catch (err) {
|
|
734
|
-
_didIteratorError9 = true;
|
|
735
|
-
_iteratorError9 = err;
|
|
736
|
-
} finally {
|
|
737
|
-
try {
|
|
738
|
-
if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
|
|
739
|
-
_iterator9.return();
|
|
740
|
-
}
|
|
741
|
-
} finally {
|
|
742
|
-
if (_didIteratorError9) {
|
|
743
|
-
throw _iteratorError9;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}
|
|
792
|
+
visList.addRecordIds(recordIds);
|
|
747
793
|
}
|
|
748
794
|
/** @internal */
|
|
749
795
|
|
|
750
796
|
}, {
|
|
751
797
|
key: "_onGroupLevelsChanged",
|
|
752
798
|
value: function _onGroupLevelsChanged(model, key, updates) {
|
|
753
|
-
this._loadedGroupLevels =
|
|
799
|
+
this._loadedGroupLevels = null;
|
|
754
800
|
|
|
755
|
-
this.
|
|
801
|
+
this._unloadGroupsAndTriggerWatches();
|
|
756
802
|
|
|
757
|
-
this._onChange(_record_query_result.
|
|
803
|
+
this._onChange(_record_query_result.WatchableRecordQueryResultKeys.groupLevels);
|
|
758
804
|
}
|
|
759
805
|
/** @internal */
|
|
760
806
|
|
|
761
807
|
}, {
|
|
762
808
|
key: "_onGroupsChanged",
|
|
763
809
|
value: function _onGroupsChanged(model, key, updates) {
|
|
764
|
-
this.
|
|
810
|
+
this._unloadGroupsAndTriggerWatches();
|
|
765
811
|
}
|
|
766
812
|
/** @internal */
|
|
767
813
|
|
|
@@ -784,7 +830,11 @@ function (_RecordQueryResult) {
|
|
|
784
830
|
addedRecordIds: _addedRecordIds,
|
|
785
831
|
removedRecordIds: _removedRecordIds
|
|
786
832
|
};
|
|
787
|
-
}
|
|
833
|
+
} // We never need to handle an initial empty update coming from record_store
|
|
834
|
+
// since it does not issue empty initial updates.
|
|
835
|
+
// Keep the if statement for type safety. Invariant would also work, but is riskier.
|
|
836
|
+
// istanbul ignore if
|
|
837
|
+
|
|
788
838
|
|
|
789
839
|
if (!updates) {
|
|
790
840
|
// If there are no updates, do nothing, since we'll handle the initial
|
|
@@ -811,50 +861,50 @@ function (_RecordQueryResult) {
|
|
|
811
861
|
}
|
|
812
862
|
|
|
813
863
|
if (this._recordIdsSet) {
|
|
814
|
-
var
|
|
815
|
-
var
|
|
816
|
-
var
|
|
864
|
+
var _iteratorNormalCompletion9 = true;
|
|
865
|
+
var _didIteratorError9 = false;
|
|
866
|
+
var _iteratorError9 = undefined;
|
|
817
867
|
|
|
818
868
|
try {
|
|
819
|
-
for (var
|
|
820
|
-
var recordId =
|
|
869
|
+
for (var _iterator9 = addedRecordIds[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
|
|
870
|
+
var recordId = _step9.value;
|
|
821
871
|
this._recordIdsSet[recordId] = true;
|
|
822
872
|
}
|
|
823
873
|
} catch (err) {
|
|
824
|
-
|
|
825
|
-
|
|
874
|
+
_didIteratorError9 = true;
|
|
875
|
+
_iteratorError9 = err;
|
|
826
876
|
} finally {
|
|
827
877
|
try {
|
|
828
|
-
if (!
|
|
829
|
-
|
|
878
|
+
if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
|
|
879
|
+
_iterator9.return();
|
|
830
880
|
}
|
|
831
881
|
} finally {
|
|
832
|
-
if (
|
|
833
|
-
throw
|
|
882
|
+
if (_didIteratorError9) {
|
|
883
|
+
throw _iteratorError9;
|
|
834
884
|
}
|
|
835
885
|
}
|
|
836
886
|
}
|
|
837
887
|
|
|
838
|
-
var
|
|
839
|
-
var
|
|
840
|
-
var
|
|
888
|
+
var _iteratorNormalCompletion10 = true;
|
|
889
|
+
var _didIteratorError10 = false;
|
|
890
|
+
var _iteratorError10 = undefined;
|
|
841
891
|
|
|
842
892
|
try {
|
|
843
|
-
for (var
|
|
844
|
-
var _recordId =
|
|
893
|
+
for (var _iterator10 = removedRecordIds[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
|
|
894
|
+
var _recordId = _step10.value;
|
|
845
895
|
this._recordIdsSet[_recordId] = undefined;
|
|
846
896
|
}
|
|
847
897
|
} catch (err) {
|
|
848
|
-
|
|
849
|
-
|
|
898
|
+
_didIteratorError10 = true;
|
|
899
|
+
_iteratorError10 = err;
|
|
850
900
|
} finally {
|
|
851
901
|
try {
|
|
852
|
-
if (!
|
|
853
|
-
|
|
902
|
+
if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
|
|
903
|
+
_iterator10.return();
|
|
854
904
|
}
|
|
855
905
|
} finally {
|
|
856
|
-
if (
|
|
857
|
-
throw
|
|
906
|
+
if (_didIteratorError10) {
|
|
907
|
+
throw _iteratorError10;
|
|
858
908
|
}
|
|
859
909
|
}
|
|
860
910
|
}
|
|
@@ -883,6 +933,10 @@ function (_RecordQueryResult) {
|
|
|
883
933
|
}, {
|
|
884
934
|
key: "_onCellValuesForSortChanged",
|
|
885
935
|
value: function _onCellValuesForSortChanged(recordStore, key, recordIds, fieldId) {
|
|
936
|
+
// We never need to handle an initial empty update coming from record_store
|
|
937
|
+
// since it does not issue empty initial updates.
|
|
938
|
+
// Keep the if statement for type safety. Invariant would also work, but is riskier.
|
|
939
|
+
// istanbul ignore if
|
|
886
940
|
if (!recordIds || !fieldId) {
|
|
887
941
|
// If there are no updates, do nothing, since we'll handle the initial
|
|
888
942
|
// callback when the record set is loaded (and we don't want to fire
|
|
@@ -948,13 +1002,13 @@ function (_RecordQueryResult) {
|
|
|
948
1002
|
// deleted and then undeleted.
|
|
949
1003
|
|
|
950
1004
|
var wereAnyFieldsCreatedOrDeleted = false;
|
|
951
|
-
var
|
|
952
|
-
var
|
|
953
|
-
var
|
|
1005
|
+
var _iteratorNormalCompletion11 = true;
|
|
1006
|
+
var _didIteratorError11 = false;
|
|
1007
|
+
var _iteratorError11 = undefined;
|
|
954
1008
|
|
|
955
1009
|
try {
|
|
956
|
-
for (var
|
|
957
|
-
var fieldId =
|
|
1010
|
+
for (var _iterator11 = addedFieldIds[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
|
|
1011
|
+
var fieldId = _step11.value;
|
|
958
1012
|
|
|
959
1013
|
// If a field that we rely on was created (i.e. it was undeleted), we need to
|
|
960
1014
|
// make sure we're watching it's config.
|
|
@@ -971,16 +1025,16 @@ function (_RecordQueryResult) {
|
|
|
971
1025
|
// istanbul ignore else
|
|
972
1026
|
|
|
973
1027
|
} catch (err) {
|
|
974
|
-
|
|
975
|
-
|
|
1028
|
+
_didIteratorError11 = true;
|
|
1029
|
+
_iteratorError11 = err;
|
|
976
1030
|
} finally {
|
|
977
1031
|
try {
|
|
978
|
-
if (!
|
|
979
|
-
|
|
1032
|
+
if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
|
|
1033
|
+
_iterator11.return();
|
|
980
1034
|
}
|
|
981
1035
|
} finally {
|
|
982
|
-
if (
|
|
983
|
-
throw
|
|
1036
|
+
if (_didIteratorError11) {
|
|
1037
|
+
throw _iteratorError11;
|
|
984
1038
|
}
|
|
985
1039
|
}
|
|
986
1040
|
}
|
|
@@ -1010,34 +1064,6 @@ function (_RecordQueryResult) {
|
|
|
1010
1064
|
}
|
|
1011
1065
|
/** @internal */
|
|
1012
1066
|
|
|
1013
|
-
}, {
|
|
1014
|
-
key: "_onCellValuesChanged",
|
|
1015
|
-
value: function _onCellValuesChanged(table, key, updates) {
|
|
1016
|
-
if (!updates) {
|
|
1017
|
-
// If there are no updates, do nothing, since we'll handle the initial
|
|
1018
|
-
// callback when the record set is loaded (and we don't want to fire
|
|
1019
|
-
// a cellValues change twice with no data).
|
|
1020
|
-
return;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
this._onChange(_record_query_result.default.WatchableKeys.cellValues, updates);
|
|
1024
|
-
}
|
|
1025
|
-
/** @internal */
|
|
1026
|
-
|
|
1027
|
-
}, {
|
|
1028
|
-
key: "_onCellValuesInFieldChanged",
|
|
1029
|
-
value: function _onCellValuesInFieldChanged(table, key, recordIds, fieldId) {
|
|
1030
|
-
if (!recordIds && !fieldId) {
|
|
1031
|
-
// If there are no updates, do nothing, since we'll handle the initial
|
|
1032
|
-
// callback when the record set is loaded (and we don't want to fire
|
|
1033
|
-
// a cellValuesInField change twice with no data).
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
this._onChange(key, recordIds, fieldId);
|
|
1038
|
-
}
|
|
1039
|
-
/** @internal */
|
|
1040
|
-
|
|
1041
1067
|
}, {
|
|
1042
1068
|
key: "_generateOrderedRecordIds",
|
|
1043
1069
|
value: function _generateOrderedRecordIds() {
|
|
@@ -1055,7 +1081,6 @@ function (_RecordQueryResult) {
|
|
|
1055
1081
|
value: function _generateAndLoadOrderedGroups() {
|
|
1056
1082
|
// istanbul ignore next
|
|
1057
1083
|
if (this._groupLevels) {
|
|
1058
|
-
(0, _error_utils.invariant)(this._visList, 'Cannot generate record ids without a vis list');
|
|
1059
1084
|
throw (0, _error_utils.spawnError)('custom group configs not supported');
|
|
1060
1085
|
} else {
|
|
1061
1086
|
// Get the group from the view itself
|
|
@@ -1081,26 +1106,26 @@ function (_RecordQueryResult) {
|
|
|
1081
1106
|
key: "_unloadOrderedGroupsIfNeeded",
|
|
1082
1107
|
value: function _unloadOrderedGroupsIfNeeded() {
|
|
1083
1108
|
if (this._orderedGroups) {
|
|
1084
|
-
var
|
|
1085
|
-
var
|
|
1086
|
-
var
|
|
1109
|
+
var _iteratorNormalCompletion12 = true;
|
|
1110
|
+
var _didIteratorError12 = false;
|
|
1111
|
+
var _iteratorError12 = undefined;
|
|
1087
1112
|
|
|
1088
1113
|
try {
|
|
1089
|
-
for (var
|
|
1090
|
-
var group =
|
|
1114
|
+
for (var _iterator12 = this._orderedGroups[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
|
|
1115
|
+
var group = _step12.value;
|
|
1091
1116
|
group.unloadData();
|
|
1092
1117
|
}
|
|
1093
1118
|
} catch (err) {
|
|
1094
|
-
|
|
1095
|
-
|
|
1119
|
+
_didIteratorError12 = true;
|
|
1120
|
+
_iteratorError12 = err;
|
|
1096
1121
|
} finally {
|
|
1097
1122
|
try {
|
|
1098
|
-
if (!
|
|
1099
|
-
|
|
1123
|
+
if (!_iteratorNormalCompletion12 && _iterator12.return != null) {
|
|
1124
|
+
_iterator12.return();
|
|
1100
1125
|
}
|
|
1101
1126
|
} finally {
|
|
1102
|
-
if (
|
|
1103
|
-
throw
|
|
1127
|
+
if (_didIteratorError12) {
|
|
1128
|
+
throw _iteratorError12;
|
|
1104
1129
|
}
|
|
1105
1130
|
}
|
|
1106
1131
|
}
|
|
@@ -1108,22 +1133,21 @@ function (_RecordQueryResult) {
|
|
|
1108
1133
|
}
|
|
1109
1134
|
/**
|
|
1110
1135
|
* If groupings change then some groups will need to be created, and some removed
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1136
|
+
* Triggers the WatchableKeys.group, as by necessity this will have changed.
|
|
1137
|
+
* TODO: This _should_ handle the diffing necessary to unload, and reload only the changed groups.
|
|
1113
1138
|
*
|
|
1114
1139
|
* @internal
|
|
1115
1140
|
*/
|
|
1116
1141
|
// TODO: (SeanKeenan) Properly diff and only unload groups that need to be unloaded
|
|
1117
1142
|
// In the meantime it's not too expensive to just unload everything, and GroupedRecordQueryResults
|
|
1118
1143
|
// don't yet properly watch changes relevant to updating, so this isn't too bad.
|
|
1119
|
-
// (They do invalidate their recordId caches, which is some very cheap work that we could remove)
|
|
1120
1144
|
|
|
1121
1145
|
}, {
|
|
1122
|
-
key: "
|
|
1123
|
-
value: function
|
|
1146
|
+
key: "_unloadGroupsAndTriggerWatches",
|
|
1147
|
+
value: function _unloadGroupsAndTriggerWatches() {
|
|
1124
1148
|
this._unloadOrderedGroupsIfNeeded();
|
|
1125
1149
|
|
|
1126
|
-
this._orderedGroups =
|
|
1150
|
+
this._orderedGroups = null;
|
|
1127
1151
|
|
|
1128
1152
|
this._onChange(_record_query_result.default.WatchableKeys.groups);
|
|
1129
1153
|
}
|
|
@@ -1133,15 +1157,14 @@ function (_RecordQueryResult) {
|
|
|
1133
1157
|
key: "_replaceVisList",
|
|
1134
1158
|
value: function _replaceVisList() {
|
|
1135
1159
|
var airtableInterface = this._sdk.__airtableInterface;
|
|
1136
|
-
var appInterface = this._sdk.__appInterface;
|
|
1137
1160
|
|
|
1138
|
-
var
|
|
1161
|
+
var recordIds = this._sourceModelRecords.map(record => record.id);
|
|
1139
1162
|
|
|
1140
1163
|
var fieldDatas = this._table.fields.map(field => field._data);
|
|
1141
1164
|
|
|
1142
1165
|
var filteredSorts = this._getSortsWithDeletedFieldsFiltered();
|
|
1143
1166
|
|
|
1144
|
-
this._visList = airtableInterface.
|
|
1167
|
+
this._visList = airtableInterface.createVisListWithRecordIds(recordIds, fieldDatas, filteredSorts, this._table.id);
|
|
1145
1168
|
}
|
|
1146
1169
|
/** @internal */
|
|
1147
1170
|
|
|
@@ -1167,6 +1190,31 @@ function (_RecordQueryResult) {
|
|
|
1167
1190
|
var sourceModelName = this._sourceModel instanceof _table.default ? 'table' : 'view';
|
|
1168
1191
|
return (0, _error_utils.spawnError)("RecordQueryResult's underlying %s has been deleted", sourceModelName);
|
|
1169
1192
|
}
|
|
1193
|
+
/** @internal */
|
|
1194
|
+
|
|
1195
|
+
}, {
|
|
1196
|
+
key: "__constructQuerySpecForBlockFieldSelectionSpec",
|
|
1197
|
+
value: function __constructQuerySpecForBlockFieldSelectionSpec(fieldSelection) {
|
|
1198
|
+
if (this._sourceModel instanceof _view.default) {
|
|
1199
|
+
return {
|
|
1200
|
+
sourceType: _block_query_spec.BlockQuerySourceType.VIEW,
|
|
1201
|
+
sourceTableId: this._table.id,
|
|
1202
|
+
sourceViewId: this._sourceModel.id,
|
|
1203
|
+
recordSelection: {
|
|
1204
|
+
fieldSelection
|
|
1205
|
+
},
|
|
1206
|
+
viewMetadataSelection: {}
|
|
1207
|
+
};
|
|
1208
|
+
} else {
|
|
1209
|
+
return {
|
|
1210
|
+
sourceType: _block_query_spec.BlockQuerySourceType.TABLE,
|
|
1211
|
+
sourceTableId: this._table.id,
|
|
1212
|
+
recordSelection: {
|
|
1213
|
+
fieldSelection
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1170
1218
|
}, {
|
|
1171
1219
|
key: "_dataOrNullIfDeleted",
|
|
1172
1220
|
get: function get() {
|
|
@@ -1175,9 +1223,7 @@ function (_RecordQueryResult) {
|
|
|
1175
1223
|
}
|
|
1176
1224
|
|
|
1177
1225
|
return {
|
|
1178
|
-
recordIds: this._orderedRecordIds
|
|
1179
|
-
groups: this._orderedGroups,
|
|
1180
|
-
groupLevels: this._loadedGroupLevels
|
|
1226
|
+
recordIds: this._orderedRecordIds
|
|
1181
1227
|
};
|
|
1182
1228
|
}
|
|
1183
1229
|
/** @internal */
|
|
@@ -1231,8 +1277,10 @@ function (_RecordQueryResult) {
|
|
|
1231
1277
|
var recordIds = this._data.recordIds; // Throws when the model has been deleted.
|
|
1232
1278
|
|
|
1233
1279
|
(0, _error_utils.invariant)(this.isDataLoaded, 'RecordQueryResult data is not loaded');
|
|
1234
|
-
(0, _error_utils.invariant)(recordIds, 'No recordIds');
|
|
1235
|
-
|
|
1280
|
+
(0, _error_utils.invariant)(recordIds, 'No recordIds'); // TODO: (#proj-blocks-sdk-record-limits) Change this to readonly upon the
|
|
1281
|
+
// next breaking change.
|
|
1282
|
+
|
|
1283
|
+
return [...recordIds];
|
|
1236
1284
|
}
|
|
1237
1285
|
/**
|
|
1238
1286
|
* The ordered GroupedRecordQueryResult's in this RecordQueryResult.
|
|
@@ -1245,12 +1293,19 @@ function (_RecordQueryResult) {
|
|
|
1245
1293
|
}, {
|
|
1246
1294
|
key: "groups",
|
|
1247
1295
|
get: function get() {
|
|
1296
|
+
var _this$_orderedGroups;
|
|
1297
|
+
|
|
1248
1298
|
// The following statements have been carefully sequenced to ensure
|
|
1249
1299
|
// that when this method fails, it reports the most salient error.
|
|
1250
|
-
|
|
1300
|
+
(0, _error_utils.invariant)(this._data, 'RecordQueryResult must not be deleted'); // Throws when the model has been deleted.
|
|
1251
1301
|
|
|
1252
1302
|
(0, _error_utils.invariant)(this.isDataLoaded, 'RecordQueryResult data is not loaded');
|
|
1253
|
-
|
|
1303
|
+
|
|
1304
|
+
if (!this._orderedGroups) {
|
|
1305
|
+
this._orderedGroups = this._generateAndLoadOrderedGroups();
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
return (_this$_orderedGroups = this._orderedGroups) !== null && _this$_orderedGroups !== void 0 ? _this$_orderedGroups : null;
|
|
1254
1309
|
}
|
|
1255
1310
|
/**
|
|
1256
1311
|
* The GroupLevels in this RecordQueryResult.
|
|
@@ -1263,10 +1318,15 @@ function (_RecordQueryResult) {
|
|
|
1263
1318
|
}, {
|
|
1264
1319
|
key: "groupLevels",
|
|
1265
1320
|
get: function get() {
|
|
1266
|
-
|
|
1321
|
+
(0, _error_utils.invariant)(this._data, 'RecordQueryResult must not be deleted'); // Throws when the model has been deleted.
|
|
1267
1322
|
|
|
1268
1323
|
(0, _error_utils.invariant)(this.isDataLoaded, 'RecordQueryResult data is not loaded');
|
|
1269
|
-
|
|
1324
|
+
|
|
1325
|
+
if (!this._loadedGroupLevels) {
|
|
1326
|
+
this._loadedGroupLevels = this._sourceModelGroupLevels;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
return this._loadedGroupLevels ? this._loadedGroupLevels.map(singleLevel => _objectSpread({}, singleLevel, {
|
|
1270
1330
|
field: this.parentTable.getFieldById(singleLevel.fieldId)
|
|
1271
1331
|
})) : null;
|
|
1272
1332
|
}
|
|
@@ -1281,13 +1341,13 @@ function (_RecordQueryResult) {
|
|
|
1281
1341
|
// using RecordQueryResult) if the user had to manually watch for deletion
|
|
1282
1342
|
// on all the fields and recreate the RecordQueryResult.
|
|
1283
1343
|
|
|
1284
|
-
var
|
|
1285
|
-
var
|
|
1286
|
-
var
|
|
1344
|
+
var _iteratorNormalCompletion13 = true;
|
|
1345
|
+
var _didIteratorError13 = false;
|
|
1346
|
+
var _iteratorError13 = undefined;
|
|
1287
1347
|
|
|
1288
1348
|
try {
|
|
1289
|
-
for (var
|
|
1290
|
-
var fieldId =
|
|
1349
|
+
for (var _iterator13 = fieldIdsOrNullIfAllFields[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
|
|
1350
|
+
var fieldId = _step13.value;
|
|
1291
1351
|
|
|
1292
1352
|
var field = this._table.getFieldByIdIfExists(fieldId);
|
|
1293
1353
|
|
|
@@ -1296,16 +1356,16 @@ function (_RecordQueryResult) {
|
|
|
1296
1356
|
}
|
|
1297
1357
|
}
|
|
1298
1358
|
} catch (err) {
|
|
1299
|
-
|
|
1300
|
-
|
|
1359
|
+
_didIteratorError13 = true;
|
|
1360
|
+
_iteratorError13 = err;
|
|
1301
1361
|
} finally {
|
|
1302
1362
|
try {
|
|
1303
|
-
if (!
|
|
1304
|
-
|
|
1363
|
+
if (!_iteratorNormalCompletion13 && _iterator13.return != null) {
|
|
1364
|
+
_iterator13.return();
|
|
1305
1365
|
}
|
|
1306
1366
|
} finally {
|
|
1307
|
-
if (
|
|
1308
|
-
throw
|
|
1367
|
+
if (_didIteratorError13) {
|
|
1368
|
+
throw _iteratorError13;
|
|
1309
1369
|
}
|
|
1310
1370
|
}
|
|
1311
1371
|
}
|
|
@@ -1359,6 +1419,12 @@ function (_RecordQueryResult) {
|
|
|
1359
1419
|
get: function get() {
|
|
1360
1420
|
return this._sourceModel instanceof _table.default ? this._recordStore.records : this._recordStore.getViewDataStore(this._sourceModel.id).visibleRecords;
|
|
1361
1421
|
}
|
|
1422
|
+
/**
|
|
1423
|
+
* This is just a helper structure to better colocate watch and unwatch logic
|
|
1424
|
+
*
|
|
1425
|
+
* @internal
|
|
1426
|
+
*/
|
|
1427
|
+
|
|
1362
1428
|
}]);
|
|
1363
1429
|
return TableOrViewQueryResult;
|
|
1364
1430
|
}(_record_query_result.default);
|