Skip to content

Commit

Permalink
feat(example): remove handler
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Jul 25, 2019
1 parent 295b76b commit d587b13
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions example/SimpleGraph.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PureComponent } from 'react';

import Graph, { isEdge } from '../src';
import Graph, { isEdge, isNode } from '../src';
// import Graph from '../dist/ReactGraph';

const SpecialNode = ({ data, onChange, styles }) => (
Expand Down Expand Up @@ -98,12 +98,26 @@ class App extends PureComponent {
this.graphInstance.zoomOut();
}

onElementsRemove(elements) {
const nodeIds = elements.filter(isNode).map(n => n.id);

this.setState(prevState => ({
elements: prevState.elements.filter(e => {
return (
!nodeIds.includes(e.id) &&
!nodeIds.includes(e.target) &&
!nodeIds.includes(e.source)
);
})
}));
}

render() {
return (
<Graph
elements={this.state.elements}
onElementClick={node => console.log('clicked', node)}
onElementsRemove={elements => console.log('remove', elements)}
onElementsRemove={elements => this.onElementsRemove(elements)}
style={{ width: '100%', height: '100%' }}
onLoad={graphInstance => this.onLoad(graphInstance)}
onChange={(elements) => this.onChange(elements)}
Expand Down

0 comments on commit d587b13

Please sign in to comment.