You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a ComponentScript needs to perform an action after the entire graph is deserialized, such as accessing nodes that are higher up or parallel in the hierarchy, it can do so by listening for the NODE_DESERIALIZED event. Inside the listener, it can then attach another listener for the GRAPH_DESERIALIZED event to its node. See example:
consthndNodeDeserialized: EventListenerUnified=()=>{consthndGraphDeserialized: EventListenerUnified=()=>{this.skeleton=Node.FIND(this,_serialization.skeleton);// do the work.this.node.removeEventListener(EVENT.GRAPH_DESERIALIZED,hndGraphDeserialized,true);this.removeEventListener(EVENT.NODE_DESERIALIZED,hndNodeDeserialized);};this.node.addEventListener(EVENT.GRAPH_DESERIALIZED,hndGraphDeserialized,true);};this.addEventListener(EVENT.NODE_DESERIALIZED,hndNodeDeserialized);
This approach introduces a lot of overhead for a simple functionality. Therefore, I propose also broadcasting the GRAPH_DESERIALIZED event to all components of all nodes. This would make it behave more similarly to the NODE_DESERIALIZED event. The example would then look something like this:
consthndGraphDeserialized: EventListenerUnified=()=>{this.skeleton=Node.FIND(this,_serialization.skeleton);// do the work.this.removeEventListener(EVENT.GRAPH_DESERIALIZED,hndGraphDeserialized,true);};this.addEventListener(EVENT.GRAPH_DESERIALIZED,hndGraphDeserialized,true);
Or we can skip removing the listener, since GRAPH_DESERIALIZED is only dispatched once per graph. The example would look like this:
this.addEventListener(EVENT.GRAPH_DESERIALIZED,()=>{this.skeleton=Node.FIND(this,_serialization.skeleton);// do the work.},true);
The text was updated successfully, but these errors were encountered:
this.addEventListener(ƒ.EVENT.COMPONENT_ADD,this.hndEvent);this.addEventListener(ƒ.EVENT.COMPONENT_REMOVE,this.hndEvent);this.addEventListener(ƒ.EVENT.NODE_DESERIALIZED,this.hndEvent);}// Activate the functions of this component as response to eventspublichndEvent=(_event: Event): void=>{switch(_event.type){caseƒ.EVENT.COMPONENT_ADD:
break;caseƒ.EVENT.COMPONENT_REMOVE:
this.removeEventListener(ƒ.EVENT.COMPONENT_ADD,this.hndEvent);this.removeEventListener(ƒ.EVENT.COMPONENT_REMOVE,this.hndEvent);break;caseƒ.EVENT.NODE_DESERIALIZED:
// if deserialized the node is now fully reconstructed and access to all its components and children is possiblebreak;}}
Sticking to this pattern, one only needs to extend the switch at the end like this
switch(_event.type){
....caseƒ.EVENT.NODE_DESERIALIZED:
// if deserialized the node is now fully reconstructed and access to all its components and children is possiblethis.node.addEventListener(EVENT.GRAPH_DESERIALIZED,this.hndEvent,true);break;caseƒ.EVENT.GRAPH_DESERIALIZED:
this.skeleton=Node.FIND(this,_serialization.skeleton);// do the work. break;}}
The number of automatic broadcasts should be kept as low as possible. I don't see the need in this particular case and once we start extending, we will probably find many other desirable broadcasts...
If a
ComponentScript
needs to perform an action after the entire graph is deserialized, such as accessing nodes that are higher up or parallel in the hierarchy, it can do so by listening for theNODE_DESERIALIZED
event. Inside the listener, it can then attach another listener for theGRAPH_DESERIALIZED
event to its node. See example:This approach introduces a lot of overhead for a simple functionality. Therefore, I propose also broadcasting the GRAPH_DESERIALIZED event to all components of all nodes. This would make it behave more similarly to the NODE_DESERIALIZED event. The example would then look something like this:
Or we can skip removing the listener, since GRAPH_DESERIALIZED is only dispatched once per graph. The example would look like this:
The text was updated successfully, but these errors were encountered: