-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
When a parsed function call returns a promise, the evaluated value is the resolved value of the promise rather than the promise object. Closes #3503
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -689,9 +689,21 @@ function parser(text, json, $filter, csp){ | |
} | ||
var fnPtr = fn(scope, locals, context) || noop; | ||
// IE stupidity! | ||
return fnPtr.apply | ||
var v = fnPtr.apply | ||
? fnPtr.apply(context, args) | ||
: fnPtr(args[0], args[1], args[2], args[3], args[4]); | ||
|
||
// Check for promise | ||
if (v && v.then) { | ||
var p = v; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jussik
Author
Contributor
|
||
if (!('$$v' in v)) { | ||
p.$$v = undefined; | ||
p.then(function(val) { p.$$v = val; }); | ||
} | ||
v = v.$$v; | ||
This comment has been minimized.
Sorry, something went wrong.
xrg
|
||
} | ||
|
||
return v; | ||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -846,6 +846,18 @@ describe('parser', function() { | |
expect(scope.$eval('greeting')).toBe(undefined); | ||
}); | ||
|
||
it('should evaluate a function call returning a promise and eventually get its return value', function() { | ||
scope.greetingFn = function() { return promise; }; | ||
expect(scope.$eval('greetingFn()')).toBe(undefined); | ||
This comment has been minimized.
Sorry, something went wrong.
xrg
|
||
|
||
scope.$digest(); | ||
expect(scope.$eval('greetingFn()')).toBe(undefined); | ||
|
||
deferred.resolve('hello!'); | ||
expect(scope.$eval('greetingFn()')).toBe(undefined); | ||
scope.$digest(); | ||
expect(scope.$eval('greetingFn()')).toBe('hello!'); | ||
}); | ||
|
||
describe('assignment into promises', function() { | ||
// This behavior is analogous to assignments to non-promise values | ||
|
6 comments
on commit 3a65822
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.
With this I'm getting an error in Angular-UI Typeahead. When calling "parserResult.source(scope, locals)" it returns "undefined".
So, maybe there is something wrong in your commit?
https://github.com/angular-ui/bootstrap/blob/master/src/typeahead/typeahead.js#L99
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.
Here is a fiddle of the broken state in 1.1.5: http://jsfiddle.net/Y6Myh/1/
I just found this today and glad to see it's been fixed!
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.
That change made $parse pretty useless when using promises (forced to use $watch now).
See angular-ui/bootstrap#949 for an exemple.
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 change makes a pretty big assumption about how promises returned by expressions are intended to be used. Even if it suits the majority case, we need some way to parse an expression and get the raw promise back. Are there any plans to provide an alternate service that doesn't do magical unwrapping?
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.
@wilsonjackson - Perhaps you could open a new issue to discuss this?
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.
@petebacondarwin Submitted #4158
What is the point in copying here?