StateTrackingManager
StateTrackingManager subclass that's aware of the Scheduler Pro data structure specifics, namely supports tracking of event segment changes.
There is normally no need to deal with this class manually since it's instantiated automatically by the project and can be reached like this:
project.stm
Tracking store changes
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();
}
},
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();
Resetting the queue on data loading
When loading data from the server it makes perfect sense to reset the queue.
If project (CrudManager protocol) is used for data loading it can be done like this:
project.on({
load() {
project.stm.resetQueue();
}
});
and in case individual stores are used:
ajaxStore.on({
load() {
ajaxStore.stm.resetQueue();
}
});
See also
- ProTransaction — Scheduler Pro transaction that filters calculated actions
- ProjectModel — The project whose stores are tracked for undo/redo
- StateTrackingManager — The base STM manager class
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Internal listeners, that cannot be removed by the user.
-
Specifies minimum length of last transactions
Has a corresponding runtime revisionQueueCommittedMinLength property.
-
Specifies length of the transaction queue when cleanup will be triggered
Has a corresponding runtime revisionQueueMaxLength property.
-
Enables revision tracking by STM
-
The transaction duration (in ms) for the auto recording mode autoRecord
-
Default manager disabled state
Has a corresponding runtime disabled property.
-
Store insert child model action factory.
-
Store remove child model action factory.
-
Store model update action factory
-
Store add model action factory.
-
Store insert model action factory.
-
Store remove model action factory.
-
Store remove all models action factory.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of Events class, or subclass thereof.
-
Identifies an object as an instance of StateTrackingManager class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of StateTrackingManager class, or subclass thereof.
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
Specifies minimum length of last transactions
Has a corresponding revisionQueueCommittedMinLength config.
-
Specifies length of the transaction queue when cleanup will be triggered
Has a corresponding revisionQueueMaxLength config.
-
Gets/sets manager auto record option
Has a corresponding autoRecord config.
-
Checks if the manager can redo.
-
Checks if the manager can undo.
-
Get/set manager disabled state
Has a corresponding disabled config.
-
Checks if STM is restoring a stash
-
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 the current state of the manager
-
Gets all the stores registered in STM
-
Gets currently recording STM transaction.
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Registers this class type with its Factory
-
Internal function used to hook destroy() calls when using thisObj
-
Internal function used restore hooked destroy() calls when using thisObj
-
Auto detaches listeners registered from start, if set as detachable
-
Internal function used to run a callback function after an event is triggered
-
Removes all listeners registered to this object by the application.
-
Clears committed revisions, we only need to use last one.
-
This method creates special conflict resolution revision which contains only conflict resolution actions. It is linked to the revision with a conflict via
conflictResolutionForproperty. Such revision cannot be rolled back locally because it will introduce the same conflict again. -
This method creates special data revision which has no input state, only a data correction for a case when applying remote revisions lead to new changes. This revision will be sent, it should be persisted on the backend, and any client applying it should not see any changes after.
-
Disables manager
-
Enables manager
-
Used to distinguish user input from values calculated by the project. If any actions in the revision are marked as user input then checkout logic will only use user input. If nothing is marked, then revision is not treated specially.
-
Merges all update actions into one per model, keeping the oldest and the newest values.
-
Rejects currently recorded transaction.
-
Resets undo/redo queue.
-
Resets redo queue.
-
Resets undo queue.
-
Stops undo/redo recording transaction after autoRecordTransactionStopTimeout delay.