amnesia.js : put the 'db' and closures inside the the module's 'create' method, in case we ever want to call it twice, for some reason

pull/1/head
ansuz 9 years ago
parent db2fcda655
commit 30bee6504e

@ -1,5 +1,3 @@
console.log("Loading amnesiadb. This is a horrible idea in production, as data *will not* persist\n");
/* /*
As the log statement says, this module does nothing to persist your data As the log statement says, this module does nothing to persist your data
across sessions. If your process crashes for any reason, all pads will die. across sessions. If your process crashes for any reason, all pads will die.
@ -14,10 +12,14 @@ console.log("Loading amnesiadb. This is a horrible idea in production, as data *
Enjoy! Enjoy!
*/ */
var db=[], module.exports.create = function(conf, cb){
index=0; console.log("Loading amnesiadb. This is a horrible idea in production,"+
"as data *will not* persist\n");
var insert = function(channelName, content, cb){ var db=[],
index=0;
cb({
message: function(channelName, content, cb){
var val = { var val = {
id:index++, id:index++,
chan: channelName, chan: channelName,
@ -26,9 +28,8 @@ var insert = function(channelName, content, cb){
}; };
db.push(val); db.push(val);
cb(); cb();
}; },
getMessages: function(channelName, cb){
var getMessages = function(channelName, cb){
db.sort(function(a,b){ db.sort(function(a,b){
return a.id - b.id; return a.id - b.id;
}); });
@ -37,11 +38,6 @@ var getMessages = function(channelName, cb){
}).forEach(function(doc){ }).forEach(function(doc){
cb(doc.msg); cb(doc.msg);
}); });
}; },
module.exports.create = function(conf, cb){
cb({
message: insert,
getMessages: getMessages,
}); });
}; };

Loading…
Cancel
Save