Repository URL to install this package:
|
Version:
2.0.4 ▾
|
"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 mobx_1 = require("xmobx/mobx");
const exotic_1 = require("exotic");
class IncrementerState {
constructor() {
this.shouldIncrement = true;
this.shouldDecrement = false;
}
incrementCount(props) {
const {
maxValue,
step
} = props;
if (this.count < maxValue) {
this.count += step;
this.shouldDecrement = true;
}
if (this.count === maxValue) {
this.shouldIncrement = false;
}
}
handleChange(props, event) {
const {
minValue,
maxValue
} = props;
let value = event.target.value;
value = value === '' ? '' : exotic_1.toNumber(value);
if (value === '' || value >= minValue && value <= maxValue) {
this.count = value;
}
if (value === 0) {
this.count = 1;
}
this.shouldDecrement = !(this.count <= minValue);
this.shouldIncrement = !(this.count >= maxValue);
}
handleBlur(props, event) {
let value = event.target.value;
if (value === '' || value <= props.minValue) {
value = props.minValue;
this.count = value;
} else if (value >= props.maxValue) {
value = props.maxValue;
this.count = value;
}
}
decrementCount(props) {
const {
minValue,
step
} = props;
if (this.count > minValue) {
this.count -= step;
this.shouldIncrement = true;
}
if (this.count === minValue) {
this.shouldDecrement = false;
}
}
}
__decorate([mobx_1.observable], IncrementerState.prototype, "count", void 0);
__decorate([mobx_1.observable], IncrementerState.prototype, "shouldIncrement", void 0);
__decorate([mobx_1.observable], IncrementerState.prototype, "shouldDecrement", void 0);
__decorate([mobx_1.action.bound], IncrementerState.prototype, "incrementCount", null);
__decorate([mobx_1.action.bound], IncrementerState.prototype, "handleChange", null);
__decorate([mobx_1.action.bound], IncrementerState.prototype, "handleBlur", null);
__decorate([mobx_1.action.bound], IncrementerState.prototype, "decrementCount", null);
exports.IncrementerState = IncrementerState; //# sourceMappingURL=state.js.map