[perf] deleteShapes (#1373)

This PR extracts a static query for the page states that are used when
deleting a shape.

### Change Type

<!-- 💡 Indicate the type of change your pull request is. -->
<!-- 🤷‍♀️ If you're not sure, don't select anything -->
<!-- ✂️ Feel free to delete unselected options -->

<!-- To select one, put an x in the box: [x] -->

- [x] `patch` — Bug Fix

### Release Notes

- Perf improvement for deleting shapes in a document with lots of pages.
This commit is contained in:
David Sheldrick 2023-05-15 11:02:24 +01:00 committed by GitHub
parent bd455b0b8b
commit fff9c4c09b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1296,6 +1296,10 @@ export class App extends EventEmitter<TLEventMap> {
// const update = this.getShapeUtil(next).onUpdate?.(prev, next)
// return update ?? next
// }
@computed
private get _allPageStates() {
return this.store.query.records('instance_page_state')
}
/** @internal */
private _shapeWillBeDeleted(deletedShape: TLShape) {
@ -1312,8 +1316,8 @@ export class App extends EventEmitter<TLEventMap> {
this._unbindArrowTerminal(arrow, handleId)
}
}
const pageStates = this._allPageStates.value
const pageStates = this.store.query.records('instance_page_state').value
const deletedIds = new Set([deletedShape.id])
const updates = compact(
pageStates.map((pageState) => {