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

Common

listenersEvents

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.

ParameterTypeDescription
transactionTransaction
Returns: String

Revisions

revisionsEnabled: Boolean= false

Enables revision tracking by STM

Misc

Properties

22

Class hierarchy

isStateTrackingManager: Boolean= truereadonly
Identifies an object as an instance of StateTrackingManager class, or subclass thereof.
isStateTrackingManager: Boolean= truereadonlystatic
Identifies an object as an instance of StateTrackingManager class, or subclass thereof.
isEventsEvents

Other

Gets/sets manager auto record option

canRedo: Boolean

Checks if the manager can redo.

canUndo: Boolean

Checks if the manager can undo.

Get/set manager disabled state

isReady: Booleanreadonly

Checks manager ready state

isRecording: Booleanreadonly

Checks manager recording state

isRestoring: Booleanreadonly

Gets manager restoring state.

length: Number

Gets current undo/redo queue length

position: Number

Gets current undo/redo queue position

queue: String[]readonly

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.

Lifecycle

configBase

Misc

Functions

41

Other

Adds a store instance to the manager

const stm = new StateTrackingManager({ ... })
const store = new Store({ ... });
stm.addStore(store);
ParameterTypeDescription
storeStore

Disables manager

Enables manager

Calls fn for each store registered in STM.

ParameterTypeDescription
fnfunction

(store, id) => ...

Checks if a store has been added to the manager

ParameterTypeDescription
storeStore
Returns: Boolean

Merges all update actions into one per model, keeping the oldest and the newest values.

Redoes current undo/redo transaction.

ParameterTypeDescription
stepsNumber
Returns: Promise -

A promise which is resolved when redo action has been performed

Redoes all transactions.

Returns: Promise -

A promise which is resolved when redo actions has been performed

Rejects currently recorded transaction.

Removes a store from the manager

ParameterTypeDescription
storeStore

Resets undo/redo queue.

Resets redo queue.

Resets undo queue.

Starts undo/redo recording transaction.

ParameterTypeDescription
titleString

Stops undo/redo recording transaction

ParameterTypeDescription
titleString

Undoes current undo/redo transaction.

ParameterTypeDescription
stepsNumber
Returns: Promise -

A promise which is resolved when undo action has been performed

Undoes all transactions.

Returns: Promise -

A promise which is resolved when undo actions has been performed

onEvents
relayAllEvents
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase

Events

9

Fired when the disabled state of the STM changes

// Adding a listener using the "on" method
stateTrackingManager.on('disabled', ({ source, disabled }) => {

});
ParameterTypeDescription
sourceStateTrackingManager
disabledBoolean

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 }) => {

});
ParameterTypeDescription
stmStateTrackingManager

Fired upon state recording operation starts.

// Adding a listener using the "on" method
stateTrackingManager.on('recordingStart', ({ stm, transaction }) => {

});
ParameterTypeDescription
stmStateTrackingManager
transactionTransaction

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 }) => {

});
ParameterTypeDescription
stmStateTrackingManager
transactionTransaction
reasonObject

Transaction stop reason

reason.stopBoolean

Transaction recording has been stopped in a normal way.

reason.disabledBoolean

Transaction recording has been stopped due to STM has been disabled.

reason.rejectedBoolean

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 }) => {

});
ParameterTypeDescription
stmStateTrackingManager

Fired upon state restoration operation stops.

// Adding a listener using the "on" method
stateTrackingManager.on('restoringStop', ({ stm }) => {

});
ParameterTypeDescription
stmStateTrackingManager
catchAllEvents
destroyEvents

Event handlers

9

Called when the disabled state of the STM changes

new StateTrackingManager({
    onDisabled({ source, disabled }) {

    }
});
ParameterTypeDescription
sourceStateTrackingManager
disabledBoolean

The current disabled state of the STM

Called upon state undo/redo queue reset.

new StateTrackingManager({
    onQueueReset({ stm }) {

    }
});
ParameterTypeDescription
stmStateTrackingManager

Called upon state recording operation starts.

new StateTrackingManager({
    onRecordingStart({ stm, transaction }) {

    }
});
ParameterTypeDescription
stmStateTrackingManager
transactionTransaction

Called upon state recording operation stops.

new StateTrackingManager({
    onRecordingStop({ stm, transaction, reason }) {

    }
});
ParameterTypeDescription
stmStateTrackingManager
transactionTransaction
reasonObject

Transaction stop reason

reason.stopBoolean

Transaction recording has been stopped in a normal way.

reason.disabledBoolean

Transaction recording has been stopped due to STM has been disabled.

reason.rejectedBoolean

Transaction recording has been stopped due to transaction has been rejected.

Called upon state restoration operation starts.

new StateTrackingManager({
    onRestoringStart({ stm }) {

    }
});
ParameterTypeDescription
stmStateTrackingManager

Called upon state restoration operation stops.

new StateTrackingManager({
    onRestoringStop({ stm }) {

    }
});
ParameterTypeDescription
stmStateTrackingManager
onDestroyEvents

Typedefs

1