Skip to content

Commit 6e752f4

Browse files
committed
fix: Remove occurrences of componentWillMount and replace with DidMount
#134
1 parent 414bb9c commit 6e752f4

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

src/components/BoardContainer.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ import * as boardActions from '../actions/BoardActions'
1515
import * as laneActions from '../actions/LaneActions'
1616

1717
class BoardContainer extends Component {
18-
//+add 2018.08.23
1918
state = {
2019
addLaneMode: false
2120
}
2221

23-
//+end
24-
componentWillMount() {
22+
componentDidMount() {
2523
const {actions, eventBusHandle} = this.props
2624
actions.loadBoard(this.props.data)
2725
if (eventBusHandle) {
@@ -48,8 +46,7 @@ class BoardContainer extends Component {
4846

4947
onLaneDrop = ({removedIndex, addedIndex, payload}) => {
5048
const {actions, handleLaneDragEnd} = this.props
51-
if (removedIndex !== addedIndex) {// 2018.08.22
52-
// actions.moveLane({oldIndex: removedIndex, newIndex: addedIndex});
49+
if (removedIndex !== addedIndex) {
5350
handleLaneDragEnd(removedIndex, addedIndex, payload)
5451
}
5552
}
@@ -77,12 +74,12 @@ class BoardContainer extends Component {
7774
toLaneId: event.toLaneId,
7875
cardId: event.cardId,
7976
index: event.index
80-
});
77+
})
8178
case 'UPDATE_LANES':
8279
return actions.updateLanes(event.lanes)
8380
}
84-
},
85-
};
81+
}
82+
}
8683
eventBusHandle(eventBus)
8784
}
8885

@@ -109,7 +106,7 @@ class BoardContainer extends Component {
109106
})
110107
return <span>{newCardWithProps}</span>
111108
} else {
112-
return <NewLane onCancel={this.hideEditableLane} onAdd={this.addNewLane}/>
109+
return <NewLane onCancel={this.hideEditableLane} onAdd={this.addNewLane} />
113110
}
114111
}
115112

@@ -142,7 +139,7 @@ class BoardContainer extends Component {
142139
'addCardTitle',
143140
'newLaneTemplate',
144141
'newCardTemplate'
145-
]);
142+
])
146143

147144
return (
148145
<BoardDiv style={style} {...otherProps} draggable={false}>
@@ -153,8 +150,7 @@ class BoardContainer extends Component {
153150
onDrop={this.onLaneDrop}
154151
lockAxis="x"
155152
getChildPayload={index => this.getLaneDetails(index)}
156-
groupName={`TrelloBoard${id}`}
157-
>
153+
groupName={`TrelloBoard${id}`}>
158154
{reducerData.lanes.map((lane, index) => {
159155
const {id, droppable, ...otherProps} = lane
160156
const laneToRender = (
@@ -167,28 +163,23 @@ class BoardContainer extends Component {
167163
{...otherProps}
168164
{...passthroughProps}
169165
/>
170-
);
171-
return draggable && laneDraggable ? (
172-
<Draggable key={lane.id}>{laneToRender}</Draggable>
173-
) : (
174-
<span key={lane.id}>{laneToRender}</span>
175-
);
166+
)
167+
return draggable && laneDraggable ? <Draggable key={lane.id}>{laneToRender}</Draggable> : <span key={lane.id}>{laneToRender}</span>
176168
})}
177169
</Container>
178-
{
179-
canAddLanes &&
180-
<Container
181-
orientation="horizontal"
182-
>
170+
{canAddLanes && (
171+
<Container orientation="horizontal">
183172
{editable && !addLaneMode ? (
184-
<LaneSection style={{ width: 200 }}>
173+
<LaneSection style={{width: 200}}>
185174
<NewLaneButton onClick={this.showEditableLane}>{addLaneTitle}</NewLaneButton>
186175
</LaneSection>
187-
) : (addLaneMode && this.renderNewLane())}
176+
) : (
177+
addLaneMode && this.renderNewLane()
178+
)}
188179
</Container>
189-
}
180+
)}
190181
</BoardDiv>
191-
);
182+
)
192183
}
193184
}
194185

@@ -226,7 +217,7 @@ BoardContainer.propTypes = {
226217
addLaneTitle: PropTypes.string,
227218
addCardTitle: PropTypes.string,
228219
newLaneTemplate: PropTypes.node
229-
};
220+
}
230221

231222
BoardContainer.defaultProps = {
232223
onDataChange: () => {},
@@ -245,12 +236,15 @@ BoardContainer.defaultProps = {
245236
laneDragClass: 'react_trello_dragLaneClass',
246237
addLaneTitle: '+ Add another lane',
247238
addCardTitle: 'Add Card'
248-
};
239+
}
249240

250241
const mapStateToProps = state => {
251242
return state.lanes ? {reducerData: state} : {}
252-
};
243+
}
253244

254245
const mapDispatchToProps = dispatch => ({actions: bindActionCreators({...boardActions, ...laneActions}, dispatch)})
255246

256-
export default connect(mapStateToProps, mapDispatchToProps)(BoardContainer)
247+
export default connect(
248+
mapStateToProps,
249+
mapDispatchToProps
250+
)(BoardContainer)

stories/AsyncLoad.story.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const data = require('./data/base.json')
99
class AsyncBoard extends Component {
1010
state = {boardData: {lanes: []}}
1111

12-
async componentWillMount () {
12+
async componentDidMount () {
1313
const response = await this.getBoard()
1414
this.setState({boardData: response})
1515
}

0 commit comments

Comments
 (0)