-
Notifications
You must be signed in to change notification settings - Fork 248
feat(scope): Automatically $digest futures inside of $apply. #55
Conversation
// NOTE(deboer): Missing headers. Ask the Dart team for a sane API. | ||
var response = new HttpResponse(value.status, value.responseText); | ||
var result; | ||
async.runZonedExperimental(() { |
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.
I don't think this is the right place for the zone. I think it should be in the root of angular bootstrap. Since it is not just HTTP futures which need to be zoned but any future anywhere in the codebase.
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.
Please make sure this works in dart2js.
I sat down with Misko and we hashed out a better approach. I'll update this PR when it is ready. |
The runZoned logic now runs inside of scope.$apply. If you wrap Futures in a scope.$apply, we will digest the scope whenever an asynchronous callback is run. |
// This will only throw exceptions from the runZoned body. | ||
// The async code will be executed after this check. | ||
if (toThrow != null) { | ||
throw toThrow; |
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.
it you throw toThrow, then you are starting a new stack trace. What you want to do is to re-throw, which is just throw; with no arg.
but if toThrow is null then you eat exception? Can you explain this logic?
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.
toThrow is passing the exception from the onError handler out to the $apply function.
If we rethrow the exception in the onError handler, the runZoned runner picks it up and we never see it again.
The "toThrow == null" is there so we throw the first exception, since we can only throw one exception in the $apply function. [ I should write a test for this behaviour... ]
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.
BTW, apparently throw; is deprecated. Gotta use "rethrow".
One comment, LGTM otherwise |
Landed in 46c671f |
No description provided.