// Building a new feature that uses MutationObserver? You don't need to modify this file
// Instead of adding conditionals to this file try the example from /shared/example.js

(function poll() {
  if (ynabToolKit.pageReady === true && typeof ynabToolKit.shared.feedChanges !== 'undefined') {

    // When this is true, the feature scripts will know they can use the mutationObserver
    ynabToolKit.actOnChangeInit = {};

    // Set 'ynabToolKit.debugNodes = true' to print changes the mutationObserver sees
    // during page interactions and updates to the developer tools console.
    ynabToolKit.debugNodes = true;

    ynabToolKit.actOnChange = function() {

      MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

      var observer = new MutationObserver(function(mutations, observer) {

        if (ynabToolKit.debugNodes) {
          console.log('MODIFIED NODES');
        }

        ynabToolKit.changedNodes = new Set();

        mutations.forEach(function(mutation) {
          var newNodes = mutation.target;

          var $nodes = $(newNodes); // jQuery set
          $nodes.each(function() {
            var $node = $(this);

            try {
              nodeClasses = new Set($node[0].className.split(' '));
              ynabToolKit.changedNodes = new Set([...ynabToolKit.changedNodes, ...nodeClasses]);
            } catch(err) {
              ynabToolKit.debugNodes.errors = err
            }

          }); // each node mutation event

          if (ynabToolKit.debugNodes) {
            // console.log(newNodes);
          }

        }); // each mutation event

        if (ynabToolKit.debugNodes) {
          console.log(ynabToolKit.changedNodes);
          console.log('###');
        }

        // Now we are ready to feed the change digest to the
        // automatically setup feedChanges file/function
        ynabToolKit.shared.feedChanges(ynabToolKit.changedNodes);

      });

      // This finally says 'Watch for changes' and only needs to be called the one time
      observer.observe($('.ember-view.layout')[0], {
        subtree : true,
        childList : true,
        characterData : true,
        attributeFilter : [ 'class' ]
      });

      ynabToolKit.actOnChangeInit = true;
    };
    ynabToolKit.actOnChange(); // Run itself once

  } else {
    setTimeout(poll, 250);
  }
})();

@@ -607,19 +607,20 @@
 Nodes = 
-tru
+fals
 e;%0A%0A    
@@ -1043,16 +1043,103 @@
 .target;
+%0A          if (ynabToolKit.debugNodes) %7B%0A            console.log(newNodes);%0A          %7D
 %0A%0A      
@@ -1341,105 +1341,8 @@
 ));%0A
-              ynabToolKit.changedNodes = new Set(%5B...ynabToolKit.changedNodes, ...nodeClasses%5D);%0A
     
@@ -1443,82 +1443,94 @@
     
-%7D); // each node mutation event%0A%0A          if (ynabToolKit.debugNodes) %7B%0A 
+  ynabToolKit.changedNodes = new Set(%5B...ynabToolKit.changedNodes, ...nodeClasses%5D);%0A%0A
     
@@ -1539,46 +1539,39 @@
     
+%7D);
  // 
-console.log(newNodes);%0A          %7D
+each node mutation event
 %0A%0A  
@@ -1646,57 +1646,8 @@
 ) %7B%0A
-          console.log(ynabToolKit.changedNodes);%0A
     
@@ -1670,17 +1670,16 @@
 g('###')
-;
 %0A       

Revert act-on-change