streaksheet
Advanced tools
Comparing version 0.7.34 to 0.7.35
@@ -49,7 +49,6 @@ import * as React from 'react'; | ||
export interface StartedRowsRequest { | ||
sectionKey: string; | ||
startIndex: number; | ||
countHint: number; | ||
abortController: AbortController | null; | ||
removerAbortController: AbortController; | ||
removerAbortController: AbortController | null; | ||
} | ||
@@ -56,0 +55,0 @@ export interface StartedRowsRequests { |
@@ -40,2 +40,3 @@ import SectionRowMatcher from './SectionRowMatcher'; | ||
getCopyString(row: T, columnKey: string): string; | ||
loadRows?(sectionKey: string, keys: string[]): void; | ||
unloadRows?(sectionKey: string, keys: string[]): void; | ||
@@ -42,0 +43,0 @@ } |
@@ -69,3 +69,5 @@ "use strict"; | ||
refreshColumnAndOverviewData = options.refreshColumnAndOverviewData; | ||
var unloadRows = options.dataHandler.unloadRows; | ||
var _options$dataHandler = options.dataHandler, | ||
loadRows = _options$dataHandler.loadRows, | ||
unloadRows = _options$dataHandler.unloadRows; | ||
@@ -334,5 +336,7 @@ var _useState = (0, _react.useState)({}), | ||
var nextStreakSheetId = (0, _react.useRef)(0); | ||
var storeRowsForRequest = (0, _react.useCallback)(function (rowsResult, request) { | ||
if (request.abortController && request.abortController.signal.aborted) return; | ||
var nextStreakSheetId = (0, _react.useRef)(0); // todo add in sectionKey to this method as a param | ||
var storeRowsForRequest = (0, _react.useCallback)(function (rowsResult, sectionKey, request) { | ||
var removerAbortController = new AbortController(); | ||
request.removerAbortController = removerAbortController; | ||
request.abortController = null; | ||
@@ -348,3 +352,3 @@ request.countHint = rowsResult.rows.length; | ||
}; | ||
var rowsChunk = Object.prototype.hasOwnProperty.call(rowsBySection, request.sectionKey) ? rowsBySection[request.sectionKey] : []; | ||
var rowsChunk = Object.prototype.hasOwnProperty.call(rowsBySection, sectionKey) ? rowsBySection[sectionKey] : []; | ||
var indexToInsertAt = (0, _sortedIndexBy["default"])(rowsChunk, newEntry, function (e) { | ||
@@ -354,9 +358,12 @@ return e.startIndex; | ||
var newRowsChunk = [].concat((0, _toConsumableArray2["default"])(rowsChunk.slice(0, indexToInsertAt)), [newEntry], (0, _toConsumableArray2["default"])(rowsChunk.slice(indexToInsertAt))); | ||
return _objectSpread(_objectSpread({}, rowsBySection), {}, (0, _defineProperty2["default"])({}, request.sectionKey, newRowsChunk)); | ||
return _objectSpread(_objectSpread({}, rowsBySection), {}, (0, _defineProperty2["default"])({}, sectionKey, newRowsChunk)); | ||
}); | ||
(0, _addEventListenerOnce["default"])(request.removerAbortController.signal, 'abort', function () { | ||
loadRows === null || loadRows === void 0 ? void 0 : loadRows(sectionKey, rowsResult.rows.map(function (r) { | ||
return r.key; | ||
})); | ||
(0, _addEventListenerOnce["default"])(removerAbortController.signal, 'abort', function () { | ||
var locallyRemovedKeys = new Set(); | ||
if (Object.prototype.hasOwnProperty.call(rowsBySection, request.sectionKey)) { | ||
locallyRemovedKeys = new Set((0, _flatMap["default"])(rowsBySection[request.sectionKey], function (rowChunk) { | ||
if (Object.prototype.hasOwnProperty.call(rowsBySection, sectionKey)) { | ||
locallyRemovedKeys = new Set((0, _flatMap["default"])(rowsBySection[sectionKey], function (rowChunk) { | ||
return rowChunk.rowsResult.rows; | ||
@@ -371,4 +378,4 @@ }).filter(function (row) { | ||
setRowsBySection(function (rowsBySection) { | ||
if (Object.prototype.hasOwnProperty.call(rowsBySection, request.sectionKey)) { | ||
var newRowsChunk = rowsBySection[request.sectionKey].filter(function (rowsChunk) { | ||
if (Object.prototype.hasOwnProperty.call(rowsBySection, sectionKey)) { | ||
var newRowsChunk = rowsBySection[sectionKey].filter(function (rowsChunk) { | ||
return rowsChunk.startIndex !== request.startIndex; | ||
@@ -378,7 +385,7 @@ }); | ||
if (newRowsChunk.length) { | ||
return _objectSpread(_objectSpread({}, rowsBySection), {}, (0, _defineProperty2["default"])({}, request.sectionKey, newRowsChunk)); | ||
return _objectSpread(_objectSpread({}, rowsBySection), {}, (0, _defineProperty2["default"])({}, sectionKey, newRowsChunk)); | ||
} else { | ||
var newRowsBySection = _objectSpread({}, rowsBySection); | ||
delete newRowsBySection[request.sectionKey]; | ||
delete newRowsBySection[sectionKey]; | ||
return newRowsBySection; | ||
@@ -395,5 +402,5 @@ } | ||
}); | ||
unloadRows === null || unloadRows === void 0 ? void 0 : unloadRows(request.sectionKey, undeletedKeysForRequest); | ||
unloadRows === null || unloadRows === void 0 ? void 0 : unloadRows(sectionKey, undeletedKeysForRequest); | ||
}); | ||
}, [rowsBySection, unloadRows]); // This function is used inside useByStreaksheet. It needs to reference | ||
}, [loadRows, rowsBySection, unloadRows]); // This function is used inside useByStreaksheet. It needs to reference | ||
// the latest state. This is a bit gross, sorry. | ||
@@ -431,6 +438,6 @@ | ||
startedRowsRequests[sectionKey].forEach(function (request) { | ||
var _request$abortControl2; | ||
var _request$abortControl2, _request$removerAbort; | ||
(_request$abortControl2 = request.abortController) === null || _request$abortControl2 === void 0 ? void 0 : _request$abortControl2.abort(); | ||
request.removerAbortController.abort(); | ||
(_request$removerAbort = request.removerAbortController) === null || _request$removerAbort === void 0 ? void 0 : _request$removerAbort.abort(); | ||
}); | ||
@@ -440,6 +447,6 @@ delete startedRowsRequests[sectionKey]; | ||
(0, _pullAt["default"])(startedRowsRequests[sectionKey], requestIndexes).forEach(function (request) { | ||
var _request$abortControl3; | ||
var _request$abortControl3, _request$removerAbort2; | ||
(_request$abortControl3 = request.abortController) === null || _request$abortControl3 === void 0 ? void 0 : _request$abortControl3.abort(); | ||
request.removerAbortController.abort(); | ||
(_request$removerAbort2 = request.removerAbortController) === null || _request$removerAbort2 === void 0 ? void 0 : _request$removerAbort2.abort(); | ||
}); | ||
@@ -469,9 +476,7 @@ | ||
var abortController = new AbortController(); | ||
var removerAbortController = new AbortController(); | ||
var request = { | ||
sectionKey: section.key, | ||
startIndex: missingRows.startRowIndex, | ||
countHint: missingRows.count, | ||
abortController: abortController, | ||
removerAbortController: removerAbortController | ||
removerAbortController: null | ||
}; | ||
@@ -488,8 +493,7 @@ | ||
dataHandler.getRows(request.sectionKey, request.startIndex, request.countHint, request.abortController.signal).then(function (rowsResult) { | ||
return storeRowsForRequest(rowsResult, request); | ||
dataHandler.getRows(section.key, request.startIndex, request.countHint, request.abortController.signal).then(function (rowsResult) { | ||
if (abortController.signal.aborted) return; | ||
storeRowsForRequest(rowsResult, section.key, request); | ||
}, function (err) { | ||
var _request$abortControl4; | ||
if ((_request$abortControl4 = request.abortController) === null || _request$abortControl4 === void 0 ? void 0 : _request$abortControl4.signal.aborted) return; | ||
if (abortController.signal.aborted) return; | ||
throw err; | ||
@@ -531,3 +535,4 @@ }); | ||
var refreshRows = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var sectionKeys, rowRequestPromises, i, startedRequestsForSection; | ||
var sectionKeys, rowRequestPromises, _loop, i; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
@@ -540,4 +545,5 @@ while (1) { | ||
for (i = 0; i < sectionKeys.length; i++) { | ||
startedRequestsForSection = startedRowsRequests[sectionKeys[i]]; | ||
_loop = function _loop(i) { | ||
var sectionKey = sectionKeys[i]; | ||
var startedRequestsForSection = startedRowsRequests[sectionKey]; | ||
startedRequestsForSection.forEach(function (rowRequest) { | ||
@@ -547,20 +553,25 @@ var _rowRequest$abortCont; | ||
(_rowRequest$abortCont = rowRequest.abortController) === null || _rowRequest$abortCont === void 0 ? void 0 : _rowRequest$abortCont.abort(); | ||
rowRequest.abortController = new AbortController(); | ||
rowRequestPromises.push(options.dataHandler.getRows(rowRequest.sectionKey, rowRequest.startIndex, rowRequest.countHint, rowRequest.abortController.signal).then(function (rowsResult) { | ||
rowRequest.removerAbortController.abort(); | ||
rowRequest.removerAbortController = new AbortController(); | ||
storeRowsForRequest(rowsResult, rowRequest); | ||
var abortController = new AbortController(); | ||
rowRequest.abortController = abortController; | ||
rowRequestPromises.push(options.dataHandler.getRows(sectionKey, rowRequest.startIndex, rowRequest.countHint, rowRequest.abortController.signal).then(function (rowsResult) { | ||
var _rowRequest$removerAb; | ||
if (abortController.signal.aborted) return; | ||
(_rowRequest$removerAb = rowRequest.removerAbortController) === null || _rowRequest$removerAb === void 0 ? void 0 : _rowRequest$removerAb.abort(); | ||
storeRowsForRequest(rowsResult, sectionKey, rowRequest); | ||
}, function (err) { | ||
var _rowRequest$abortCont2; | ||
if ((_rowRequest$abortCont2 = rowRequest.abortController) === null || _rowRequest$abortCont2 === void 0 ? void 0 : _rowRequest$abortCont2.signal.aborted) return; | ||
if (abortController.signal.aborted) return; | ||
throw err; | ||
})); | ||
}); | ||
}; | ||
for (i = 0; i < sectionKeys.length; i++) { | ||
_loop(i); | ||
} | ||
_context.next = 5; | ||
_context.next = 6; | ||
return Promise.all(rowRequestPromises); | ||
case 5: | ||
case 6: | ||
case "end": | ||
@@ -567,0 +578,0 @@ return _context.stop(); |
{ | ||
"name": "streaksheet", | ||
"version": "0.7.34", | ||
"version": "0.7.35", | ||
"author": "Chris Cowan <agentme49@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
487011
4277