This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
respect explicit return values from controller functions (fixes #11147) #11326
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b89320a
test(compile): failing test - respect controller return value
jamestalmage 57fe701
fix(compile): respect explicit return values from controller functions
jamestalmage d0f1285
test(compile): additional tests for controllers with explicit return …
jamestalmage 0266a1c
refactor(compile): remove duplicate type checks
jamestalmage f6f0117
test(compile): apply discussed changes from #11326
jamestalmage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1967,13 +1967,16 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
for (i in elementControllers) { | ||
controller = elementControllers[i]; | ||
var controllerResult = controller(); | ||
if (controllerResult !== controller.instance && | ||
controller === controllerForBindings) { | ||
// Remove and re-install bindToController bindings | ||
thisLinkFn.$$destroyBindings(); | ||
thisLinkFn.$$destroyBindings = | ||
if (controllerResult !== controller.instance && (isObject(controllerResult) || isFunction(controllerResult))) { | ||
controller.instance = controllerResult; | ||
$element.data('$' + directive.name + 'Controller', controllerResult); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are a few different circumstances that this happens, so we might need to be a bit more careful about this --- be sure to include test coverage that covers controllers for transclude directives too |
||
if (controller === controllerForBindings) { | ||
// Remove and re-install bindToController bindings | ||
thisLinkFn.$$destroyBindings(); | ||
thisLinkFn.$$destroyBindings = | ||
initializeDirectiveBindings(scope, attrs, controllerResult, | ||
bindings, scopeDirective); | ||
bindings, scopeDirective); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't change indentation (you can put this all on one line though --- this is v8 style sneaking in =) |
||
} | ||
} | ||
} | ||
} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in particular, don't worry about the
isObject() || isFunction()
stuff, since that's handled in controller.js anywaysThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind
I'm not sure what you are asking for here. We should mimic the behavior of native javascript: If they return an object or function use that as the result of the instantiation, otherwise return "as normal":There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is duplicating code which already runs in the
controller()
function itself, it's not needed hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
particularly here (the
instantiate
object is not updated here, because the compiler needed to be able to determine if a new result was returned so that the bindings could be reset --- so you still need to setcontroller.instance
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind,
I see what you are saying, my above concern is already handled by the call to the
controller()
callback. I am adding a test case that verifies it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argh!
Come on Github! Real time updates for line comments!