Repository navigation
perf(autocomplete): Use virtual repeat... #3733
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,21 +155,26 @@ function MdAutocomplete () { | |
| <md-progress-linear\ | ||
| ng-if="$mdAutocompleteCtrl.loading && !$mdAutocompleteCtrl.hidden"\ | ||
| md-mode="indeterminate"></md-progress-linear>\ | ||
| <ul role="presentation"\ | ||
| class="md-autocomplete-suggestions md-whiteframe-z1 {{menuClass || \'\'}}"\ | ||
| id="ul-{{$mdAutocompleteCtrl.id}}"\ | ||
| ng-hide="$mdAutocompleteCtrl.hidden"\ | ||
| ng-mouseenter="$mdAutocompleteCtrl.listEnter()"\ | ||
| ng-mouseleave="$mdAutocompleteCtrl.listLeave()"\ | ||
| ng-mouseup="$mdAutocompleteCtrl.mouseUp()">\ | ||
| <li ng-repeat="(index, item) in $mdAutocompleteCtrl.matches"\ | ||
| ng-class="{ selected: index === $mdAutocompleteCtrl.index }"\ | ||
| ng-click="$mdAutocompleteCtrl.select(index)"\ | ||
| md-autocomplete-list-item="$mdAutocompleteCtrl.itemName">\ | ||
| ' + itemTemplate + '\ | ||
| </li>\ | ||
| ' + noItemsTemplate + '\ | ||
| </ul>\ | ||
| <md-virtual-repeat-container\ | ||
| md-auto-shrink\ | ||
| md-auto-shrink-min="1"\ | ||
| ng-hide="$mdAutocompleteCtrl.hidden && !$mdAutocompleteCtrl.notFoundVisible()"\ | ||
| class="md-autocomplete-suggestions-container md-whiteframe-z1"\ | ||
| role="presentation">\ | ||
| <ul class="md-autocomplete-suggestions"\ | ||
| ng-class="::menuClass"\ | ||
| id="ul-{{$mdAutocompleteCtrl.id}}"\ | ||
| ng-mouseenter="$mdAutocompleteCtrl.listEnter()"\ | ||
| ng-mouseleave="$mdAutocompleteCtrl.listLeave()"\ | ||
| ng-mouseup="$mdAutocompleteCtrl.mouseUp()">\ | ||
| <li md-virtual-repeat="item in $mdAutocompleteCtrl.matches"\ | ||
| ng-class="{ selected: $index === $mdAutocompleteCtrl.index }"\ | ||
| ng-click="$mdAutocompleteCtrl.select($index)"\ | ||
| md-extra-name="$mdAutocompleteCtrl.itemName">\ | ||
| ' + itemTemplate + '\ | ||
| </li>' + noItemsTemplate + '\ | ||
| </ul>\ | ||
| </md-virtual-repeat-container>\ | ||
| </md-autocomplete-wrap>\ | ||
| <aria-status\ | ||
| class="md-visually-hidden"\ | ||
|
|
@@ -178,21 +183,19 @@ function MdAutocomplete () { | |
| <p ng-repeat="message in $mdAutocompleteCtrl.messages track by $index" ng-if="message">{{message}}</p>\ | ||
| </aria-status>'; | ||
|
|
||
| function getItemTemplate () { | ||
| var templateTag = element.find('md-item-template').remove(), | ||
| html = templateTag.length ? templateTag.html() : element.html(); | ||
| function getItemTemplate() { | ||
| var templateTag = element.find('md-item-template').detach(), | ||
| html = templateTag.length ? templateTag.html() : element.html(); | ||
| if (!templateTag.length) element.empty(); | ||
| return html; | ||
| } | ||
|
|
||
| function getNoItemsTemplate () { | ||
| var templateTag = element.find('md-not-found').remove(), | ||
| template = templateTag.length ? templateTag.html() : ''; | ||
| function getNoItemsTemplate() { | ||
| var templateTag = element.find('md-not-found').detach(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is just being used as a template (and angular isn't actually parsing it) - does it matter if we use remove or detach?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/angular/angular.js/blob/master/src/jqLite.js remove will call into jqLiteDealloc, which tries to find data associated with the elements to clean up. In this case we can be confident that such data does not exist, so detach is faster.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, very cool! |
||
| template = templateTag.length ? templateTag.html() : ''; | ||
| return template | ||
| ? '<li ng-if="!$mdAutocompleteCtrl.matches.length && !$mdAutocompleteCtrl.loading\ | ||
| && !$mdAutocompleteCtrl.hidden"\ | ||
| ng-hide="$mdAutocompleteCtrl.hidden"\ | ||
| md-autocomplete-parent-scope>' + template + '</li>' | ||
| ? '<li ng-if="$mdAutocompleteCtrl.notFoundVisible()"\ | ||
| md-autocomplete-parent-scope>' + template + '</li>' | ||
| : ''; | ||
|
|
||
| } | ||
|
|
||
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.
So, I think I get it: You just have to
scope.$apply(), then$timeout.flush(), then$$rAF.flush(), then againscope.$apply(), then finally$$rAF.flush()again and...BAM...virtual-repeat ready !!!Nice !
(Some comments would be also nice here, but I guess that's not very straightforward.)
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.
LOL - completely obvious.
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.
as @gkalpak says, the code is 100% self-documenting and not confusing at all.
However, I've added some comments as well.