More debugging

This commit is contained in:
Steve Ruiz 2021-11-05 07:03:44 +00:00
parent e3775c4c12
commit 39f56d564a
2 changed files with 9 additions and 4 deletions

View file

@ -4,9 +4,11 @@ import { Decoration, TLDrawDocument, TLDrawShapeType } from '~types'
export function migrate(document: TLDrawDocument, newVersion: number): TLDrawDocument { export function migrate(document: TLDrawDocument, newVersion: number): TLDrawDocument {
const { version = 0 } = document const { version = 0 } = document
console.log(`Migrating document from ${version} to ${newVersion}.`)
if (version === newVersion) return document if (version === newVersion) return document
if (version <= 12) { if (version <= 13) {
Object.values(document.pages).forEach((page) => { Object.values(document.pages).forEach((page) => {
Object.values(page.bindings).forEach((binding) => { Object.values(page.bindings).forEach((binding) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View file

@ -100,10 +100,13 @@ export class TLDrawState extends StateManager<Data> {
onChange?: (tlstate: TLDrawState, data: Data, reason: string) => void, onChange?: (tlstate: TLDrawState, data: Data, reason: string) => void,
onUserChange?: (tlstate: TLDrawState, user: TLDrawUser) => void onUserChange?: (tlstate: TLDrawState, user: TLDrawUser) => void
) { ) {
super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => { super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next, prevVersion) => {
return { return {
...next, ...next,
document: migrate({ ...next.document, ...prev.document, version: 0 }, TLDrawState.version), document: migrate(
{ ...next.document, ...prev.document, version: prevVersion },
TLDrawState.version
),
} }
}) })
@ -2458,7 +2461,7 @@ export class TLDrawState extends StateManager<Data> {
} }
} }
static version = 12.6 static version = 13
static defaultDocument: TLDrawDocument = { static defaultDocument: TLDrawDocument = {
id: 'doc', id: 'doc',