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
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!
*/
module.exports.create = function(conf, cb){
console.log("Loading amnesiadb. This is a horrible idea in production,"+
"as data *will not* persist\n");
var db=[],
index=0;
var insert = function(channelName, content, cb){
cb({
message: function(channelName, content, cb){
var val = {
id:index++,
chan: channelName,
@ -26,9 +28,8 @@ var insert = function(channelName, content, cb){
};
db.push(val);
cb();
};
var getMessages = function(channelName, cb){
},
getMessages: function(channelName, cb){
db.sort(function(a,b){
return a.id - b.id;
});
@ -37,11 +38,6 @@ var getMessages = function(channelName, cb){
}).forEach(function(doc){
cb(doc.msg);
});
};
module.exports.create = function(conf, cb){
cb({
message: insert,
getMessages: getMessages,
},
});
};

Loading…
Cancel
Save