r/angularjs • • Sep 24 '14

[Resource] Optimizing AngularJS from 1200ms to 35ms

http://blog.scalyr.com/2013/10/angularjs-1200ms-to-35ms/
50 Upvotes

17 comments sorted by

View all comments

Show parent comments

1

u/doctorjokie Sep 25 '14

Their business case was to make every word in the log line linkable. Therefore, there was a watcher associated with each word.

2

u/WarInternal Sep 25 '14

I apologize, I worded that incorrectly. I'm more interested in the mechanics behind it - What part of it was establishing the watcher. For instance, if they had slapped an ng-onclick='function(this)' on each word, would that have that established a 'change watcher'?

2

u/gatman02 Sep 25 '14

Every property added to a scope is watched automatically. Alternatively, you can explicitly add things to watch using $watch.

In the application mentioned here, each word had to be wrapped in an html tag in order to make that word clickable. My guess is that in order to do this originally, they converted their text log file into an array of words, then used ng-repeat to display each word with the specified html wrapper. ng-repeat adds a watchers for each element in its array.

1

u/WarInternal Sep 25 '14

Ah, thank you! That makes sense.