in packages/redux-dag-history/src/DagGraph.ts [32:67]
public print(): string {
const graph = this.graph.toJS()
let root: any = null
const states: { [key: string]: any } = {}
const getOrCreateState = (stateId: StateId) => {
let result = states[stateId]
if (!result) {
result = {
id: stateId,
name: this.stateName(stateId),
children: [] as StateId[],
}
states[stateId] = result
}
return result
}
Object.keys(graph.states || {}).forEach(stateId => {
const parentId = graph.states[stateId].parent
const state = getOrCreateState(stateId)
if (!parentId) {
root = state
}
getOrCreateState(parentId).children.push(state)
states[stateId] = state
})
const tree = {
current: graph.current,
chronologicalStates: graph.chronologicalStates,
branches: graph.branches,
states: graph.states,
dag: root,
}
return JSON.stringify(tree, null, 4)
}