zRains commented on code in PR #3801:
URL: https://github.com/apache/ambari/pull/3801#discussion_r1701185657


##########
ambari-web/app/views/application.js:
##########
@@ -48,13 +48,25 @@ App.ApplicationView = Em.View.extend({
    */
   initNavigationBar: function () {
     if (App.get('router.mainController.isClusterDataLoaded')) {
-      $('body').on('DOMNodeInserted', '.navigation-bar', () => {
-        $('.navigation-bar').navigationBar({
-          fitHeight: true,
-          collapseNavBarClass: 'icon-double-angle-left',
-          expandNavBarClass: 'icon-double-angle-right'
-        });
-        $('body').off('DOMNodeInserted', '.navigation-bar');
+      const observer = new MutationObserver(mutations => {
+        if (document.querySelector('.navigation-bar')) {
+          observer.disconnect();
+          $('.navigation-bar').navigationBar({
+            fitHeight: true,
+            collapseNavBarClass: 'icon-double-angle-left',
+            expandNavBarClass: 'icon-double-angle-right'
+          });
+        }

Review Comment:
   The number of executions can be reduced.
   ```suggestion
           var targetNode
           mutations.forEach(mutation => {
             if (mutation.type === 'childList' && (targetNode = 
$('.navigation-bar')).length) {
               observer.disconnect();
               targetNode.navigationBar({
                 fitHeight: true,
                 collapseNavBarClass: 'icon-double-angle-left',
                 expandNavBarClass: 'icon-double-angle-right'
               });
             }
           })
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to