This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix/perf(tabs): Fix performance and visual issues.
Initially, the tabs used DOMSubtreeModified to listen for changes and update the height, pagination and inkbar styles. At some point, we used a different method to update the height, but we were still watching all DOM changes and updating the pagination and inkbar styles whenever the contents changed. Fix this with the following two changes: 1. Move the DOM watching to a new md-tabs-dummy-wrapper directive which only watches for changes to the tab's labels (not the content too) so that the updates are called less frequently. 2. Replace DOMSubtreeModified watching with new MutationObservers which are more drastically more performant. Additionally, some recent changes caused some bugs in the tabs by using a cached version of the internal elements instead of calling `getElements()` which searches the DOM and refreshes the cached elements. Fix by adding more calls to `getElements()` where appropriate to properly update the cache after tabs may have changed. Fixes #5681. References #4940, and might cause PR #8293 to need a rebase if this goes in first. Closes #8496
- Loading branch information
1 parent
077769b
commit 77958a1
Showing
5 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
angular | ||
.module('material.components.tabs') | ||
.directive('mdTabsDummyWrapper', MdTabsDummyWrapper); | ||
|
||
/** | ||
* @private | ||
* | ||
* @param $mdUtil | ||
* @returns {{require: string, link: link}} | ||
* @constructor | ||
* | ||
* @ngInject | ||
*/ | ||
function MdTabsDummyWrapper ($mdUtil) { | ||
return { | ||
require: '^?mdTabs', | ||
link: function link (scope, element, attr, ctrl) { | ||
if (!ctrl) return; | ||
|
||
var observer = new MutationObserver(function(mutations) { | ||
ctrl.updatePagination(); | ||
ctrl.updateInkBarStyles(); | ||
}); | ||
var config = { childList: true, subtree: true }; | ||
|
||
observer.observe(element[0], config); | ||
|
||
// Disconnect the observer | ||
scope.$on('$destroy', function() { | ||
if (observer) { | ||
observer.disconnect(); | ||
} | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters