I tried to have two modules sending notification to each other: ModuleA sending “TEST_NOTI” to ModuleB, and ModuleB shows the information of this notification on mirror.
I put ModuleA and ModuleB in different folders named by themselves.
My code in ModuleA is like:
start:function(){
this.count=0;
},
notificationReceived:function(notification,payload,sender){
switch(notification){
case "DOM_OBJECTS_CREATED":
var timer=setInterval(()=>{
this.count++;
this.sendNotification("TEST_NOTI",this.count);
},1000)
break;
default:
break;
}
},
My code in ModuleB is like:
getDom:function(){
var wrapper=document.createElement("p");
wrapper.className="test results";
wrapper.id="parent";
wrapper.innerHTML="test results: ";
return wrapper;
},
notificationReceived:function(notification,payload,sender){
var self=this;
switch(notification){
case "DOM_OBJECTS_CREATED":
setInterval(()=>{
this.updateDom();
},1000)
break;
case "TEST_NOTI":
var parent=document.getElementById("parent");
var child=document.createElement("p");
child.id="test notification";
child.innerHTML="TEST_NOTI received"+payload;
parent.appendChild(child);
break;
default:
break;
}
},
I assume that ModuleB will show
test results:
TEST_NOTI received [counting]
where [counting] counts from 1 to infinity.
However, the second line of my assumption only appears occasionally
. I could hardly find any regulation in its appearance.
Could anyone help me to figure out whether its a problem within my code or its a problem of the notification connection?
Are there any place to learn about the notification except the doc?