Ver código fonte

messageaggregator can remove children

Adam Shaw 8 anos atrás
pai
commit
68441ae6e3
1 arquivos alterados com 12 adições e 3 exclusões
  1. 12 3
      src/common/MessageAggregator.js

+ 12 - 3
src/common/MessageAggregator.js

@@ -1,5 +1,7 @@
 
 function buildMessageAggregator(parent, initName, destroyName) {
+	var childUpEvent = 'all:' + initName;
+	var childDownEvent = 'before:all:' + destroyName;
 	var childCnt = 0;
 	var reportCnt = 0;
 
@@ -9,12 +11,19 @@ function buildMessageAggregator(parent, initName, destroyName) {
 
 
 	function addChild(child) {
-		child.on('all:' + initName, up);
-		child.on('before:all:' + destroyName, down);
+		child.on(childUpEvent, up);
+		child.on(childDownEvent, down);
 		childCnt++;
 	}
 
 
+	function removeChild(child) {
+		child.off(childUpEvent, up);
+		child.off(childDownEvent, down);
+		childCnt--;
+	}
+
+
 	function up() {
 		if (++reportCnt === childCnt + 1) {
 			parent.trigger('all:' + initName);
@@ -29,7 +38,7 @@ function buildMessageAggregator(parent, initName, destroyName) {
 	}
 
 
-	return { addChild: addChild };
+	return { addChild: addChild, removeChild: removeChild };
 }
 
 FC.buildMessageAggregator = buildMessageAggregator;