hadron-document
Version:
Hadron Document
50 lines • 1.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hadron_type_checker_1 = __importDefault(require("hadron-type-checker"));
const element_events_1 = require("../element-events");
const standard_1 = __importDefault(require("./standard"));
/**
* CRUD editor for decimal128 values.
*/
class Decimal128Editor extends standard_1.default {
/**
* Create the editor with the element.
*
* @param {Element} element - The hadron document element.
*/
constructor(element) {
super(element);
}
/**
* Complete the decimal128 edit by converting the valid string to a decimal128
* value or leaving as invalid.
*/
complete() {
super.complete();
if (this.element.isCurrentTypeValid()) {
this.element.edit(hadron_type_checker_1.default.cast(this.element.currentValue, 'Decimal128'));
}
}
/**
* Edit Decimal128 element. Check if the value is a Decimal128 before setting typed
* up value.
*
* @param {Object} value - The new value.
*/
edit(value) {
try {
hadron_type_checker_1.default.cast(value, 'Decimal128');
this.element.currentValue = value;
this.element.setValid();
this.element._bubbleUp(element_events_1.ElementEvents.Edited, this.element);
}
catch (error) {
this.element.setInvalid(value, this.element.currentType, error.message);
}
}
}
exports.default = Decimal128Editor;
//# sourceMappingURL=decimal128.js.map