@@ -5,15 +5,6 @@ import React, { Component } from 'react'
55import TreeNode from '../tree-node'
66import { findIndex } from '../utils'
77
8- const shouldRenderNode = ( node , searchModeOn , data ) => {
9- if ( searchModeOn || node . expanded ) return true
10-
11- const parent = node . _parent && data . get ( node . _parent )
12- // if it has a parent, then check parent's state.
13- // otherwise root nodes are always rendered
14- return ! parent || parent . expanded
15- }
16-
178class Tree extends Component {
189 static propTypes = {
1910 data : PropTypes . object ,
@@ -68,6 +59,17 @@ class Tree extends Component {
6859 }
6960 }
7061
62+ shouldRenderNode = ( node , props ) => {
63+ const { data, searchModeOn } = props
64+ const { expanded, _parent } = node
65+ if ( searchModeOn || expanded ) return true
66+
67+ const parent = _parent && data . get ( _parent )
68+ // if it has a parent, then check parent's state.
69+ // otherwise root nodes are always rendered
70+ return ! parent || parent . expanded
71+ }
72+
7173 getNodes = props => {
7274 const {
7375 data,
@@ -86,7 +88,7 @@ class Tree extends Component {
8688 } = props
8789 const items = [ ]
8890 data . forEach ( node => {
89- if ( shouldRenderNode ( node , searchModeOn , data ) ) {
91+ if ( this . shouldRenderNode ( node , props ) ) {
9092 items . push (
9193 < TreeNode
9294 keepTreeOnSearch = { keepTreeOnSearch }
0 commit comments