2018-06-19 19:50:37 +00:00
|
|
|
import { Container } from 'unstated'
|
|
|
|
|
|
|
|
export default class CounterContainer extends Container {
|
|
|
|
state = {
|
|
|
|
count: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
increment = () => {
|
2018-12-17 16:34:32 +00:00
|
|
|
this.setState(state => ({ count: state.count + 1 }))
|
2018-06-19 19:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
decrement = () => {
|
2018-12-17 16:34:32 +00:00
|
|
|
this.setState(state => ({ count: state.count - 1 }))
|
2018-06-19 19:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reset = () => {
|
|
|
|
this.setState({ count: 0 })
|
|
|
|
}
|
2019-01-06 15:58:06 +00:00
|
|
|
|
|
|
|
// this two methods are not setState as they work only before rendering
|
|
|
|
initState = count => {
|
|
|
|
this.state = { count }
|
|
|
|
}
|
|
|
|
resetState = () => {
|
|
|
|
this.initState(0)
|
|
|
|
}
|
2018-06-19 19:50:37 +00:00
|
|
|
}
|
2019-01-06 15:58:06 +00:00
|
|
|
export const counterStore = new CounterContainer()
|