commit 076658824184f61cc5a49c86608c974952de92d8
parent f3ca563f9b970498f0f1ad7199dbc6672ede0f8b
Author: Simon Kornblith <simon@simonster.com>
Date: Fri, 13 Jul 2012 00:06:49 -0400
Closes https://www.zotero.org/trac/ticket/1867, remove Zotero.Hash
Diffstat:
2 files changed, 9 insertions(+), 81 deletions(-)
diff --git a/chrome/content/zotero/xpcom/notifier.js b/chrome/content/zotero/xpcom/notifier.js
@@ -24,7 +24,7 @@
*/
Zotero.Notifier = new function(){
- var _observers = new Zotero.Hash();
+ var _observers = {};
var _disabled = false;
var _types = [
'collection', 'creator', 'search', 'share', 'share-items', 'item',
@@ -69,18 +69,18 @@ Zotero.Notifier = new function(){
var hash = Zotero.randomString(len);
tries--;
}
- while (_observers.get(hash));
+ while (_observers[hash]);
Zotero.debug('Registering observer for '
+ (types ? '[' + types.join() + ']' : 'all types')
+ ' in notifier with hash ' + hash + "'", 4);
- _observers.set(hash, {ref: ref, types: types});
+ _observers[hash] = {ref: ref, types: types};
return hash;
}
function unregisterObserver(hash){
Zotero.debug("Unregistering observer in notifier with hash '" + hash + "'", 4);
- _observers.remove(hash);
+ delete _observers[hash];
}
/**
@@ -115,7 +115,7 @@ Zotero.Notifier = new function(){
var queue = _inTransaction && !force;
Zotero.debug("Notifier.trigger('" + event + "', '" + type + "', " + '[' + ids.join() + '])'
- + (queue ? " queued" : " called " + "[observers: " + _observers.length + "]"));
+ + (queue ? " queued" : " called " + "[observers: " + Object.keys(_observers).length + "]"));
// Merge with existing queue
if (queue) {
@@ -143,20 +143,20 @@ Zotero.Notifier = new function(){
return true;
}
- for (var i in _observers.items){
+ for (var i in _observers){
Zotero.debug("Calling notify('" + event + "') on observer with hash '" + i + "'", 4);
- if (!_observers.get(i)) {
+ if (!_observers[i]) {
Zotero.debug("Observer no longer exists");
continue;
}
// Find observers that handle notifications for this type (or all types)
- if (!_observers.get(i).types || _observers.get(i).types.indexOf(type)!=-1){
+ if (!_observers[i].types || _observers[i].types.indexOf(type)!=-1){
// Catch exceptions so all observers get notified even if
// one throws an error
try {
- _observers.get(i).ref.notify(event, type, ids, extraData);
+ _observers[i].ref.notify(event, type, ids, extraData);
}
catch (e) {
Zotero.debug(e);
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -2333,78 +2333,6 @@ Zotero.VersionHeader = {
}
}
-
-
-/**
-* Class for creating hash arrays that behave a bit more sanely
-*
-* Hashes can be created in the constructor by alternating key and val:
-*
-* var hasharray = new Zotero.Hash('foo','foovalue','bar','barvalue');
-*
-* Or using hasharray.set(key, val)
-*
-* _val_ defaults to true if not provided
-*
-* If using foreach-style looping, be sure to use _for (i in arr.items)_
-* rather than just _for (i in arr)_, or else you'll end up with the
-* methods and members instead of the hash items
-*
-* Most importantly, hasharray.length will work as expected, even with
-* non-numeric keys
-*
-* Adapated from http://www.mojavelinux.com/articles/javascript_hashes.html
-* (c) Mojavelinux, Inc.
-* License: Creative Commons
-**/
-Zotero.Hash = function(){
- this.length = 0;
- this.items = {};
-
- // Public methods defined on prototype below
-
- for (var i = 0; i < arguments.length; i += 2) {
- if (typeof(arguments[i + 1]) != 'undefined') {
- this.items[arguments[i]] = arguments[i + 1];
- this.length++;
- }
- }
-}
-
-Zotero.Hash.prototype.get = function(in_key){
- return this.items[in_key] ? this.items[in_key] : false;
-}
-
-Zotero.Hash.prototype.set = function(in_key, in_value){
- // Default to a boolean hash if value not provided
- if (typeof(in_value) == 'undefined'){
- in_value = true;
- }
-
- if (typeof(this.items[in_key]) == 'undefined') {
- this.length++;
- }
-
- this.items[in_key] = in_value;
-
- return in_value;
-}
-
-Zotero.Hash.prototype.remove = function(in_key){
- var tmp_value;
- if (typeof(this.items[in_key]) != 'undefined') {
- this.length--;
- var tmp_value = this.items[in_key];
- delete this.items[in_key];
- }
-
- return tmp_value;
-}
-
-Zotero.Hash.prototype.has = function(in_key){
- return typeof(this.items[in_key]) != 'undefined';
-}
-
Zotero.DragDrop = {
currentDataTransfer: null,