Repository URL to install this package:
|
Version:
2.1.14 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const tslib_1 = require("tslib");
const exotic_1 = require("exotic");
const mobx_1 = require("xmobx/mobx");
class CountState {
constructor() {
// no need for the word left
this.shouldDisableRightIcon = false;
this.shouldDisableLeftIcon = false;
}
incrementCount(limit) {
this.count = exotic_1.toNumber(this.count);
if (this.count < limit) {
this.count += 1;
this.enableIcon('left');
}
if (this.count === limit) {
this.disableIcon('right');
}
}
decrementCount() {
this.count = exotic_1.toNumber(this.count);
if (this.count > 1) {
this.count -= 1;
this.enableIcon('right');
}
if (this.count === 1) {
this.disableIcon('left');
}
}
setCount(value) {
this.count = value;
}
disableIcon(direction) {
switch (true) {
case direction === 'right':
this.shouldDisableRightIcon = true;
break;
case direction === 'left':
this.shouldDisableLeftIcon = true;
break;
default:
this.shouldDisableRightIcon = true;
this.shouldDisableLeftIcon = true;
}
}
enableIcon(direction) {
switch (true) {
case direction === 'right':
this.shouldDisableRightIcon = false;
break;
case direction === 'left':
this.shouldDisableLeftIcon = false;
break;
default:
this.shouldDisableRightIcon = false;
this.shouldDisableLeftIcon = false;
}
}
}
tslib_1.__decorate([mobx_1.observable], CountState.prototype, "count", void 0);
tslib_1.__decorate([mobx_1.observable], CountState.prototype, "shouldDisableRightIcon", void 0);
tslib_1.__decorate([mobx_1.observable], CountState.prototype, "shouldDisableLeftIcon", void 0);
tslib_1.__decorate([mobx_1.action.bound], CountState.prototype, "incrementCount", null);
tslib_1.__decorate([mobx_1.action.bound], CountState.prototype, "decrementCount", null);
tslib_1.__decorate([mobx_1.action], CountState.prototype, "setCount", null);
tslib_1.__decorate([mobx_1.action], CountState.prototype, "disableIcon", null);
tslib_1.__decorate([mobx_1.action], CountState.prototype, "enableIcon", null);
exports.CountState = CountState;