Skip to content

Commit

Permalink
Merge pull request #69 from CrazyFork/dev
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
e1emeb0t authored Oct 31, 2016
2 parents 2dcfcdb + 53ba08d commit e6a765f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
4 changes: 4 additions & 0 deletions libs/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export function watchPropertyChange(target, property, cb) {
let origin = target[property]

Object.defineProperty(target, property, {
configurable: true,

get() {
return origin
},
Expand All @@ -46,6 +48,8 @@ export function watchPropertyChange(target, property, cb) {
return ()=>{
if (target.__watch_cache && target.__watch_cache[property]){
delete target.__watch_cache[property]
delete target[property]
target[property] = origin
}
}
}
Expand Down
31 changes: 16 additions & 15 deletions src/tree/Node.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ReactTransitionGroup from 'react-addons-transition-group'

import { PropTypes, Component } from '../../libs';
import {watchPropertyChange} from '../../libs/utils'
import { watchPropertyChange } from '../../libs/utils'
import CollapseTransition from './CollapseTransition'


Expand All @@ -11,13 +11,13 @@ function FirstChild(props) {
return childrenArray[0] || null;
}

function NodeContent(props){
function NodeContent(props) {
const {nodeModel, renderContent, context} = props

if (typeof renderContent === 'function' ){
if (typeof renderContent === 'function') {
return renderContent(Object.freeze(context))
}else{
return <span className="el-tree-node__label">{ nodeModel.label }</span>
} else {
return <span className="el-tree-node__label">{nodeModel.label}</span>
}
}

Expand Down Expand Up @@ -61,8 +61,8 @@ export default class Node extends Component {
}),
}

if (nodeModel.data != null){
this.watchers.c = watchPropertyChange(nodeModel.data, childrenKey, () =>{
if (nodeModel.data != null) {
this.watchers.c = watchPropertyChange(nodeModel.data, childrenKey, () => {
nodeModel.updateChildren()
this.setState({})//force update view
})
Expand Down Expand Up @@ -155,9 +155,9 @@ export default class Node extends Component {
</div>
<ReactTransitionGroup
component={FirstChild}>
<CollapseTransition>
{
expanded && (
{
expanded && (
<CollapseTransition>
<div
className="el-tree-node__children">
{
Expand All @@ -167,9 +167,10 @@ export default class Node extends Component {
})
}
</div>
)
}
</CollapseTransition>

</CollapseTransition>
)
}
</ReactTransitionGroup>
</div>
)
Expand All @@ -190,7 +191,7 @@ Node.propTypes = {
Node.defaultProps = {
nodeModel: {},
options: {},
onCheckChange(){},
onNodeClicked(){},
onCheckChange() { },
onNodeClicked() { },
}

0 comments on commit e6a765f

Please sign in to comment.