nostalgorithm

create an audit trail of every method call.

nostalgorithm

##examples ###create an audit trail of every method call

var n = require('nostalgorithm');
var o = {
    myMethodOnefunction(){ return 5; },
    myMethodTwofunction(x){ return 5 + x; },
    child: {
        anotherMethodfunction(x){ return 2*x; }
    }
};
 
n.watch(o);
 
o.myMethodOne();
o.child.anotherMethod(10);
o.myMethodTwo(4);
 
console.log(o.nostalgorithm.calls); => [
    {name: 'myMethodOne', arguments: [], value: 5 },
    {name: 'child.anotherMethod', arguments: [10], value: 20 },
    {name: 'myMethodTwo', arguments: [4], value: 9 }
] 
 
n.ignore(o);
 
o.myMethodOne();
 
// o.nostalgorithm.calls is unchanged because we called ignore 

###how long did a method take to execute?

var n = require('nostalgorithm');
var q = require('q');
var o = {
    myMethodOnefunction(){ return 5; },
    myMethodTwofunction(){ 
        var d = q.defer();
        setTimeout(function(){d.resolve('heloo');}, 32);
        return d.promise; 
    },
};
 
n.before(o, function(d){ d.start = new Date(); });
n.after(o, function(d){ 
    d.end = new Date();
    console.log(d.name + ' took ' + (d.end - d.start) + 'ms');
});
 
o.myMethodOne();
o.myMethodTwo();

output:

myMethodOne took 0ms        
myMethodTwo took 35ms