Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upInvestigate using $evalAsync instead of $timeout #411
Comments
|
+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, |
|
Where is |
|
I like this better than
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." |
|
@gigablox - $timeout is being called in $firebaseUtils - https://github.com/firebase/angularfire/blob/master/src/utils.js#L173 |
Also in $firebase in the $asArray and $asObject logic.
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. |
|
Seems like This would eliminate any need to batch events and also has the big added benefit of getting coalesced with |
|
This has been deferred until after 1.0 due to time constraints. |
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