-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refactor($http): coalesce calls to $rootScope.$apply WIP #7634
Conversation
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
@@ -81,7 +81,7 @@ function $RootScopeProvider(){ | |||
|
|||
this.$get = ['$injector', '$exceptionHandler', '$parse', '$browser', | |||
function( $injector, $exceptionHandler, $parse, $browser) { | |||
|
|||
var $timeout; |
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.
Could not inject this directly, due to circular dependencies
I agree that having a solution that works for $http (and any other service that may run into this same issue) would be very nice. Now I do have a few open questions: 1/ I find odd the circular dependency between $rootScope and $timeout
Should there be a second $digets? 3/ Another scenario
Why should the second process wait for 100000000 for the apply to happen? Having different behaviors depending in the way this function is being called can have some unexpected consequences |
Yeah, I'm not really set in stone on the "configurable debounce time" thing, the default timeout may be good enough for many cases. Or maybe instead, there could be a different debounce time for each service. I'm not set on all that. Currently only $http uses it at all, anyways. As for the circular dependency, well you can do this with just $browser.defer() --- but this kind of sucks for testing purposes Actually, browser.defer probably is good enough, since the timeout mock just wraps it. |
There should be only single delay value used by everyone and it should mean "delay at most for X ms". |
@kseamon could you test this on DFA? The workaround that Caitlin came up with means that tests remain mostly unaffected, which is quite nice even though I'd like the implementation to be less hacky. |
@kseamon any word on this? It would be good to hear back regarding this =) |
Hi. I had a working but incomplete demo as of December. Not sure how useful it https://github.com/kseamon/angular.js/tree/http-coalesce The main thing that is missing is having $apply flush the $applyAsync queue Well, that and unit tests, which are ultimately what scared me off of the -Karl On Thu, Jul 31, 2014 at 1:54 PM, Caitlin Potter notifications@github.com
|
* the value used is 0. The default is 10. | ||
*/ | ||
this.debounceApply = function(timeout) { | ||
APPLY_ASYNC_WAIT = timeout; |
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.
Shouldn't be named like a constant
Not sure if it's intentionally being left out, but in my unfinished version from a while back, I also had the cookies service use async apply. |
@IgorMinar and I discussed this at some length. We're going to sit down with @kseamon next Wednesday 8/20 to run some experiments and get some more data behind the approach. Here are some initial thoughts, but these are just for discussion at this point:
|
My thoughts:
So, from my POV, I really don't think we should be making this configurable per-request. and I really don't think it should be configurable at all --- unless there's a use case where you'd want to use it most of the time but occasionally not, I don't see the value in making the API more complicated for this. Making the angular api even crazier is really not something that I think we should be doing unless people ask for it. What does the WG think about that? |
Current state of this: support for evaluating expressions like $evalAsync has not been added -- but it's
trivial to add this.
There are some mock helpers added to enable better testing, although they aren't documented since they
are not likely to be useful to users of the library.
Currently, there's a configuration method to allow users to define the debounce time for $http responses,
but I'm not opposed to removing this, as it doesn't seem particularly useful under normal circumstances.