Return a changelog of actions that happened from a function call. #821
Replies: 2 comments 1 reply
-
That's an interesting idea and definitely a topic we should consider while planning future features related to tracking changes made in the cells. |
Beta Was this translation helpful? Give feedback.
-
Well, no, those are not two sources of truth. You don't read the same property, for example, IMO You have everything you need to shift the data correctly. It's the very same input a function removeRows(sheetId, rowsToRemove) {
hfInstance.removeRows(sheetId, rowsToRemove)
const { height } = hfInstance.getSheetDimensions(sheetId)
const shiftedRows = [ ]
for (let i = 0; i < height; i++) {
if (i > rowsToRemove[0]) {
shiftedRows.push({ old: i, new: i - rowsToRemove[1] })
}
}
return shiftedRows
} Skipped some edge cases for brevity. And for thousands of rows it's a long collection of indexes we could calculate anyway. IMO unnecessary overhead and memory footprint. What you need is Unit of Work pattern to keep them in sync. Alter both with a single transaction or rollback if any of storages fails to apply changes. Or just keep them next to each other and they will stay in sync class HyperFormulaCalculationService implements CalculationService {
#hyperformula: HyperFormula
#styles: StylesStorage
removeRows(sheetId: number, indexes: ColumnRowIndex[][]) {
this.#hyperformula.removeRows()
this.#styles.removeRows()
}
} |
Beta Was this translation helpful? Give feedback.
-
So this is a follow up discussion to this one here: #739
The fundamental issue is keeping Hyperformula in sync with a spreadsheet that has extra data with it such as styles and comments. I am sure you guys at Handsontable have the same issue. I proposed a solution in 739 that was not really in hyperformula's scope.
Example:
hyperformula.removeRows()
and the values in hyperformula automatically shifts everything up a row. However we have to keep our cell styles in sync with this so we then have to write code that shifts the cell styles up a row. This is bad because there are 2 sources of truth and the cell styles can now get out of sync with hyperformula values. The same issue occurs in copy/cut/paste.Proposed solution:
removeRows
it would be good if it could also return a 'changelog' of the actions that happened. I.e forremoveRows(this.sheet.sheetId, [ 1, 1, ])
it would return this:This way in our spreadsheet we can just read the old values and the new values and shift our data up by the same amount. Keeping everything in sync. This solves the 'keeping in sync' issue and does not bloat hyperformula with stuff that slows down performance.
Let me know your thoughts on this.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions