Skip to content

tnrich/objectWatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

ObjectWatcher

A super simple package to allow you to set watchers/listeners on your javascript variables.

Useful mostly for debugging when you aren't sure where a variable is being set/modified.

Just slap a watcher on it:

var watch = require(object-watcher).watch;

var data = {
     quantity: 0
     , products:  []
}
, watcher = function(propertyName, oldValue, newValue){ 
	console.log("Variable Changed!");
	console.log(propertyName, oldValue, newValue);
};

watch(data, 'quantity', watcher);
watch(data, 'products', watcher);

data.quantity = 8
// Variable Changed!

A slightly more compact version:

watch(data, 'quantity', function(propertyName, oldValue, newValue){ 
    console.log("Variable Changed!");
    console.log(propertyName, oldValue, newValue);
});

About

A super simple package to allow you to set watchers/listeners on your javascript variables.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published