<commit_before>/*!
 * backbone.layoutmanager.js v0.5.0
 * Copyright 2012, <NAME> (@tbranyen)
 * backbone.layoutmanager.js may be freely distributed under the MIT license.
 */
(function(window) {

"use strict";

// Alias the libraries from the global object
var Backbone = window.Backbone;
var _ = window._;
var $ = window.$;

var LayoutManager = Backbone.View.extend({
  // This is a named function to improve logging and debugging within browser
  // dev tools.  Typically you do not use "anonymous" named functions since IE
  // has a well known bug, BUT I think we all know the reason why I'm ignoring
  // that here.
  constructor: function LayoutManager(options) {
    options = options || {};

    // Apply the default render scheme.
    this._render = function(manage) {
      return manage(this).render();
    };

    // Ensure the View is setup correctly
    LayoutManager.setupView(this, options);

    // Set the prefix for a layout
    if (options.paths) {
      this._prefix = options.paths.layout || "";
    }

    // Have Backbone set up the rest of this View
    Backbone.View.call(this, options);
  },

  // Shorthand to root.view function with append flag.
  insertView: function(partial, view) {
    if (view) {
      return this.setView(partial, view, true);
    }

    // Omitting a partial will place the View directly into the parent.
    return this.setView(partial, true);
  },

  // Works like insertView, except allows you to bulk insert via setViews.
  insertViews: function(views) {
    // Ensure each view is wrapped in an array.
    _.each(views, function(view, selector) {
      views[selector] = [].concat(view);
    });

    return this.setViews(views);
  },

  // Will return a single view that matches the filter function.
  getView: function(fn) {
    return this.getViews(fn).first().value();
  },

  // Provide a filter function to get a flattened array of all the subviews.
  // If the filter function is omitted it will return all subviews.
  getViews: function(fn) {
    // Flatten all views.
    var views = _.chain(this.views).map(function(view) {
      return [].concat(view);
    }, this).flatten().value();

    // Return a wrapped function to allow for easier chaining.
    return _.chain(_.filter(views, fn ? fn : _.identity));
  },

  // This takes in a partial name and view instance and assigns them to
  // the internal collection of views.  If a view is not a LayoutManager
  // instance, then mix in the LayoutManager prototype.  This ensures
  // all Views can be used successfully.
  //
  // Must definitely wrap any render method passed in or defaults to a
  // typical render function `return layout(this).render()`.
  setView: function(name, view, append) {
    var partials, options;
    var root = this;

    // If no name was passed, use an empty string and shift all arguments.
    if (!_.isString(name)) {
      append = view;
      view = name;
      name = "";
    }

    // If the parent View's object, doesn't exist... create it.
    this.views = this.views || {};
    // Ensure remove is called when swapping View's.
    if (!append && this.views[name]) {
      this.views[name].remove();
    }

    // Instance overrides take precedence, fallback to prototype options.
    options = view._options();

    // Ensure render is set correctly.
    if (options.render !== LayoutManager.prototype.options.render) {
      view.render = options.render;<commit_msg>Correctly call remove() when child views are swapped. Fix #90<commit_after>/*!
 * backbone.layoutmanager.js v0.5.0
 * Copyright 2012, <NAME> (@tbranyen)
 * backbone.layoutmanager.js may be freely distributed under the MIT license.
 */
(function(window) {

"use strict";

// Alias the libraries from the global object
var Backbone = window.Backbone;
var _ = window._;
var $ = window.$;

var LayoutManager = Backbone.View.extend({
  // This is a named function to improve logging and debugging within browser
  // dev tools.  Typically you do not use "anonymous" named functions since IE
  // has a well known bug, BUT I think we all know the reason why I'm ignoring
  // that here.
  constructor: function LayoutManager(options) {
    options = options || {};

    // Apply the default render scheme.
    this._render = function(manage) {
      return manage(this).render();
    };

    // Ensure the View is setup correctly
    LayoutManager.setupView(this, options);

    // Set the prefix for a layout
    if (options.paths) {
      this._prefix = options.paths.layout || "";
    }

    // Have Backbone set up the rest of this View
    Backbone.View.call(this, options);
  },

  // Shorthand to root.view function with append flag.
  insertView: function(partial, view) {
    if (view) {
      return this.setView(partial, view, true);
    }

    // Omitting a partial will place the View directly into the parent.
    return this.setView(partial, true);
  },

  // Works like insertView, except allows you to bulk insert via setViews.
  insertViews: function(views) {
    // Ensure each view is wrapped in an array.
    _.each(views, function(view, selector) {
      views[selector] = [].concat(view);
    });

    return this.setViews(views);
  },

  // Will return a single view that matches the filter function.
  getView: function(fn) {
    return this.getViews(fn).first().value();
  },

  // Provide a filter function to get a flattened array of all the subviews.
  // If the filter function is omitted it will return all subviews.
  getViews: function(fn) {
    // Flatten all views.
    var views = _.chain(this.views).map(function(view) {
      return [].concat(view);
    }, this).flatten().value();

    // Return a wrapped function to allow for easier chaining.
    return _.chain(_.filter(views, fn ? fn : _.identity));
  },

  // This takes in a partial name and view instance and assigns them to
  // the internal collection of views.  If a view is not a LayoutManager
  // instance, then mix in the LayoutManager prototype.  This ensures
  // all Views can be used successfully.
  //
  // Must definitely wrap any render method passed in or defaults to a
  // typical render function `return layout(this).render()`.
  setView: function(name, view, append) {
    var partials, options;
    var root = this;

    // If no name was passed, use an empty string and shift all arguments.
    if (!_.isString(name)) {
      append = view;
      view = name;
      name = "";
    }

    // If the parent View's object, doesn't exist... create it.
    this.views = this.views || {};

    // Ensure remove is called when swapping View's.
    if (!append && this.views[name]) {
      this.views[name].remove();
    }

    // Instance overrides take precedence, fallback to prototype options.
    options = view._options();

    // Ensure render is set correctly.
    if (options.render !== LayoutManager.prototype.options.render) {
      view.render = options.render;
{'fraction_non_alphanumeric': 0.1109662465594669, 'fraction_numerical': 0.0023178328263074024, 'mean_word_length': 2.8312985571587124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2327381', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1911, 'n_words': 750}