Created
February 27, 2019 21:40
-
-
Save shobishani/789409b0dba662b224d718b9c60af14a to your computer and use it in GitHub Desktop.
Pakistan and India never stoppable war
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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