Skip to content

Commit d707561

Browse files
committed
Type trrack tree output
1 parent 8d9ed34 commit d707561

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

apps/react-trrack-example/src/app/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Typography,
99
} from '@mui/material';
1010

11-
import { HistoryTree, type HistoryNode } from './components/HistoryTree';
11+
import { HistoryTree } from './components/HistoryTree';
1212
import { Navbar } from './components/Navbar';
1313
import { useTrrackTaskManager } from './store/trrack';
1414

@@ -67,7 +67,7 @@ function App() {
6767
</List>
6868
<HistoryTree
6969
currentNodeId={trrack.current.id}
70-
root={trrack.tree() as HistoryNode}
70+
root={trrack.tree()}
7171
onSelect={(id) => trrackManager.trrack.to(id)}
7272
/>
7373
</Box>

apps/react-trrack-example/src/app/components/HistoryTree.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
import { type TrrackTreeNode } from '@trrack/core';
12
import { List, ListItemButton, ListItemText } from '@mui/material';
23

3-
export type HistoryNode = {
4-
id: string;
5-
label: string;
6-
children: HistoryNode[];
7-
};
4+
export type HistoryNode = TrrackTreeNode<unknown, string>;
85

96
function HistoryTreeBranch({
107
currentNodeId,

packages/core/src/provenance/trrack.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import { applyPatch, compare, deepClone, Operation } from 'fast-json-patch';
3-
import { RecordActionArgs, Trrack } from './types';
3+
import { RecordActionArgs, Trrack, TrrackTreeNode } from './types';
44
import { PayloadAction } from '../action';
55

66
import { initEventManager } from '../event';
@@ -464,15 +464,10 @@ function isNextNodeUp(
464464
);
465465
}
466466

467-
type TreeNode = Omit<ProvenanceNode<any, any>, 'children' | 'name'> & {
468-
name: string;
469-
children: TreeNode[];
470-
};
471-
472467
function getTreeFromNode(
473468
node: ProvenanceNode<any, any>,
474469
nodes: Nodes<any, any>
475-
): TreeNode {
470+
): TrrackTreeNode<any, any> {
476471
return {
477472
...node,
478473
children: node.children.map((n) => getTreeFromNode(nodes[n], nodes)),

packages/core/src/provenance/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ export type RecordActionArgs<State, Event extends string> = {
2222
onlySideEffects?: boolean;
2323
};
2424

25+
export type TrrackTreeNode<State, Event extends string> = Omit<
26+
ProvenanceNode<State, Event>,
27+
'children'
28+
> & {
29+
name: string;
30+
children: TrrackTreeNode<State, Event>[];
31+
};
32+
2533
export interface Trrack<State, Event extends string> {
2634
registry: Registry<Event>;
2735
isTraversing: boolean;
@@ -72,7 +80,7 @@ export interface Trrack<State, Event extends string> {
7280
skipOnNew?: boolean
7381
): UnsubscribeCurrentChangeListener;
7482
done(): void;
75-
tree(): unknown;
83+
tree(): TrrackTreeNode<State, Event>;
7684
on(event: TrrackEvents, listener: (args?: unknown) => void): void;
7785
export(): string;
7886
exportObject(): ProvenanceGraph<State, Event>;

0 commit comments

Comments
 (0)