Automatic unwrapping of promises by $parse severely limits its usefulness
The behavior introduced by 3a65822, which automatically unwraps promises returned by functions invoked by $parse, prevents any consumer of an expression from handling promise resolution on its own. More pertinent discussion of the problem exists here: #3503
Notably this breaks the typeahead directive in UI bootstrap, as per this issue: angular-ui/bootstrap#949
Here's a simple example of why this change is problematic.
http://plnkr.co/edit/ymxbpR?p=preview
The directive in that plunk executes a function on click (in the same way as ng-click) and expects a promise to be returned, which it will use to decorate the link with loading text.
Because $parse unwraps the promise, the directive has no chance to add its own handlers. If you switch the Angular version to 1.2.0rc1, it works as expected. I don't believe this is an uncommon use case, and certainly not one the framework should prevent from being possible. I hope this can be resolved by the next RC.
... or it should be ditched altogether. Personally I prefer the latter ...
++ Agreed.
I guess @petebacondarwin is right. +1 on ditching :)
+1 on ditching
Yeah, ditching the whole thing certainly makes the process clearer, which I'm definite in favour of. I'm just concerned about all of the 1.0 and 1.1 code that would break if automatic unwrapping was removed. It would likely be a lot more than the amount that broke by adding support for unwrapping functions that return promises.
@jussik The particular changes discussed in this thread were introduced after RC1. Correct me if I'm wrong but I think everyone is talking about ditching that, not previous support.
Actually I would ditch the lot as a breaking change for 1.2 but this probably won't happen. On 4 Oct 2013 10:31, "Georgios Diamantopoulos" [email protected] wrote:
@jussik https://github.com/jussik The particular changes discussed in this thread were introduced after RC1. Correct me if I'm wrong but I think everyone is talking about ditching that, not previous support.
— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/4158#issuecomment-25686440 .
I'm personally fine with either ditching all or keeping all (preference leaning towards ditching), but I don't see inconsistent behaviour as a valid solution (hence my PR that instigated this discussion).
As @wilsonjackson said:
I agree that promise objects should be unwrapped (or not) according to the same rules whether they result from a function call or not.
The commits that @jankuca has referenced also affect both loose promise objects and functions that return promises.
Would ditching it and keeping existing behavior based on a "compatibility flag" be an acceptable solution for current apps that use this? To be deprecated completely in another major release?
+1 for ditching.
If a user wants promises unwrapped, that can easily be got around by adding a $rootScope.unwrap function as per @xrg's suggestion. It seems like something Angular core (and especially the $parse service) shouldn't concern itself with.
as @petebacondarwin unwrap() doesn't work for the case of: {{unwrap(some.path.with.promise.somewhere.in.the.middle)}} because unwrap would be called with undefined if there was promise somewhere not-at-the-end of the path.
Asynchronous validation broken with Angular 1.2.0-rc2: https://github.com/angular-ui/ui-utils/issues/120
As a workaround, in rc2 i ve commented out the unwrapping lines in _functionCall
Sent from a device with a small keyboard
On 6 Oct 2013, at 08:55, "Andreas Gruenbacher" [email protected] wrote:
angular-ui/ui-utils#120
— Reply to this email directly or view it on GitHub.
guys, check out #4317
Yey, awesome! But, @IgorMinar I can't see those commits in master: https://github.com/angular/angular.js/commits/master
I guess I'm just blind or something is messed up with the git repo....
I think they broke something and got reverted...
they are in master now. there was an issue with IE8, but that's fixed now.
I still don't see a fix with that or a similar title on master. @IgorMinar, has this really been fixed in a completely different commit?
This is a great feature!! why to take it down?
Please consider introducing a custom operator (#, @ or something else) to make promise unwrapping explicit. For example:
- ng-options="item.name for item in items#"
- {{items#[0].name}}
Both cases can be implemented using a function which unwraps the promise (i.e. unwrap(items) instead of items#). The function would be something along the lines of:
if (!('$$v' in promise)) {
promise.$$v = undefined;
promise.then(function(val) { promise.$$v = val; });
}
return promise.$$v;