JSFiddle - React, Tailwind, and code Playground
JavaScript
getEverything: function(obj, attrArr, callback) {
// This function uses an object and an array of attributes and retrieves all these
// They are compiled into a map object of the attribute name and the value, which is passed back to the callback.
var dataMap = {},
missingAttrs = false,
useRefs = false,
schema = {
attributes: [],
references: {}
};
this.refs = {};
var i = 0,
attr;
while (attr = attrArr[i++]) {
var refcheck = attr.match("/");
if (refcheck !== null && refcheck.length > 0) {
var refattr = attr.split("/");
var child;
if (obj.hasAttribute(refattr[0]) && typeof(child = obj.get(refattr[0])) == "Object") {
dataMap[attr] = child.get(refattr[2]);
} else {
if (!schema.references[refattr[0]]) schema.references[refattr[0]] = {
attributes: [refattr[2]]
};
else if (dojo.indexOf(schema.references[refattr[0]].attributes, refattr[2]) == -1) schema.references[refattr[0]].attributes.push(refattr[2]);
if (!this.refs[refattr[0]]) this.refs[refattr[0]] = [attr];
else this.refs[refattr[0]].push(attr);
useRefs = true;
}
} else if (!obj.hasAttribute(attr)) {
schema.attributes.push(attr);
missingAttrs = true;
} else {
dataMap[attr] = obj.get(attr);
}
}
var getMissing = function(newObj, scope) {
var k = -1,
flatattr;
while (flatattr = schema.attributes[++k]) {
dataMap[flatattr] = newObj.get(flatattr);
}
};
var getRefs = function(newObj, scope) {
for (var ref in scope.refs) {
var refattrs = scope.refs[ref];
var child = newObj.getChild(ref);
var j = -1,
refattr;
while (refattr =...