@@ -10,7 +10,7 @@ import TransitionGroupWrapper from './TransitionGroupWrapper';
1010import Node from '../Node' ;
1111import Link from '../Link' ;
1212import { TreeNodeDatum , Point , RawNodeDatum } from '../types/common' ;
13- import { TreeLinkEventCallback , TreeProps } from './types' ;
13+ import { TreeLinkEventCallback , TreeNodeEventCallback , TreeProps } from './types' ;
1414import globalCss from '../globalCss' ;
1515
1616type TreeState = {
@@ -303,15 +303,12 @@ class Tree extends React.Component<TreeProps, TreeState> {
303303 /**
304304 * Handles the user-defined `onNodeClick` function.
305305 */
306- handleOnNodeClickCb = ( nodeId : string , evt : SyntheticEvent ) => {
306+ handleOnNodeClickCb : TreeNodeEventCallback = ( hierarchyPointNode , evt ) => {
307307 const { onNodeClick } = this . props ;
308308 if ( onNodeClick && typeof onNodeClick === 'function' ) {
309- const data = clone ( this . state . data ) ;
310- const matches = this . findNodesById ( nodeId , data , [ ] ) ;
311- const targetNode = matches [ 0 ] ;
312309 // Persist the SyntheticEvent for downstream handling by users.
313310 evt . persist ( ) ;
314- onNodeClick ( clone ( targetNode ) , evt ) ;
311+ onNodeClick ( clone ( hierarchyPointNode ) , evt ) ;
315312 }
316313 } ;
317314
@@ -330,15 +327,12 @@ class Tree extends React.Component<TreeProps, TreeState> {
330327 /**
331328 * Handles the user-defined `onNodeMouseOver` function.
332329 */
333- handleOnNodeMouseOverCb = ( nodeId : string , evt : SyntheticEvent ) => {
330+ handleOnNodeMouseOverCb : TreeNodeEventCallback = ( hierarchyPointNode , evt ) => {
334331 const { onNodeMouseOver } = this . props ;
335332 if ( onNodeMouseOver && typeof onNodeMouseOver === 'function' ) {
336- const data = clone ( this . state . data ) ;
337- const matches = this . findNodesById ( nodeId , data , [ ] ) ;
338- const targetNode = matches [ 0 ] ;
339333 // Persist the SyntheticEvent for downstream handling by users.
340334 evt . persist ( ) ;
341- onNodeMouseOver ( clone ( targetNode ) , evt ) ;
335+ onNodeMouseOver ( clone ( hierarchyPointNode ) , evt ) ;
342336 }
343337 } ;
344338
@@ -357,15 +351,12 @@ class Tree extends React.Component<TreeProps, TreeState> {
357351 /**
358352 * Handles the user-defined `onNodeMouseOut` function.
359353 */
360- handleOnNodeMouseOutCb = ( nodeId : string , evt : SyntheticEvent ) => {
354+ handleOnNodeMouseOutCb : TreeNodeEventCallback = ( hierarchyPointNode , evt ) => {
361355 const { onNodeMouseOut } = this . props ;
362356 if ( onNodeMouseOut && typeof onNodeMouseOut === 'function' ) {
363- const data = clone ( this . state . data ) ;
364- const matches = this . findNodesById ( nodeId , data , [ ] ) ;
365- const targetNode = matches [ 0 ] ;
366357 // Persist the SyntheticEvent for downstream handling by users.
367358 evt . persist ( ) ;
368- onNodeMouseOut ( clone ( targetNode ) , evt ) ;
359+ onNodeMouseOut ( clone ( hierarchyPointNode ) , evt ) ;
369360 }
370361 } ;
371362
@@ -509,12 +500,14 @@ class Tree extends React.Component<TreeProps, TreeState> {
509500 ) ;
510501 } ) }
511502
512- { nodes . map ( ( { data, x, y, parent, ...rest } , i ) => {
503+ { nodes . map ( ( hierarchyPointNode , i ) => {
504+ const { data, x, y, parent } = hierarchyPointNode ;
513505 return (
514506 < Node
515507 key = { 'node-' + i }
516508 data = { data }
517509 position = { { x, y } }
510+ hierarchyPointNode = { hierarchyPointNode }
518511 parent = { parent }
519512 nodeClassName = { this . getNodeClassName ( parent , data ) }
520513 renderCustomNodeElement = { renderCustomNodeElement }
0 commit comments