Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

refactor($http): remove unneeded call to $apply #13128

Closed
wants to merge 1 commit into from

Conversation

thorn0
Copy link
Contributor

@thorn0 thorn0 commented Oct 20, 2015

This $apply call was needed only for tests, so it's been moved to $httpBackend.flush. An example of such a test can be found in ngIncludeSpec.js. It fails if $digest isn't synchronously invoked after each response. See also the comments I included in the code of the tests.

BREAKING CHANGE: $httpProvider.useApplyAsync was removed

Closes #13108
Closes #13111

@thorn0 thorn0 force-pushed the http-remove-unneeded-apply branch 2 times, most recently from c2e24b9 to 305dd5d Compare October 20, 2015 00:46
@gkalpak
Copy link
Member

gkalpak commented Nov 5, 2015

@thorn0, I finally got around to taking a proper look. It generally lgtm, with the exceptions of the changes to tests. It's too much imo (and this doesn't properly reflect the fact that the actual implications in behaviour are minimal).
I will submit a cleaned up (imo) version of the test-related changes later, so we can discuss further.

@petebacondarwin, I guess we are OK with the BC for v1.5.x. Also, wondering if, by essentially making applyAsync the default (and only) behaviour, we are breaking someone's app. I would be very surprized if someone relied on the fact that there would be a digest after each and every response (and before any other response's promise gets resolved).
All things considered, I don't think it's worth getting it into v1.4.x (but it's not difficult either).
(If we decided to backport it, we could avoid the BC of removing useApplyAsync(), by replacing it with a noop (and possibly logging a deprecation message).)

So, are we OK with having applyAsync as the default (and only) behaviour for v1.5.x ?

gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 5, 2015
gkalpak added a commit to gkalpak/angular.js that referenced this pull request Nov 5, 2015
@gkalpak
Copy link
Member

gkalpak commented Nov 5, 2015

See gkalpak@e00f10c (wrt to the test changes).

@thorn0
Copy link
Contributor Author

thorn0 commented Nov 5, 2015

@gkalpak My main objection against your cleanup is that if we leave $httpBackend.flush unchanged, we'll for sure break a lot of unit tests. Just like in your version of that test in ngIncludeSpec, it's totally counter-intutive that $httpBackend.flush() must be invoked multiple times in a row for everything to start working.

I would be very surprized if someone relied on the fact that there would be a digest after each and every response

Actually, lots of code relies on this. And this code is unit tests. That's why $httpBackend.flush has to be accordingly modified.

@jprince
Copy link

jprince commented Nov 17, 2015

My main objection against your cleanup is that if we leave $httpBackend.flush unchanged, we'll for sure break a lot of unit tests. Just like in your version of that test in ngIncludeSpec, it's totally counter-intutive that $httpBackend.flush(); must be invoked multiple times in a row for everything to start working.

FWIW I stumbled upon this PR while investigating why setting useApplyAsynch(true) when upgrading to 1.4.x has caused a few of my unit tests to fail. Thankfully someone had done a nice writeup on this issue (http://www.klaascuvelier.be/2015/09/angular-applyasync-httpbackend/) which helped me identify the remediation. At any rate, I agree with @thorn0 that the "solution" of invoking $httpBackend.flush(); multiple times is unintuitive.

@petebacondarwin petebacondarwin modified the milestones: 1.4.8, 1.5.0-beta.2 Nov 17, 2015
@matsko matsko modified the milestones: 1.5.0-beta.2, 1.5.0-beta.3 Nov 18, 2015
@petebacondarwin
Copy link
Member

We are not going to get this into 1.5.0.

@jbedard
Copy link
Contributor

jbedard commented May 25, 2017

What ever happened to this? What do people think about something like this or maybe just removing useApplyAsync (and making it always true)? It would be nice to remove such flags...

@thorn0
Copy link
Contributor Author

thorn0 commented Feb 5, 2018

Can we probably at least deprecate useApplyAsync (and scope#$applyAsync) in 1.7?

@gkalpak
Copy link
Member

gkalpak commented Feb 5, 2018

What is wrong with scope#$applyAsync()?

@thorn0
Copy link
Contributor Author

thorn0 commented Feb 5, 2018

Internally it's used only in $http for useApplyAsync. As a public API, it's very confusing because it's not clear at all what its purpose is and why one would prefer it over $evalAsync.

This `$apply` call was needed only for tests, so it's been moved to `$httpBackend.flush`.

BREAKING CHANGE: `$httpProvider.useApplyAsync` has been removed.

Closes angular#13108
Closes angular#13111
@Narretz Narretz modified the milestones: 1.6.x, 1.7.x Apr 12, 2018
@jbedard jbedard self-assigned this May 5, 2018
@petebacondarwin
Copy link
Member

Thanks for this @thorn0 - at this point in the project's lifecycle we don't feel that this adds enough value to be worth the potential breaking change. So we are going to close this as won't merge.

@thorn0
Copy link
Contributor Author

thorn0 commented May 26, 2018

@petebacondarwin We should've at least removed/deprecated $httpProvider.useApplyAsync, which does nothing but, as per the docs, promises 'significant performance improvement'.

@gkalpak
Copy link
Member

gkalpak commented May 26, 2018

AFAICT, with useApplyAsync(false) there can indeed be more digests triggered. So, useApplyAsync(true) should indeed offer better performance.

@thorn0
Copy link
Contributor Author

thorn0 commented May 27, 2018

Oh, right. So why not make it the default behavior?

@gkalpak
Copy link
Member

gkalpak commented May 27, 2018

Because it might be a breaking change. In retrospect, I'm not sure why we didn't do it for 1.7.0 😕

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants