Add initialize deck method

This commit is contained in:
Guillaume Darricau
2018-08-02 13:52:57 +02:00
parent 3e602e46f1
commit 30983dc681

View File

@@ -121,7 +121,20 @@ export default class CardStack extends Component {
}
componentDidMount(){
this.initDeck();
}
componentWillReceiveProps(nextProps){
if (nextProps.children !== this.props.children) {
this.setState({
cards: nextProps.children,
cardA: nextProps.children[(this.state.topCard=='cardA')? this.state.sindex-2 : this.state.sindex-1],
cardB: nextProps.children[(this.state.topCard=='cardB')? this.state.sindex-2 : this.state.sindex-1]
});
}
}
initDeck() {
// check if we only have 1 child
if(typeof this.props.children !== 'undefined' && !Array.isArray(this.props.children)){
this.setState({
@@ -138,17 +151,6 @@ export default class CardStack extends Component {
sindex: 2,
});
}
}
componentWillReceiveProps(nextProps){
if (nextProps.children !== this.props.children) {
this.setState({
cards: nextProps.children,
cardA: nextProps.children[(this.state.topCard=='cardA')? this.state.sindex-2 : this.state.sindex-1],
cardB: nextProps.children[(this.state.topCard=='cardB')? this.state.sindex-2 : this.state.sindex-1]
});
}
}
_resetCard(){