igniteui-angular
Version:
Ignite UI for Angular is a dependency-free Angular toolkit for building modern web apps
110 lines (109 loc) • 4.09 kB
TypeScript
import { Transaction, State, Action } from './transaction';
import { IgxBaseTransactionService } from './base-transaction';
export declare class IgxTransactionService<T extends Transaction, S extends State> extends IgxBaseTransactionService<T, S> {
protected _transactions: T[];
protected _redoStack: Action<T>[][];
protected _undoStack: Action<T>[][];
protected _states: Map<any, S>;
/**
* @returns if there are any transactions in the Undo stack
*/
get canUndo(): boolean;
/**
* @returns if there are any transactions in the Redo stack
*/
get canRedo(): boolean;
/**
* Adds provided transaction with recordRef if any
*
* @param transaction Transaction to be added
* @param recordRef Reference to the value of the record in the data source related to the changed item
*/
add(transaction: T, recordRef?: any): void;
/**
* Returns all recorded transactions in chronological order
*
* @param id Optional record id to get transactions for
* @returns All transaction in the service or for the specified record
*/
getTransactionLog(id?: any): T[];
/**
* Returns aggregated changes from all transactions
*
* @param mergeChanges If set to true will merge each state's value over relate recordRef
* and will record resulting value in the related transaction
* @returns Collection of aggregated transactions for each changed record
*/
getAggregatedChanges(mergeChanges: boolean): T[];
/**
* Returns the state of the record with provided id
*
* @param id The id of the record
* @param pending Should get pending state
* @returns State of the record if any
*/
getState(id: any, pending?: boolean): S;
/**
* Returns whether transaction is enabled for this service
*/
get enabled(): boolean;
/**
* Returns value of the required id including all uncommitted changes
*
* @param id The id of the record to return value for
* @param mergeChanges If set to true will merge state's value over relate recordRef
* and will return merged value
* @returns Value with changes or **null**
*/
getAggregatedValue(id: any, mergeChanges: boolean): any;
/**
* Clears all pending transactions and aggregated pending state. If commit is set to true
* commits pending states as single transaction
*
* @param commit Should commit the pending states
*/
endPending(commit: boolean): void;
/**
* Applies all transactions over the provided data
*
* @param data Data source to update
* @param id Optional record id to commit transactions for
*/
commit(data: any[], id?: any): void;
/**
* Clears all transactions
*
* @param id Optional record id to clear transactions for
*/
clear(id?: any): void;
/**
* Remove the last transaction if any
*/
undo(): void;
/**
* Applies the last undone transaction if any
*/
redo(): void;
protected addTransaction(transaction: T, states: Map<any, S>, recordRef?: any): void;
/**
* Verifies if the passed transaction is correct. If not throws an exception.
*
* @param transaction Transaction to be verified
*/
protected verifyAddedTransaction(states: Map<any, S>, transaction: T, recordRef?: any): void;
/**
* Updates the provided states collection according to passed transaction and recordRef
*
* @param states States collection to apply the update to
* @param transaction Transaction to apply to the current state
* @param recordRef Reference to the value of the record in data source, if any, where transaction should be applied
*/
protected updateState(states: Map<any, S>, transaction: T, recordRef?: any): void;
/**
* Updates state related record in the provided data
*
* @param data Data source to update
* @param state State to update data from
*/
protected updateRecord(data: any[], state: S): void;
}