Skip to content

Commit

Permalink
minimal Protos
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasplesch committed May 28, 2020
1 parent 90e26ca commit 1e0ff82
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/NodeNameSpace.js
Expand Up @@ -24,6 +24,7 @@ x3dom.NodeNameSpace = function ( name, document )
this.defMap = {};
this.parent = null;
this.childSpaces = [];
this.protos = []; // the ProtoDeclarationArray
};

/**
Expand Down Expand Up @@ -392,6 +393,7 @@ x3dom.NodeNameSpace.prototype.setupTree = function ( domNode, parent )
}
else
{

// check and create ROUTEs
if ( domNode.localName.toLowerCase() === "route" )
{
Expand Down Expand Up @@ -521,6 +523,10 @@ x3dom.NodeNameSpace.prototype.setupTree = function ( domNode, parent )
}
}.bind( this ) );
}
if ( this.setupProto( domNode, parent ) )
{
console.log("Proto setup");
}
else
{
// be nice to users who use nodes not (yet) known to the system
Expand All @@ -531,3 +537,55 @@ x3dom.NodeNameSpace.prototype.setupTree = function ( domNode, parent )

return n;
};

x3dom.NodeNameSpace.prototype.setupProto = function ( domNode, parent )
{
var tagName = domNode.localName.toLowerCase();
var name = domNode.getAttribute( "name" );
if ( parent && tagName == "protodeclare" )
{
console.log("found ProtoDeclare", name, domNode)
var protoDeclaration = {
'name' : name,
'isExternProto' : false,
'fields' : [], //FieldDefinitionArray
}
var protoInterface = domNode.querySelector('ProtoInterface');
var protoBody = domNode.querySelector('ProtoBody');
if (protoBody)
{
protoDeclaration['ProtoBody'] = protoBody;
protoDeclaration['newInstance'] = function() {
var c = this.setupTree( protoBody.querySelector('*'), parent );//only use first child
console.log(c);
return c
}.bind( this )
this.protos.push( protoDeclaration );
}
else
{
x3dom.debug.logWarning( "ProtoDeclare without a ProtoBody definition: " + domNode.name);
}
}
if ( parent && tagName == "protoinstance" )
{
console.log("found ProtoInstance", domNode);
if (name)
{
var protoDeclaration = this.protos.find( proto => proto.name == name );
if (protoDeclaration == undefined)
{
x3dom.debug.logWarning( "ProtoInstance without a ProtoDeclaration " + name );
return true
}
else
{
parent.addChild( protoDeclaration.newInstance(), domNode.getAttribute( "containerField" ));
}
}
else {
x3dom.debug.logWarning( "ProtoInstance without a name under " + parent.localName)
}
}
return true
}

0 comments on commit 1e0ff82

Please sign in to comment.