hadron-document
Version:
Hadron Document
58 lines • 1.84 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 object id values.
*/
class ObjectIdEditor extends standard_1.default {
/**
* Create the editor with the element.
*
* @param {Element} element - The hadron document element.
*/
constructor(element) {
super(element);
}
/**
* Complete the object id edit by converting the valid string to an object id
* object or leaving as invalid.
*/
complete() {
super.complete();
if (this.element.isCurrentTypeValid()) {
this.element.edit(hadron_type_checker_1.default.cast(this.element.currentValue, 'ObjectId'));
}
}
/**
* Edit the element with the provided value.
*
* @param {Object} value - The new value.
*/
edit(value) {
try {
hadron_type_checker_1.default.cast(value, 'ObjectId');
this.element.currentValue = value;
this.element.setValid();
this.element._bubbleUp(element_events_1.ElementEvents.Edited, this.element);
}
catch (e) {
this.element.setInvalid(value, this.element.currentType, e.message);
}
}
/**
* Start the object id edit.
*/
start() {
super.start();
if (this.element.isCurrentTypeValid()) {
this.edit(String(this.element.currentValue));
}
}
}
exports.default = ObjectIdEditor;
//# sourceMappingURL=objectid.js.map