Recording a navigable history of the stream of states
The Aurelia Store plugin provides a powerful feature for recording and navigating through the history of state changes in your application. This can be incredibly useful for debugging, implementing undo/redo functionality, and gaining insights into how your application's state evolves over time.
To enable history tracking, you need to configure it during the plugin registration in your main.ts
file:
Explanation:
history: { undoable: true }
: This option tells the Aurelia Store plugin to start recording the history of state changes.
The StateHistory<T>
Object
StateHistory<T>
ObjectWhen history is enabled, the state
property of the store (which you subscribe to) will no longer emit simple State
objects. Instead, it will emit StateHistory<State>
objects. The StateHistory
interface looks like this:
Explanation:
past: T[]
: An array of previous states, representing the history of state changes.present: T
: The current state of the application.future: T[]
: An array of states that have been undone (using thejump
action, which we'll discuss later). These states can be "redone" by moving them back to thepresent
.
Example:
In this example, the state
property of the App
component will now hold a StateHistory<State>
object, giving you access to the past
, present
, and future
states.
Last updated
Was this helpful?