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

* Fix setting settings preventing UI from updating

* Add tests for replacePageContent
pull/449/head
Milo Hill 2021-12-15 21:14:40 +00:00 zatwierdzone przez GitHub
rodzic ec203332de
commit 1271070798
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 34 dodań i 4 usunięć

Wyświetl plik

@ -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))
})
})
})

Wyświetl plik

@ -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) => {