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
This commit is contained in:
@@ -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!
|
||||
*/
|
||||
|
||||
var db=[],
|
||||
index=0;
|
||||
module.exports.create = function(conf, cb){
|
||||
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 = {
|
||||
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,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user