Repository URL to install this package:
Version:
0.9.7 ▾
|
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
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;
}
}
}
__decorate([
mobx_1.observable
], CountState.prototype, "count", void 0);
__decorate([
mobx_1.observable
], CountState.prototype, "shouldDisableRightIcon", void 0);
__decorate([
mobx_1.observable
], CountState.prototype, "shouldDisableLeftIcon", void 0);
__decorate([
mobx_1.action.bound
], CountState.prototype, "incrementCount", null);
__decorate([
mobx_1.action.bound
], CountState.prototype, "decrementCount", null);
__decorate([
mobx_1.action
], CountState.prototype, "setCount", null);
__decorate([
mobx_1.action
], CountState.prototype, "disableIcon", null);
__decorate([
mobx_1.action
], CountState.prototype, "enableIcon", null);
exports.CountState = CountState;
//# sourceMappingURL=state.js.map