All new
alle new
This commit is contained in:
1 parent
da64472251
commit
5b20adee48
1605 files changed
+396517
-1674
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
exports.readRelationships = readRelationships;
|
||||
exports.defaultValue = new Relationships([]);
|
||||
exports.Relationships = Relationships;
|
||||
|
||||
|
||||
function readRelationships(element) {
|
||||
var relationships = [];
|
||||
element.children.forEach(function(child) {
|
||||
if (child.name === "relationships:Relationship") {
|
||||
var relationship = {
|
||||
relationshipId: child.attributes.Id,
|
||||
target: child.attributes.Target,
|
||||
type: child.attributes.Type
|
||||
};
|
||||
relationships.push(relationship);
|
||||
}
|
||||
});
|
||||
return new Relationships(relationships);
|
||||
}
|
||||
|
||||
function Relationships(relationships) {
|
||||
var targetsByRelationshipId = Object.create(null);
|
||||
relationships.forEach(function(relationship) {
|
||||
targetsByRelationshipId[relationship.relationshipId] = relationship.target;
|
||||
});
|
||||
|
||||
var targetsByType = Object.create(null);
|
||||
relationships.forEach(function(relationship) {
|
||||
if (!targetsByType[relationship.type]) {
|
||||
targetsByType[relationship.type] = [];
|
||||
}
|
||||
targetsByType[relationship.type].push(relationship.target);
|
||||
});
|
||||
|
||||
return {
|
||||
findTargetByRelationshipId: function(relationshipId) {
|
||||
return targetsByRelationshipId[relationshipId];
|
||||
},
|
||||
findTargetsByType: function(type) {
|
||||
return targetsByType[type] || [];
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user