Uh oh!
There was an error while loading. Please reload this page.
fix(autocomplete): improve promise logic - #6521
Conversation
googlebot
commented
Jan 3, 2016
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
winniehell
commented
Jan 3, 2016
@googlebot I signed it! |
googlebot
commented
Jan 3, 2016
CLAs look good, thanks! |
48f668d to
a3fd0e9Comparewinniehell
commented
Jan 3, 2016
Failing tests seem to be unrelated as they appear e.g. in #6515 (build 99782625) and #6518 (build 99851677) as well. Not sure what I can do about it... 👽❓ |
devversion
commented
Jan 3, 2016
The tests of the whole project are currently failing. That's not an issue from you ;) And now to the PR, I thought we using here the Promise Service from Angular. See here. This a implementation inspired by https://github.com/kriskowal/q Am I wrong? |
winniehell
commented
Jan 3, 2016
@devversion you are right that it is usual to use There are two reasons for me not to use
|
devversion
commented
Jan 3, 2016
Can be true, I don't know about A+ etc. But in this context of code we using DI to get the $q service of Angular, so there won't be any other Deferred API, that's why I think this change is not needed. |
winniehell
commented
Jan 3, 2016
Even though |
winniehell
commented
Jan 3, 2016
For clarification: the effect on |
always reset loading state of autocomplete after handleResults() even if promise implementation does not support finally()
a3fd0e9 to
3588c0aComparewinniehell
commented
Jan 27, 2016
Tests are now all green. |
There was a problem hiding this comment.
Why not use the $q.when( ) to wrap angular & foreign promises:
functionfetchResults(searchText){varitems=$scope.$parent.$eval(itemExpr),term=searchText.toLowerCase(),isList=angular.isArray(items);if(isList)handleResults(items);elsehandleAsyncResults(items);functionhandleAsyncResults(items){if(!items)return;items=$q.when(items);setLoading(true);$mdUtil.nextTick(function(){items.finally(function(){setLoading(false);});},true,$scope);}}There was a problem hiding this comment.
PR #6860 also suggest not listening for .success( ).
There was a problem hiding this comment.
@ThomasBurleson Probably a good point, but this is a complaint on the original code, not this PR.
There was a problem hiding this comment.
@winniehell - please incorporate my suggestions ^^ and test. This will make the merged code better moving forward.
ThomasBurleson
commented
Jan 28, 2016
@robertmesserle - can you review? |
robertmesserle
commented
Jan 28, 2016
@ThomasBurleson LGTM |
winniehell
commented
Feb 2, 2016
@ThomasBurleson: I'll try to rework this including your comments and a fix for #6860. |
winniehell
commented
Feb 5, 2016
@ThomasBurleson: Alright, I was still trying to figure out, how to write a test for it. Thank you for fixing this! 👍 😃 |
The
finally-function supported by q is not part of the A+ spec. Therefore, other promise implementations do not have it (e.g. the promise polyfill in babel). To ensure thatmd-autocompleteresets its loading state properly, I usedtheniffinallyis not available.This pull request was joined with #6860.