From ac067246622bfa59ea32c663aaf6a531665b7f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88hm?= Date: Fri, 12 Apr 2013 14:27:45 +0200 Subject: [PATCH 1/3] Refactoring for better reading and understanding of instantiate function --- src/auto/injector.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index a6937af46de5..b155e10af582 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -582,11 +582,15 @@ function createInjector(modulesToLoad) { } } + function isInlineAnnotated(fn){ + return isArray(fn); + } + function instantiate(Type, locals) { var Constructor = function() {}, instance, returnedValue; - Constructor.prototype = (isArray(Type) ? Type[Type.length - 1] : Type).prototype; + Constructor.prototype = (isInlineAnnotated(Type) ? Type[Type.length - 1] : Type).prototype; instance = new Constructor(); returnedValue = invoke(Type, instance, locals); From 05c37c41f3c8174b56501f104fcbaec2ae4b5196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88hm?= Date: Fri, 12 Apr 2013 14:35:06 +0200 Subject: [PATCH 2/3] Added another helper for better code readability --- src/auto/injector.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index b155e10af582..235b1b15def5 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -586,11 +586,24 @@ function createInjector(modulesToLoad) { return isArray(fn); } + function getAnnotatedFunction(fn){ + if(isInlineAnnotated(fn)){ + return fn[fn.length - 1] + } + else{ + return fn; + } + } + function instantiate(Type, locals) { var Constructor = function() {}, - instance, returnedValue; + annotatedFunction, + instance, + returnedValue; + + annotatedFunction = getAnnotatedFunction(Type); - Constructor.prototype = (isInlineAnnotated(Type) ? Type[Type.length - 1] : Type).prototype; + Constructor.prototype = annotatedFunction.prototype; instance = new Constructor(); returnedValue = invoke(Type, instance, locals); From 5c5a2e45d5ea73dd43c15ec964c4109b25399568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88hm?= Date: Fri, 12 Apr 2013 14:36:08 +0200 Subject: [PATCH 3/3] Add comments for added functions --- src/auto/injector.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/auto/injector.js b/src/auto/injector.js index 235b1b15def5..515d4fa76094 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -582,10 +582,13 @@ function createInjector(modulesToLoad) { } } + // Is Given function annotated like + // $injector.invoke(['serviceA', function(serviceA){}]) function isInlineAnnotated(fn){ return isArray(fn); } + // Get function of an annotated invoke description function getAnnotatedFunction(fn){ if(isInlineAnnotated(fn)){ return fn[fn.length - 1]