Merge pull request #174 from rspeer/master

Fix to globalPads -- resolves issue #160
This commit is contained in:
Peter 'Pita' Martischka 2011-09-30 01:50:20 -07:00
commit b6211ee6a5

View file

@ -21,10 +21,20 @@
require("../db/Pad"); require("../db/Pad");
var db = require("./DB").db; var db = require("./DB").db;
/** /**
* A Array with all known Pads * An Object containing all known Pads. Provides "get" and "set" functions,
* which should be used instead of indexing with brackets. These prepend a
* colon to the key, to avoid conflicting with built-in Object methods or with
* these functions themselves.
*
* If this is needed in other places, it would be wise to make this a prototype
* that's defined somewhere more sensible.
*/ */
globalPads = []; globalPads = {
get: function (name) { return this[':'+name]; },
set: function (name, value) { this[':'+name] = value; },
remove: function (name) { delete this[':'+name]; }
};
/** /**
* Returns a Pad Object with the callback * Returns a Pad Object with the callback
@ -65,7 +75,7 @@ exports.getPad = function(id, text, callback)
} }
} }
var pad = globalPads[id]; var pad = globalPads.get(id);
//return pad if its already loaded //return pad if its already loaded
if(pad != null) if(pad != null)
@ -86,7 +96,7 @@ exports.getPad = function(id, text, callback)
} }
else else
{ {
globalPads[id] = pad; globalPads.set(id, pad);
callback(null, pad); callback(null, pad);
} }
}); });
@ -110,6 +120,6 @@ exports.isValidPadId = function(padId)
//removes a pad from the array //removes a pad from the array
exports.unloadPad = function(padId) exports.unloadPad = function(padId)
{ {
if(globalPads[padId]) if(globalPads.get(padId))
delete globalPads[padId]; globalPads.remove(padId);
} }