Migrate snapshot (#1843)
Add `Store.migrateSnapshot`, another surface API alongside getSnapshot and loadSnapshot. ### Change Type - [x] `minor` — New feature ### Release Notes - [editor] add `Store.migrateSnapshot`
This commit is contained in:
parent
0b3e83be52
commit
48a1bb4d88
7 changed files with 126 additions and 13 deletions
|
@ -2495,9 +2495,9 @@ export type TLStoreOptions = {
|
|||
initialData?: SerializedStore<TLRecord>;
|
||||
defaultName?: string;
|
||||
} & ({
|
||||
schema: StoreSchema<TLRecord, TLStoreProps>;
|
||||
schema?: StoreSchema<TLRecord, TLStoreProps>;
|
||||
} | {
|
||||
shapeUtils: readonly TLAnyShapeUtilConstructor[];
|
||||
shapeUtils?: readonly TLAnyShapeUtilConstructor[];
|
||||
});
|
||||
|
||||
// @public (undocumented)
|
||||
|
|
|
@ -15,8 +15,8 @@ export type TLStoreOptions = {
|
|||
initialData?: SerializedStore<TLRecord>
|
||||
defaultName?: string
|
||||
} & (
|
||||
| { shapeUtils: readonly TLAnyShapeUtilConstructor[] }
|
||||
| { schema: StoreSchema<TLRecord, TLStoreProps> }
|
||||
| { shapeUtils?: readonly TLAnyShapeUtilConstructor[] }
|
||||
| { schema?: StoreSchema<TLRecord, TLStoreProps> }
|
||||
)
|
||||
|
||||
/** @public */
|
||||
|
@ -30,11 +30,16 @@ export type TLStoreEventInfo = HistoryEntry<TLRecord>
|
|||
* @public */
|
||||
export function createTLStore({ initialData, defaultName = '', ...rest }: TLStoreOptions): TLStore {
|
||||
const schema =
|
||||
'schema' in rest
|
||||
? rest.schema
|
||||
: createTLSchema({
|
||||
shapes: currentPageShapesToShapeMap(checkShapesAndAddCore(rest.shapeUtils)),
|
||||
'schema' in rest && rest.schema
|
||||
? // we have a schema
|
||||
rest.schema
|
||||
: // we need a schema
|
||||
createTLSchema({
|
||||
shapes: currentPageShapesToShapeMap(
|
||||
checkShapesAndAddCore('shapeUtils' in rest && rest.shapeUtils ? rest.shapeUtils : [])
|
||||
),
|
||||
})
|
||||
|
||||
return new Store({
|
||||
schema,
|
||||
initialData,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue