lib/js/TreeView.js
function() {
      var t = this,
          branches = t.model.get('branches'),
          leaves = t.model.get('leaves');

      // Determine if we should connect a monitor to this node
      //
      // Connect a monitor if:
      // * There isn't one already connected, and
      // * There's a monitor definition available, and
      // * We're open, or
      // *   preFetch is selected, and
      // *     we have no parent or our parent is open
      //
      // ** Is there any way to make this logic simpler?
      var shouldConnect = !t.model.hasMonitor()
        && t.options.monitorParams
        && (t.model.get('isOpen')
          || (t.options.preFetch
            && (!t.options.parentView
              || t.options.parentView.model.get('isOpen'))));

      // Connect to the monitor if we've determined we should
      if (shouldConnect) {

        // If there isn't any model data to display, show Loading...
        if (!branches || !leaves) {
          t.loading = $('<li>Loading...</li>').appendTo(t.$el);
        }

        // Build and connect the Monitor
        var initParams = _.extend(
          {},
          t.options.monitorParams.initParams || {},
          {path:t.options.path}
        );
        var monitorParams = _.extend(
          {},
          t.options.monitorParams,
          {initParams: initParams}
        );
        t.monitor = new Monitor(monitorParams);
        t.model.attachMonitor(t.monitor);

        // Call our handlers once connected
        t.monitor.on('connect', function(){
          setTimeout(function(){
            for (var i in t.connectHandlers) {
              var handler = t.connectHandlers[i];
              handler(t.monitor);
            }
          },10);
        });

        // Connect the monitor and process errors.  Successes will change
        // the underlying data model (or not), causing a re-render.
        t.monitor.connect(function(error) {

          // Remove the Loading... message
          if (t.loading) {
            t.loading.remove();
            t.loading = null;
          }

          // Handle errors
          if (error) {
            $('<li>(connection problem)</li>').appendTo(t.$el);
            console.error('TreeView monitor connection problem:', error, t.monitor);

            // Detach the problem monitor so it'll have another chance
            // if the user opens/closes the branch.
            t.model.detachMonitor();
          }

        });
      }
    }
function() {
      var t = this,
          branches = t.model.get('branches'),
          leaves = t.model.get('leaves');

      // Determine if we should connect a monitor to this node
      //
      // Connect a monitor if:
      // * There isn't one already connected, and
      // * There's a monitor definition available, and
      // * We're open, or
      // *   preFetch is selected, and
      // *     we have no parent or our parent is open
      //
      // ** Is there any way to make this logic simpler?
      var shouldConnect = !t.model.hasMonitor()
        && t.options.monitorParams
        && (t.model.get('isOpen')
          || (t.options.preFetch
            && (!t.options.parentView
              || t.options.parentView.model.get('isOpen'))));

      // Connect to the monitor if we've determined we should
      if (shouldConnect) {

        // If there isn't any model data to display, show Loading...
        if (!branches || !leaves) {
          t.loading = $('<li>Loading...</li>').appendTo(t.$el);
        }

        // Build and connect the Monitor
        var initParams = _.extend(
          {},
          t.options.monitorParams.initParams || {},
          {path:t.options.path}
        );
        var monitorParams = _.extend(
          {},
          t.options.monitorParams,
          {initParams: initParams}
        );
        t.monitor = new Monitor(monitorParams);
        t.model.attachMonitor(t.monitor);

        // Call our handlers once connected
        t.monitor.on('connect', function(){
          setTimeout(function(){
            for (var i in t.connectHandlers) {
              var handler = t.connectHandlers[i];
              handler(t.monitor);
            }
          },10);
        });

        // Connect the monitor and process errors.  Successes will change
        // the underlying data model (or not), causing a re-render.
        t.monitor.connect(function(error) {

          // Remove the Loading... message
          if (t.loading) {
            t.loading.remove();
            t.loading = null;
          }

          // Handle errors
          if (error) {
            $('<li>(connection problem)</li>').appendTo(t.$el);
            console.error('TreeView monitor connection problem:', error, t.monitor);

            // Detach the problem monitor so it'll have another chance
            // if the user opens/closes the branch.
            t.model.detachMonitor();
          }

        });
      }
    }
function ( ) { var t = this , branches = t . model . get ( 'branches' ) , leaves = t . model . get ( 'leaves' ) ; // Determine if we should connect a monitor to this node // // Connect a monitor if: // * There isn't one already connected, and // * There's a monitor definition available, and // * We're open, or // *   preFetch is selected, and // *     we have no parent or our parent is open // // ** Is there any way to make this logic simpler? var shouldConnect = ! t . model . hasMonitor ( ) && t . options . monitorParams && ( t . model . get ( 'isOpen' ) || ( t . options . preFetch && ( ! t . options . parentView || t . options . parentView . model . get ( 'isOpen' ) ) ) ) ; // Connect to the monitor if we've determined we should if ( shouldConnect ) { // If there isn't any model data to display, show Loading... if ( ! branches || ! leaves ) { t . loading = $ ( '<li>Loading...</li>' ) . appendTo ( t . $el ) ; } // Build and connect the Monitor var initParams = _ . extend ( { } , t . options . monitorParams . initParams || { } , { path : t . options . path } ) ; var monitorParams = _ . extend ( { } , t . options . monitorParams , { initParams : initParams } ) ; t . monitor = new Monitor ( monitorParams ) ; t . model . attachMonitor ( t . monitor ) ; // Call our handlers once connected t . monitor . on ( 'connect' , function ( ) { setTimeout ( function ( ) { for ( var i in t . connectHandlers ) { var handler = t . connectHandlers [ i ] ; handler ( t . monitor ) ; } } , 10 ) ; } ) ; // Connect the monitor and process errors.  Successes will change // the underlying data model (or not), causing a re-render. t . monitor . connect ( function ( error ) { // Remove the Loading... message if ( t . loading ) { t . loading . remove ( ) ; t . loading = null ; } // Handle errors if ( error ) { $ ( '<li>(connection problem)</li>' ) . appendTo ( t . $el ) ; console . error ( 'TreeView monitor connection problem:' , error , t . monitor ) ; // Detach the problem monitor so it'll have another chance // if the user opens/closes the branch. t . model . detachMonitor ( ) ; } } ) ; } }
Determine if we should connect a monitor to the node, and connect if necessary.
Determine if we should connect a monitor to the node and connect if necessary .