★ wanayoo — archive 1999 https://github.com/firebase/angularfire/issues/411Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate using $evalAsync instead of $timeout #411

Closed
katowulf opened this issue Aug 27, 2014 · 7 comments
Closed

Investigate using $evalAsync instead of $timeout #411

katowulf opened this issue Aug 27, 2014 · 7 comments

Comments

@katowulf
Copy link
Member

@katowulf katowulf commented Aug 27, 2014

May be considerably faster at updating data and make for less timing issues.

http://www.bennadel.com/blog/2605-scope-evalasync-vs-timeout-in-angularjs.htm

@jwngr jwngr added the enhancement label Aug 27, 2014
@bendrucker
Copy link
Contributor

@bendrucker bendrucker commented Aug 28, 2014

+1. The example in the article is pretty silly since that's just bad code and not a case for eval async. Promises help you prevent you from shooting yourself in the foot in cases like this. Sometimes sync sometimes async is a nightmare (http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony).

But yes, evalAsync is the right tool for AF.

@gigablox
Copy link

@gigablox gigablox commented Aug 28, 2014

Where is $timeout being used that lead to this ticket?

@joshbowdoin
Copy link
Contributor

@joshbowdoin joshbowdoin commented Aug 28, 2014

I like this better than $timeout, but run into a few problems...

$evalAsync is a method on $scope... Which scope would AngularFire be using? I can't pass a scope to it from a service. The $rootScope I guess?

Also, it seems like the AngularJS team doesn't really see it being used this way (not sure why). From https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$evalAsync: "However, it is encouraged to always call code that changes the model from within an $apply call. That includes code evaluated via $evalAsync."

@joshbowdoin
Copy link
Contributor

@joshbowdoin joshbowdoin commented Aug 28, 2014

@katowulf
Copy link
Member Author

@katowulf katowulf commented Aug 28, 2014

$timeout is being called in $firebaseUtils

Also in $firebase in the $asArray and $asObject logic.

Also, it seems like the AngularJS team doesn't really see it being used this way

It's not practical to call all of our functions from within $apply--this leads to lots of messy introspection to make sure a $apply is not already in progress (it can be in several unpredictable ways), and I don't think that comment applies for us. Our use case seems to be inline with it's intent.

$evalSync will try to execute before the next DOM compile event, which is pretty ideal, and might even remove the need to batch our incoming events. I'll have to do some profiling and digging into the source to test that posit.

@bendrucker
Copy link
Contributor

@bendrucker bendrucker commented Nov 5, 2014

Seems like $applyAsync (new to 1.3) is the best bet: angular/angular.js@e94d454

This would eliminate any need to batch events and also has the big added benefit of getting coalesced with $http response propogation as well.

@jwngr jwngr added this to the 1.0.0 Release milestone Dec 17, 2014
@jwngr jwngr modified the milestones: 1.0.0 Release [low pri], 1.0.0 Release Jan 22, 2015
@katowulf
Copy link
Member Author

@katowulf katowulf commented Feb 12, 2015

This has been deferred until after 1.0 due to time constraints.

@katowulf katowulf modified the milestones: After 1.0 Release, 1.0.0 Release [low pri] Feb 12, 2015
@katowulf katowulf closed this in b7be0b8 Apr 22, 2015
jwngr pushed a commit that referenced this issue Apr 22, 2015
Fixes #411 - switch to $evalAsync() for improved performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.