This is a set of ideas for how an activity module could work that uses leveldb and is meant to track all the important activity happening on a site. Primary usage would be on the server. It could presumably also work on the client side, but probably wouldn't need to.
or some similar package name.
activity-trackeris available, though
db: a levelup instance for storing all the valuesoptions: TBD
options:type: string slug that identifies the model that is being acted onaction: string that specifies an action likecreate,update,deletemessage: string that is used as the main description of the activitydata: object with arbitrary data that can be attached to the activity
internally this function adds a timestamp and a key.
callbackprovideserrorandresponsearguments, theresponsebeing the activity object.
callbackprovides anerrorargument.
callbackprovideserrorandresponsearguments, theresponsebeing the activity object.
options:live: default isfalse,truemakes it a stream that automatically updates when there are new activities- usual levelup createReadStream options
function Post (options) {
this.activity = require('activity-tracker')(db)
}
Post.prototype.create = function (options, cb) {
this.activity.add({ type: 'post', action: 'create', message: options.title })
// ... usual create stuff
}module.exports = Post
function Posts (options) {
// make Posts an event emitter
}
Posts.prototype.create = function (options, cb) {
// do the create stuff that results in the final `post` object
this.emit('create', post)
}Then in another file:
var posts = require('./posts')
var activity = require('activity-tracker')(db)
posts.on('create', function (post) {
activity.add({ type: 'post', action: 'create', message: post.title })
})