Skip to content

Instantly share code, notes, and snippets.

@shobishani
Created February 27, 2019 21:40
Show Gist options
  • Save shobishani/789409b0dba662b224d718b9c60af14a to your computer and use it in GitHub Desktop.
Save shobishani/789409b0dba662b224d718b9c60af14a to your computer and use it in GitHub Desktop.
Pakistan and India never stoppable war
import React,{Component} from 'react';
import _ from 'lodash';
class Tension extends Component{
state = {
nations: {
pakistan: {
isResponding: false
},
india: {
isResponding: false
}
}
};
//1974
componentDidMount() {
this.startRandomFight();
_.throttle(this.toggleNation, 300000, {'trailing': false})();
}
//never unmounted
componentWillUnmount(){
//oh! crap did we forgot to cancel the throttle
//crap again we even forgot to take the instance of throttle so we can end war :(
}
startRandomFight = () => {
const randomIssue = Math.floor(Math.random() * 2);
this.setState({
nations: {
pakistan: {isResponding: randomIssue === 1},
india: {isResponding: randomIssue === 0},
}
});
};
toggleNation = () => {
const {nations} = this.state;
this.setState({
nations: {
pakistan: {isResponding: !nations.pakistan.isResponding},
india: {isResponding: !nations.india.isResponding}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment