Skip to content

Commit

Permalink
feat(treenode): 注册ContextTypes以保证Tree和TreeNode通过context进行信息的交互
Browse files Browse the repository at this point in the history
  • Loading branch information
beth committed May 19, 2018
1 parent 970cce7 commit ba90a34
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/component/Head/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Head extends Component {
title: '我是默认名字'
}

constructor() {
super();
constructor(props) {
super(props);
this.state = {
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/component/Menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Menu extends Component {
}

constructor(props) {
super();
super(props);
this.state = {
checkedKeys: [],
data: [],
Expand Down
14 changes: 7 additions & 7 deletions src/component/Tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export const contextTypes = {
}

class Tree extends Component {
// static propTypes = {
// className: PropTypes.string,
// checkedKeys: PropTypes.any,
// onCheck: PropTypes.func,
// children: PropTypes.any
// }
static propTypes = {
className: PropTypes.string,
checkedKeys: PropTypes.any,
onCheck: PropTypes.func,
children: PropTypes.any
}

static childContextTypes = contextTypes;

constructor(props) {
super();
super(props);
this.state = {
expandedKeys: [],
selectedKeys: [],
Expand Down
30 changes: 30 additions & 0 deletions src/component/Tree/treeNode.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { contextTypes } from './index';
import {
toArray,
getNodeChildren,
} from './utils';
import './index.css';

export const nodeContextTypes = {
...contextTypes,
bTreeNode: PropTypes.shape({
onUpCheckConduct: PropTypes.func,
})
};

class TreeNode extends Component {
static propTypes = {
currentIndex: PropTypes.string,
Expand All @@ -15,6 +23,28 @@ class TreeNode extends Component {
children: PropTypes.any
}

static contextTypes = nodeContextTypes;

static childContextTypes = nodeContextTypes;

constructor(props) {
super(props);
console.log(this.context);

this.state = {};
}

getChildContext() {
return {
...this.context,
bTreeNode: {
onUpCheckConduct: this.onUpCheckConduct,
},
}
}

onUpCheckConduct = () => {}

renderCheckbox = () => {
return (
<input type="checkbox" />
Expand Down

0 comments on commit ba90a34

Please sign in to comment.