Fix changing a setting preventing page content from being replaced (#447)

* Fix setting settings preventing UI from updating

* Add tests for replacePageContent
This commit is contained in:
Milo Hill 2021-12-15 21:14:40 +00:00 committed by GitHub
parent ec203332de
commit 1271070798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 4 deletions

View file

@ -658,4 +658,31 @@ describe('TldrawTestApp', () => {
}, 100)
})
})
describe('When replacing the page content', () => {
it('Should update the page with the correct shapes and bindings.', () => {
const shapes = mockDocument.pages.page1.shapes
const bindings = mockDocument.pages.page1.bindings
const app = new TldrawTestApp('multiplayer', {
onChangePage: () => {},
}).createPage()
app.replacePageContent(shapes, bindings)
expect(app.shapes).toEqual(Object.values(shapes))
expect(app.bindings).toEqual(Object.values(bindings))
})
it('It should update the page shapes after the settings have been updated', () => {
const shapes = mockDocument.pages.page1.shapes
const bindings = mockDocument.pages.page1.bindings
const app = new TldrawTestApp('multiplayer', {
onChangePage: () => {},
}).createPage()
app.setSetting('isDebugMode', true)
app.replacePageContent(shapes, bindings)
expect(app.shapes).toEqual(Object.values(shapes))
expect(app.bindings).toEqual(Object.values(bindings))
})
})
})

View file

@ -540,10 +540,13 @@ export class TldrawApp extends StateManager<TDSnapshot> {
changedBindings[id] = undefined
})
this.justSent = true
this.callbacks.onChangePage?.(this, changedShapes, changedBindings)
this.prevShapes = this.page.shapes
this.prevBindings = this.page.bindings
// Only trigger update if shapes or bindings have changed
if (Object.keys(changedBindings).length > 0 || Object.keys(changedShapes).length > 0) {
this.justSent = true
this.callbacks.onChangePage?.(this, changedShapes, changedBindings)
this.prevShapes = this.page.shapes
this.prevBindings = this.page.bindings
}
}
getReservedContent = (ids: string[], pageId = this.currentPageId) => {