-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivityLog.js
41 lines (32 loc) · 996 Bytes
/
activityLog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var nodeModules = {
events: require('events'),
util: require('util')
};
var utils = require('./utilities.js');
var activityLog = function activityLog() {
nodeModules.events.EventEmitter.call(this);
var log = [];
var self = this;
var idSeed = 0;
this.addEntry = function addEntry(entry) {
entry.timestamp = new Date();
entry.id = idSeed++;
log.push(entry);
self.emit('activity');
};
this.removeEntry = function removeEntry(index) {
log.splice(index, 1);
};
this.findAllEntries = function findAllEntries() {
return log;
};
this.findEntries = function findEntries(since) {
var entries = [];
var i = log.length - 1;
while (i >= 0 && log[i].id > since)
entries.unshift(log[i--]);
return entries;
};
};
nodeModules.util.inherits(activityLog, nodeModules.events.EventEmitter);
module.exports = activityLog;