fixes migration bug?

This commit is contained in:
Steve Ruiz 2021-11-05 06:52:28 +00:00
parent 795936f8f1
commit 25cd388ff3
4 changed files with 16778 additions and 3 deletions

View file

@ -103,7 +103,7 @@ export class TLDrawState extends StateManager<Data> {
super(TLDrawState.defaultState, id, TLDrawState.version, (prev, next) => {
return {
...next,
document: { ...next.document, ...prev.document },
document: { ...next.document, ...prev.document, version: prev.document.version },
}
})
@ -129,6 +129,7 @@ export class TLDrawState extends StateManager<Data> {
})
} catch (e) {
console.error('The data appears to be corrupted. Resetting!', e)
localStorage.setItem(this.document.id + '_corrupted', JSON.stringify(this.document))
this.patchState({
...TLDrawState.defaultState,
@ -2457,7 +2458,7 @@ export class TLDrawState extends StateManager<Data> {
}
}
static version = 12.5
static version = 12.6
static defaultDocument: TLDrawDocument = {
id: 'doc',

View file

@ -2,6 +2,7 @@
import { TLDrawState } from '~state'
import type { TLDrawDocument } from '~types'
import oldDoc from './old-doc'
import oldDoc2 from './old-doc-2'
describe('When migrating bindings', () => {
it('migrates', () => {
@ -16,4 +17,19 @@ describe('When migrating bindings', () => {
new TLDrawState().loadDocument(oldDoc as unknown as TLDrawDocument)
})
it('migrates older document', () => {
// Object.values((oldDoc as unknown as TLDrawDocument).pages).forEach((page) => {
// Object.values(page.bindings).forEach((binding) => {
// if ('meta' in binding) {
// // @ts-ignore
// Object.assign(binding, binding.meta)
// }
// })
// })
const tlstate = new TLDrawState().loadDocument(oldDoc2 as unknown as TLDrawDocument)
expect(tlstate.getShape('d7ab0a49-3cb3-43ae-3d83-f5cf2f4a510a').style.color).toBe('black')
})
})

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"include": ["src", "src/test/*.json"],
"exclude": ["node_modules", "dist", "docs"],
"compilerOptions": {
"resolveJsonModule": true,