More debugging
This commit is contained in:
parent
e3775c4c12
commit
39f56d564a
2 changed files with 9 additions and 4 deletions
|
@ -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
|
||||||
|
|
|
@ -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',
|
||||||
|
|
Loading…
Reference in a new issue