torso-bundle.js
function(oldViews, newViews, staleViews) {
      var firstItemViewLeft, injectionSite,
        view = this,
        sizeOfOldViews = _.size(oldViews),
        sizeOfNewViews = _.size(newViews),
        sizeOfStaleViews = _.size(staleViews);
      if (view.itemContainer && sizeOfOldViews && sizeOfOldViews == sizeOfStaleViews) {
        // we removed all the views!
        injectionSite = $('<span>');
        _.first(oldViews).$el.before(injectionSite);
      }
      view.__removeStaleItemViews(staleViews);
      _.each(newViews, function(createdViewInfo, indexOfView) {
        if (createdViewInfo.indexOfModel === 0) {
          // need to handle this case uniquely.
          var replaceMethod;
          if (!view.itemContainer) {
            replaceMethod = _.bind(view.$el.prepend, view.$el);
          } else {
            if (injectionSite) {
              replaceMethod = _.bind(injectionSite.replaceWith, injectionSite);
            } else {
              var staleModelIdMap = _.indexBy(staleViews, 'modelId');
              var firstModelIdLeft = _.find(view.__orderedModelIdList, function(modelId) {
                return !staleModelIdMap[modelId];
              });
              firstItemViewLeft = view.getTrackedView(view.__modelToViewMap[firstModelIdLeft]);
              replaceMethod = _.bind(firstItemViewLeft.$el.prepend, firstItemViewLeft.$el);
            }
          }
          view.attachView(null, createdViewInfo.view, {
            replaceMethod: replaceMethod,
            discardInjectionSite: true
          });
        } else {
          // There will always the view before this one because we are adding new views in order
          // and we took care of the initial case.
          _addItemView.call(view, createdViewInfo.view, createdViewInfo.indexOfModel);
        }
      });
      this.reorder();
    }
function(oldViews, newViews, staleViews) {
      var firstItemViewLeft, injectionSite,
        view = this,
        sizeOfOldViews = _.size(oldViews),
        sizeOfNewViews = _.size(newViews),
        sizeOfStaleViews = _.size(staleViews);
      if (view.itemContainer && sizeOfOldViews && sizeOfOldViews == sizeOfStaleViews) {
        // we removed all the views!
        injectionSite = $('<span>');
        _.first(oldViews).$el.before(injectionSite);
      }
      view.__removeStaleItemViews(staleViews);
      _.each(newViews, function(createdViewInfo, indexOfView) {
        if (createdViewInfo.indexOfModel === 0) {
          // need to handle this case uniquely.
          var replaceMethod;
          if (!view.itemContainer) {
            replaceMethod = _.bind(view.$el.prepend, view.$el);
          } else {
            if (injectionSite) {
              replaceMethod = _.bind(injectionSite.replaceWith, injectionSite);
            } else {
              var staleModelIdMap = _.indexBy(staleViews, 'modelId');
              var firstModelIdLeft = _.find(view.__orderedModelIdList, function(modelId) {
                return !staleModelIdMap[modelId];
              });
              firstItemViewLeft = view.getTrackedView(view.__modelToViewMap[firstModelIdLeft]);
              replaceMethod = _.bind(firstItemViewLeft.$el.prepend, firstItemViewLeft.$el);
            }
          }
          view.attachView(null, createdViewInfo.view, {
            replaceMethod: replaceMethod,
            discardInjectionSite: true
          });
        } else {
          // There will always the view before this one because we are adding new views in order
          // and we took care of the initial case.
          _addItemView.call(view, createdViewInfo.view, createdViewInfo.indexOfModel);
        }
      });
      this.reorder();
    }
function ( oldViews , newViews , staleViews ) { var firstItemViewLeft , injectionSite , view = this , sizeOfOldViews = _ . size ( oldViews ) , sizeOfNewViews = _ . size ( newViews ) , sizeOfStaleViews = _ . size ( staleViews ) ; if ( view . itemContainer && sizeOfOldViews && sizeOfOldViews == sizeOfStaleViews ) { // we removed all the views! injectionSite = $ ( '<span>' ) ; _ . first ( oldViews ) . $el . before ( injectionSite ) ; } view . __removeStaleItemViews ( staleViews ) ; _ . each ( newViews , function ( createdViewInfo , indexOfView ) { if ( createdViewInfo . indexOfModel === 0 ) { // need to handle this case uniquely. var replaceMethod ; if ( ! view . itemContainer ) { replaceMethod = _ . bind ( view . $el . prepend , view . $el ) ; } else { if ( injectionSite ) { replaceMethod = _ . bind ( injectionSite . replaceWith , injectionSite ) ; } else { var staleModelIdMap = _ . indexBy ( staleViews , 'modelId' ) ; var firstModelIdLeft = _ . find ( view . __orderedModelIdList , function ( modelId ) { return ! staleModelIdMap [ modelId ] ; } ) ; firstItemViewLeft = view . getTrackedView ( view . __modelToViewMap [ firstModelIdLeft ] ) ; replaceMethod = _ . bind ( firstItemViewLeft . $el . prepend , firstItemViewLeft . $el ) ; } } view . attachView ( null , createdViewInfo . view , { replaceMethod : replaceMethod , discardInjectionSite : true } ) ; } else { // There will always the view before this one because we are adding new views in order // and we took care of the initial case. _addItemView . call ( view , createdViewInfo . view , createdViewInfo . indexOfModel ) ; } } ) ; this . reorder ( ) ; }
Attempts to insert new views and remove stale views individually and correctly reorder all views in an
attempt to be faster then a full view re-render
@method __updateByAddingRemoving
@param oldViews {Array of Views} - correctly ordered list of views before making changes to models to render
@param newViews {Array of Views} - the new views created that will be inserted
@param staleViews {Array of Views} - the stale views that will be removed
Attempts to insert new views and remove stale views individually and correctly reorder all views in an attempt to be faster then a full view re - render