Skip to content

Commit

Permalink
Added state selection event
Browse files Browse the repository at this point in the history
  • Loading branch information
coolwr committed Jul 15, 2019
1 parent ce36c43 commit 9cba09f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@statecharts/xstate-viz",
"version": "0.1.2",
"name": "@sierralabs/xstate-viz",
"version": "0.2.1",
"description": "Visualizer for XState.",
"main": "lib/index.js",
"scripts": {
Expand Down
21 changes: 20 additions & 1 deletion src/StateChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,33 @@ export class StateChart extends React.Component<
}
);
}
onSelectionChange(stateChartNode: StateChartNode) {
selectStateNodePath(path: string[]) {
for (const stateChartNode of this.stateChartNodes) {
let index = 0;
for (const part of path) {
// attempt to match all path parts
if (stateChartNode.props.stateNode.path[index] !== part) {
break; // not a match
} else if (index === path.length - 1) {
// found the stateChartNode to select
this.changeSelection(stateChartNode);
return;
}
index++;
}
}
}
changeSelection(stateChartNode: StateChartNode) {
if (this.selected) {
// unselect previous state
this.selected.setState({ selected: false });
}
// set the current selected state
stateChartNode.setState({ selected: true });
this.selected = stateChartNode;
}
onSelectionChange(stateChartNode: StateChartNode) {
this.changeSelection(stateChartNode);
// notify a start chart was selected
if (this.props.onSelectionChange) {
this.props.onSelectionChange(stateChartNode);
Expand Down

0 comments on commit 9cba09f

Please sign in to comment.