commit d01ff389d42fd61d6733cc4e838bddd3ef3937b3
parent 98f42001cc86bd79d2b5877d04cfc3b10080ca05
Author: Dan Stillman <dstillman@zotero.org>
Date: Sat, 3 Jun 2006 20:26:31 +0000
Use the Hash datatype in Notifier to store observers and improve debug output to display how many we have registered when trigger() is called
Diffstat:
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/chrome/chromeFiles/content/scholar/xpcom/notifier.js b/chrome/chromeFiles/content/scholar/xpcom/notifier.js
@@ -1,7 +1,7 @@
Scholar.Notifier = new function(){
var _observers = new Array();
- _observers['columnTree'] = new Array();
- _observers['itemTree'] = new Array();
+ _observers['columnTree'] = new Scholar.Hash();
+ _observers['itemTree'] = new Scholar.Hash();
this.registerColumnTree = registerColumnTree;
this.registerItemTree = registerItemTree;
@@ -43,12 +43,15 @@ Scholar.Notifier = new function(){
throw('Invalid type in Notifier.trigger()');
}
- for (i in _observers[treeType]){
- Scholar.debug("Calling _observers['" + treeType + "']"
- + "['" + i + "'].notify('" + event + "', " + type + "', "
- + (typeof ids=='Object' ? ids.join() : ids)
- + ")", 4);
- _observers[treeType][i].notify(event, type, ids);
+ Scholar.debug("Notifier.trigger('" + event + "', '" + type + "', "
+ + (typeof ids=='Object' ? ids.join() : ids) + ") called "
+ + "[column trees: " + _observers['columnTree'].length
+ + ", item trees: " + _observers['itemTree'].length + "]");
+
+ for (i in _observers[treeType].items){
+ Scholar.debug("Calling notify() on " + treeType + " with hash '"
+ + i + "'", 4);
+ _observers[treeType].get(i).notify(event, type, ids);
}
}
@@ -66,15 +69,15 @@ Scholar.Notifier = new function(){
var hash = Scholar.randomString(len);
tries--;
}
- while (_observers[type][hash]);
+ while (_observers[type].get(hash));
Scholar.debug('Registering ' + type + " in notifier with hash '" + hash + "'", 4);
- _observers[type][hash] = ref;
+ _observers[type].set(hash, ref);
return hash;
}
function _unregister(type, hash){
Scholar.debug("Unregistering " + type + " in notifier with hash '" + hash + "'", 4);
- delete _observers[type][hash];
+ _observers[type].remove(hash);
}
}