0.2.1 • Published 10 years ago

nostalgorithm v0.2.1

Weekly downloads
9
License
-
Repository
github
Last release
10 years ago

nostalgorithm

Build Status Dependency Status

NPM

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

var n = require('nostalgorithm');
var o = {
  	myMethodOne: function(){ return 5; },
  	myMethodTwo: function(x){ return 5 + x; },
  	child: {
  		anotherMethod: function(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 = {
    myMethodOne: function(){ return 5; },
    myMethodTwo: function(){ 
		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
0.2.1

10 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.0

11 years ago