export type SyncRequest = { /** The name of the component attribute, e.g. `"position"` or `"position.x"` */ attributeName: string; /** The value of the component attribute derived by the value of the transaction */ attributeValue: any; /** The index of the component */ componentIndex: number; /** The module id of the component */ moduleId: string; /** The decimal precision of floats, defaults to 4 */ precision?: number; }; export type Transaction = { /** The object to modify */ object: T; /** The value of the transaction */ value: U; /** Read from the object into a serializable format */ /** Write a value on the object from the format resolved by the read property */ write: (root: T, data: U) => void; /** Whether a historic entry should be recorded, `true` by default */ createHistoryRecord?: boolean; /** The sync configuration. If undefined, the change will not be persisted to disk */ sync?: Omit; } & ({ read: (root: T) => U; } | { historicValue: U; }); export type TransactionQueueCommitArgs = Transaction[]; /** * The TransactionQueue class is a queue of transactions that can be undone and * redone. A transaction is a change to a value that can be undone and redone. * The root of a transaction as well as the data is completely arbitrary. * * ### Committing a transaction * * To commit a transaction, you must provide the root object, the data to write, * a function to read the data from the root object, and a function to write the * data to the root object. * * @example * Single object in single commit * ```ts * const obj = { * foo: { * bar: 'baz', * }, * } * * const transactionQueue = new TransactionQueue() * transactionQueue.commit( * obj, * 'quo', * (obj) => obj.foo.bar, * (obj, value) => (obj.foo.bar = value), * ) * * expect(obj.foo.bar).toBe('quo') * ``` * * @example * Multiple objects in single commit * ```ts * const arr = [{ foo: 'bar' }, { foo: 'baz' }] * * const transactionQueue = new TransactionQueue() * transactionQueue.commit( * arr, * arr.map(() => 'qux'), * (arr) => arr.map((obj) => obj.foo), * (arr, data) => arr.forEach((obj, i) => (obj.foo = data[i])), * ) * * expect(arr[0].foo).toBe('qux') * expect(arr[1].foo).toBe('qux') * ``` */ export declare class TransactionQueue { /** Queue of transactions that have been commited and can be undone */ private commitedQueue; /** Queue of transactions that have been undone and can be redone */ private undoneQueue; syncQueue: SyncRequest[]; private syncTimeout; private onCommitCallbacks; onCommit(callback: (transactions: Transaction[]) => void): () => void; private onUndoCallbacks; onUndo(callback: (transactions: Transaction[]) => void): () => void; private onRedoCallbacks; onRedo(callback: (transactions: Transaction[]) => void): () => void; private onTransactionCallbacks; onTransaction(callback: (transactions: Transaction[]) => void): () => void; commit(transactions: TransactionQueueCommitArgs): void; get canUndo(): boolean; undo(): void; get canRedo(): boolean; redo(): void; addSyncRequest(request: SyncRequest): void; sync(): void; private doSync; }