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
|
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!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
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=[],
|
var db=[],
|
||||||
index=0;
|
index=0;
|
||||||
|
cb({
|
||||||
var insert = function(channelName, content, 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,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user