StateTrackingManager
Tracks the state of every store registered via addStore. It is disabled by default so remember to call enable when your stores are registered and initial dataset is loaded. Use undo / redo method calls to restore state to a particular point in time
stm = new StateTrackingManager({
autoRecord : true,
listeners : {
recordingStop() {
// your custom code to update undo/redo GUI controls
updateUndoRedoControls();
},
restoringStop({ stm }) {
// your custom code to update undo/redo GUI controls
updateUndoRedoControls();
},
disabled() {
// in Gantt, Scheduler and other scheduling products,
// also need to update the undo/redo controls on `disabled`
// event, due to implementation details
updateUndoRedoControls();
}
},
getTransactionTitle(transaction) {
// your custom code to analyze the transaction and return custom transaction title
const lastAction = transaction.queue[transaction.queue.length - 1];
if (lastAction instanceof AddAction) {
let title = 'Add new record';
}
return title;
}
});
stm.addStore(userStore);
stm.addStore(companyStore);
stm.addStore(otherStore);
stm.enable();
Note: STM currently does not support undoing server side added and saved records. Therefore it's recommended to reset the queue each time a tracked store(s) loads from or saves its changes to the server. If Crud Manager is used it can be done like this:
crudManager.on({
requestDone() {
stm.resetQueue();
}
});
and in case individual stores are used:
ajaxStore.on({
afterRequest({ exception }) {
if (!exception) {
stm.resetQueue();
}
}
});
Configs
10
Configs
10Common
Other
Whether to start transaction recording automatically in case the Manager is enabled.
In the auto recording mode, the manager waits for the first change in any store being managed and starts a transaction, i.e. records any changes in its monitored stores. The transaction lasts for autoRecordTransactionStopTimeout and afterward creates one undo/redo step, including all changes in the stores during that period of time.
In non auto recording mode you have to call startTransaction / stopTransaction to start and end a transaction.
NOTE, enabling this option, will not enable the STM itself. This should be done with a separate call
to enable method or by assigning false to disabled property. If
you don't enable the STM, it will not be tracking changes in the data.
If you use the UndoRedo widget in your app, it will enable STM automatically, on the load event of
the project's crud manager (in the gantt case, the project is the crud manager). In other cases, you need
to enable STM manually.
By the end of a transaction, with this config set to true, all model update actions will be merged to
one action per model. Only the initial start value and the last change will be kept.
If non auto recording mode, you can call mergeTransactionUpdateActions.
The transaction duration (in ms) for the auto recording mode autoRecord
Default manager disabled state
Function to create a transaction title if none is provided. The function receives a transaction and should return a title.
| Parameter | Type | Description |
|---|---|---|
transaction | Transaction |
Revisions
Enables revision tracking by STM
Properties
22
Properties
22Class hierarchy
Other
Gets/sets manager auto record option
Checks if the manager can redo.
Checks if the manager can undo.
Get/set manager disabled state
Checks manager ready state
Checks manager recording state
Gets manager restoring state.
Gets current undo/redo queue length
Gets current undo/redo queue position
Gets titles of all recorded undo/redo transactions
Gets currently recording STM transaction.
Misc
Functions
41
Functions
41Other
Adds a store instance to the manager
const stm = new StateTrackingManager({ ... })
const store = new Store({ ... });
stm.addStore(store);
| Parameter | Type | Description |
|---|---|---|
store | Store |
Disables manager
Enables manager
Calls fn for each store registered in STM.
| Parameter | Type | Description |
|---|---|---|
fn | function | (store, id) => ... |
Merges all update actions into one per model, keeping the oldest and the newest values.
Redoes current undo/redo transaction.
| Parameter | Type | Description |
|---|---|---|
steps | Number |
A promise which is resolved when redo action has been performed
Redoes all transactions.
A promise which is resolved when redo actions has been performed
Rejects currently recorded transaction.
Resets undo/redo queue.
Resets redo queue.
Resets undo queue.
Undoes current undo/redo transaction.
| Parameter | Type | Description |
|---|---|---|
steps | Number |
A promise which is resolved when undo action has been performed
Undoes all transactions.
A promise which is resolved when undo actions has been performed
Configuration
Events
Events
9
Events
9Fired when the disabled state of the STM changes
// Adding a listener using the "on" method
stateTrackingManager.on('disabled', ({ source, disabled }) => {
});| Parameter | Type | Description |
|---|---|---|
source | StateTrackingManager | |
disabled | Boolean | The current disabled state of the STM |
Fired upon state undo/redo queue reset.
// Adding a listener using the "on" method
stateTrackingManager.on('queueReset', ({ stm }) => {
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager |
Fired upon state recording operation starts.
// Adding a listener using the "on" method
stateTrackingManager.on('recordingStart', ({ stm, transaction }) => {
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager | |
transaction | Transaction |
Fired upon state recording operation stops.
// Adding a listener using the "on" method
stateTrackingManager.on('recordingStop', ({ stm, transaction, reason, reason.stop, reason.disabled, reason.rejected }) => {
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager | |
transaction | Transaction | |
reason | Object | Transaction stop reason |
reason.stop | Boolean | Transaction recording has been stopped in a normal way. |
reason.disabled | Boolean | Transaction recording has been stopped due to STM has been disabled. |
reason.rejected | Boolean | Transaction recording has been stopped due to transaction has been rejected. |
Fired upon state restoration operation starts.
// Adding a listener using the "on" method
stateTrackingManager.on('restoringStart', ({ stm }) => {
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager |
Fired upon state restoration operation stops.
// Adding a listener using the "on" method
stateTrackingManager.on('restoringStop', ({ stm }) => {
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager |
Event handlers
9
Event handlers
9Called when the disabled state of the STM changes
new StateTrackingManager({
onDisabled({ source, disabled }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | StateTrackingManager | |
disabled | Boolean | The current disabled state of the STM |
Called upon state undo/redo queue reset.
new StateTrackingManager({
onQueueReset({ stm }) {
}
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager |
Called upon state recording operation starts.
new StateTrackingManager({
onRecordingStart({ stm, transaction }) {
}
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager | |
transaction | Transaction |
Called upon state recording operation stops.
new StateTrackingManager({
onRecordingStop({ stm, transaction, reason }) {
}
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager | |
transaction | Transaction | |
reason | Object | Transaction stop reason |
reason.stop | Boolean | Transaction recording has been stopped in a normal way. |
reason.disabled | Boolean | Transaction recording has been stopped due to STM has been disabled. |
reason.rejected | Boolean | Transaction recording has been stopped due to transaction has been rejected. |
Called upon state restoration operation starts.
new StateTrackingManager({
onRestoringStart({ stm }) {
}
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager |
Called upon state restoration operation stops.
new StateTrackingManager({
onRestoringStop({ stm }) {
}
});| Parameter | Type | Description |
|---|---|---|
stm | StateTrackingManager |