-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Add an XMLEditor class which internally uses our handleEdit function in order to provide:
- a
transactmethod used to transact newEdits by callinghandleEditwhile recording that edit in - an undo stack "
past" containing already transactedEdits, - a redo stack "
future" containing already undoneEdits, - an
undomethod which moves the most recentpastedit to the top of thefuturestack, transacting the undo edit and returning the new most recent transaction record, if any, - a
redomethod which moves the nextfutureedit in line to the top of thepaststack, transacting the redo edit and returning the new most recent transaction record, - a
canUndoboolean property indicating presence ofpastedits toundo, - a
canRedoboolean property indicating presence offutureedits toredo, - and a way to add and remove "transacted" callbacks, which it calls passing the new most recent transaction record whenever
edit,undo, orredohave been called, so that users may be notified of transactions.
Apart from the Edit to commit, the edit method should also allow the user to specify an optional string title for the transaction, and to indicate by optional boolean flag whether to squash the current transaction onto the last committed transaction, rolling them into a single undo entry and updating the title if given.
Given our EditV2 class and the types
// Transaction intent in flight
export interface Transaction<Change> {
change: Change;
title?: string;
squash?: boolean;
}
// record of committed Transaction
export interface TransactionRecord<Change> {
changes: Change[];
title?: string;
txID: number;
}
export type TransactedCallback<Change> = (txRecord: TransactionRecord<Change>) => void;
export interface Transactor<Change> {
transact(tx: Transaction<Change>): TransactionRecord<Change>; // May throw - duck!
undo(): TransactionRecord<Change> | undefined;
redo(): TransactionRecord<Change>;
canUndo: boolean;
canRedo: boolean;
past: TransactionRecord[];
future: TransactionRecord[];
addTransactedCallback(txCallback: TransactedCallback): void;
removeTransactedCallback(txCallback: TransactedCallback): void;
}our class should implement
export class XMLEditor implements Transactor<EditV2>Metadata
Metadata
Assignees
Labels
No labels