Adds migration for documents

This commit is contained in:
Steve Ruiz 2021-10-28 22:49:00 +01:00
parent 5901035214
commit 10d0a5f5a1
6 changed files with 31909 additions and 3 deletions

View file

@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { TLDrawState } from '~state'
import type { TLDrawDocument } from '~types'
import oldDoc from '../test/old-doc.json'
describe('When migrating bindings', () => {
it('migrates', () => {
Object.values((oldDoc as TLDrawDocument).pages).forEach((page) => {
Object.values(page.bindings).forEach((binding) => {
if ('meta' in binding) {
// @ts-ignore
Object.assign(binding, binding.meta)
}
})
})
new TLDrawState().loadDocument(oldDoc)
})
})

View file

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { StateManager } from 'rko'
import { Vec } from '@tldraw/vec'
@ -99,6 +100,15 @@ export class TLDrawState extends StateManager<Data> {
onUserChange?: (tlstate: TLDrawState, user: TLDrawUser) => void
) {
super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => {
Object.values(prev.document.pages).forEach((page) => {
Object.values(page.bindings).forEach((binding) => {
if ('meta' in binding) {
// @ts-ignore
Object.assign(binding, binding.meta)
}
})
})
return {
...next,
document: { ...next.document, ...prev.document },
@ -2446,7 +2456,7 @@ export class TLDrawState extends StateManager<Data> {
}
}
static version = 10.5
static version = 11
static defaultDocument: TLDrawDocument = {
id: 'doc',

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long