basicprimitives
Version:
Basic Primitives Diagrams for JavaScript - data visualization components library that implements organizational chart and multi-parent dependency diagrams, contains implementations of JavaScript Controls and PDF rendering plugins.
29 lines (21 loc) • 715 B
JavaScript
export default function EnumerationReader(enumeration, isNullable, defaultValue) {
this.enumeration = enumeration;
this.isNullable = isNullable;
this.defaultValue = defaultValue;
this.hash = {};
/* collect valid enumeration values */
for (var key in enumeration) {
this.hash[enumeration[key]] = key;
}
};
EnumerationReader.prototype.read = function (target, source, path, context) {
var result = null;
if (source === null || typeof source == "undefined" || !this.hash.hasOwnProperty(source)) {
source = this.isNullable ? null : this.defaultValue;
}
result = source;
if (target !== source) {
context.isChanged = true;
}
return result;
};