Skip to content

Instantly share code, notes, and snippets.

@jiin
Created March 10, 2015 11:23
Show Gist options
  • Save jiin/f15bc12fa15d7149745f to your computer and use it in GitHub Desktop.
Save jiin/f15bc12fa15d7149745f to your computer and use it in GitHub Desktop.
// made for bitlanders.com
.factory('middlaw', ['$rootScope', function($rootScope) {
var scopePrototype = Object.getPrototypeOf($rootScope);
var cache = [];
var colors = {
'$apply': '#8e44ad',
'$digest': '#3498db',
'$timeout': '#f1c40f'
};
var getLineNumber = function () {
return ((new Error).stack).split('\n')[3]
};
return {
rewrite: function(attr, cb) {
cache[attr] = scopePrototype[attr];
scopePrototype[attr] = function $middleware() {
console.log('%c[MIDDLAW] rewrite of %s\n%s', 'background-color: #FFF; color: ' + colors[attr] + ';', attr, getLineNumber());
if (typeof cb === 'function')
cb.call(this);
cache[attr].apply(this, arguments);
}
}
};
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment