Trrack
State
After creating the registry and registering actions, you can initialize a
Trrack instance.
Along with the registry, you also need your application state.
type State = {
// Model your application state here. Flat structures are usually best for
// modular updates and smaller diffs.
};
const state: State = {
// Initialize your application state here.
};Trrack Instance
Now with the registry and state, initialize Trrack:
import { initializeTrrack } from '@trrack/core';
const trrack = initializeTrrack({
initialState: state,
registry,
});Listener
Trrack provides a listener to subscribe to state changes. State changes happen when moving between nodes in the provenance graph because of a new node, an undo, or a redo.
trrack.currentChange(() => {
// Respond to state changes here
});You can register multiple listeners and Trrack will call them all in order.
Accessing Current State
Trrack stores state as either a full snapshot or a diff from the previous state. You can access the current state with:
const state = trrack.getState();Traversal
You can jump to any node in the provenance graph using to:
trrack.to(nodeId);Trrack also provides helper methods to undo and redo:
trrack.undo();
trrack.redo();Last updated on