UNPKG

@infinite-canvas-tutorial/webcomponents

Version:
56 lines (55 loc) 2.21 kB
/** * Borrow from https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/store.ts */ import { SerializedNode } from '@infinite-canvas-tutorial/ecs'; import { EventEmitter } from 'eventemitter3'; import { AppState } from '../context'; import { Snapshot } from './Snapshot'; export declare const StoreIncrementEvent = "storeIncrement"; export type ValueOf<T> = T[keyof T]; export declare const CaptureUpdateAction: { /** * Immediately undoable. * * Use for updates which should be captured. * Should be used for most of the local updates. * * These updates will _immediately_ make it to the local undo / redo stacks. */ readonly IMMEDIATELY: "IMMEDIATELY"; /** * Never undoable. * * Use for updates which should never be recorded, such as remote updates * or scene initialization. * * These updates will _never_ make it to the local undo / redo stacks. */ readonly NEVER: "NEVER"; /** * Eventually undoable. * * Use for updates which should not be captured immediately - likely * exceptions which are part of some async multi-step process. Otherwise, all * such updates would end up being captured with the next * `CaptureUpdateAction.IMMEDIATELY` - triggered either by the next `updateScene` * or internally by the editor. * * These updates will _eventually_ make it to the local undo / redo stacks. */ readonly EVENTUALLY: "EVENTUALLY"; }; export type CaptureUpdateActionType = ValueOf<typeof CaptureUpdateAction>; export declare class Store { private _snapshot; private scheduledActions; onStoreIncrementEmitter: EventEmitter<string | symbol, any>; get snapshot(): Snapshot; set snapshot(snapshot: Snapshot); private scheduleAction; shouldCaptureIncrement(): void; shouldUpdateSnapshot(): void; commit(elements: Map<string, SerializedNode> | undefined, appState: AppState | undefined): void; captureIncrement(elements: Map<string, SerializedNode> | undefined, appState: AppState | undefined): void; updateSnapshot(elements: Map<string, SerializedNode> | undefined, appState: AppState | undefined): void; }