Repository URL to install this package:
Version:
0.9.5 ▾
|
import { observable, action } from 'xmobx/mobx'
import { IncrementerProps, DefaultIncrementerState } from './typings'
class IncrementerState implements DefaultIncrementerState {
@observable count: number
@observable shouldIncrement: boolean = true
@observable shouldDecrement: boolean = false
@action.bound
incrementCount(props: IncrementerProps) {
const { maxValue, step } = props
if (this.count < maxValue) {
this.count += step
this.shouldDecrement = true
}
if (this.count === maxValue) {
this.shouldIncrement = false
}
}
@action.bound
decrementCount(props: IncrementerProps) {
const { step } = props
if (this.count > 1) {
this.count -= step
this.shouldIncrement = true
}
if (this.count === 1) {
this.shouldDecrement = false
}
}
}
export { IncrementerState }