Skip to content

Commit 5eacc2a

Browse files
author
lewis617
committed
remove constructor
1 parent baae702 commit 5eacc2a

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

todo/dist/app.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,10 @@ webpackJsonp([0],{
7575
var Todo = function (_React$Component) {
7676
_inherits(Todo, _React$Component);
7777

78-
function Todo(props) {
78+
function Todo() {
7979
_classCallCheck(this, Todo);
8080

81-
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Todo).call(this, props));
82-
83-
_this.state = { list: [] };
84-
return _this;
81+
return _possibleConstructorReturn(this, Object.getPrototypeOf(Todo).apply(this, arguments));
8582
}
8683

8784
_createClass(Todo, [{
@@ -106,6 +103,21 @@ webpackJsonp([0],{
106103
value: function render() {
107104
var _this2 = this;
108105

106+
var items = undefined;
107+
if (this.state.list) {
108+
items = this.state.list.map(function (item, i) {
109+
return _react2.default.createElement(
110+
'li',
111+
{ key: i },
112+
item.name,
113+
_react2.default.createElement(
114+
'button',
115+
{ onClick: _this2.remove.bind(_this2, i) },
116+
'remove'
117+
)
118+
);
119+
});
120+
}
109121
return _react2.default.createElement(
110122
'div',
111123
null,
@@ -118,18 +130,7 @@ webpackJsonp([0],{
118130
_react2.default.createElement(
119131
'ul',
120132
null,
121-
this.state.list.map(function (item, i) {
122-
return _react2.default.createElement(
123-
'li',
124-
{ key: i },
125-
item.name,
126-
_react2.default.createElement(
127-
'button',
128-
{ onClick: _this2.remove.bind(_this2, i) },
129-
'remove'
130-
)
131-
);
132-
})
133+
items
133134
)
134135
);
135136
}

todo/src/components/todo.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import store from '../stores/store'
55
import actions from '../actions/actions'
66

77
export default class Todo extends React.Component{
8-
constructor(props) {
9-
super(props);
10-
this.state = {list: []};
11-
}
128

139
componentDidMount() {
1410
actions.getAll();
@@ -26,17 +22,21 @@ export default class Todo extends React.Component{
2622
}
2723

2824
render() {
25+
let items;
26+
if(this.state.list){
27+
items=this.state.list.map( (item,i)=> {
28+
return <li key={i}>
29+
{item.name}
30+
<button onClick={this.remove.bind(this,i)}>remove</button>
31+
</li>
32+
})
33+
}
2934
return (
3035
<div>
3136
<input type="text" ref="item"/>
3237
<button onClick={this.add.bind(this)}>add</button>
3338
<ul>
34-
{this.state.list.map( (item,i)=> {
35-
return <li key={i}>
36-
{item.name}
37-
<button onClick={this.remove.bind(this,i)}>remove</button>
38-
</li>
39-
})}
39+
{items}
4040
</ul>
4141
</div>
4242
)

0 commit comments

Comments
 (0)