Last active
October 1, 2016 10:24
-
-
Save alirezamirian/7a34df147987ed60e395a1e205e28dd3 to your computer and use it in GitHub Desktop.
A try for adding debugging info when each of the methods of directives controller gets called. It neither work correctly nor is configurable yet to set which directives to diagnose (you should hardcode it!). I'm just pushing it as a draft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("diagnostics", []) | |
.run(function($injector, $controller, $log){ | |
var directivesToInspect = []; | |
directivesToInspect.forEach(function(directiveName){ | |
$injector.get(directiveName + "Directive").forEach(function(directive){ | |
if(angular.isArray(directive.controller)){ | |
var Ctrl = directive.controller[directive.controller.length-1]; | |
directive.controller[directive.controller.length-1] = function(){ | |
var locals = {}; | |
for(var i=0; i<arguments.length; i++){ | |
locals[directive.controller[i]] = arguments[i]; | |
} | |
var ctrlInstance = $controller(Ctrl, locals); | |
angular.forEach(ctrlInstance, function(value, key){ | |
if(angular.isFunction(value) && !value.noDiagnostic && | |
(directive.noDiagnostic || []).indexOf(key) < 0){ | |
var fn = value; | |
$log.debug("decorating controller function: " + directiveName + "." + key); | |
ctrlInstance[key] = function(){ | |
$log.debug("inspector: call to function: " + directiveName + "." + key); | |
fn.apply(ctrlInstance, arguments); | |
} | |
} | |
}); | |
return ctrlInstance; | |
} | |
} | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment