Thorax.Mixins = {};

{{#inject "configure"}}
  //HelperView will not have mixins so need to check
  this.constructor.mixins && _.each(this.constructor.mixins, this.mixin, this);
  this.mixins && _.each(this.mixins, this.mixin, this);
{{/inject}}

{{#inject "extend"}}
  child.mixins = _.clone(this.mixins);
{{/inject}}

{{#inject "static-view-properties"}}
  _.extend(Thorax.View, {
    mixins: [],
    mixin: function(mixin) {
      this.mixins.push(mixin);
    },
    registerMixin: function(name, callback, methods) {
      Thorax.Mixins[name] = [callback, methods];
    }
  });
{{/inject}}

Thorax.View.prototype.mixin = function(name) {
  if (!this._appliedMixins) {
    this._appliedMixins = [];
  }
  if (this._appliedMixins.indexOf(name) == -1) {
    this._appliedMixins.push(name);
    if (typeof name === 'function') {
      name.call(this);
    } else {
      var mixin = Thorax.Mixins[name];
      _.extend(this, mixin[1]);
      //mixin callback may be an array of [callback, arguments]
      if (_.isArray(mixin[0])) {
        mixin[0][0].apply(this, mixin[0][1]);
      } else {
        mixin[0].apply(this, _.toArray(arguments).slice(1));
      }
    }
  }
};

function applyMixin(mixin) {
  if (_.isArray(mixin)) {
    this.mixin.apply(this, mixin);
  } else {
    this.mixin(mixin);
  }
}

Thorax.Mixins = {};

{{#inject "configure"}}
  //HelperView will not have mixins so need to check
  this.constructor.mixins && _.each(this.constructor.mixins, this.mixin, this);
  this.mixins && _.each(this.mixins, this.mixin, this);
{{/inject}}

{{#inject "extend"}}
  child.mixins = _.clone(this.mixins);
{{/inject}}

{{#inject "static-view-properties"}}
  _.extend(Thorax.View, {
    mixins: [],
    mixin: function(mixin) {
      this.mixins.push(mixin);
    },
    registerMixin: function(name, callback, methods) {
      Thorax.Mixins[name] = [callback, methods];
    }
  });
{{/inject}}

Thorax.View.prototype.mixin = function(name) {
  if (!this._appliedMixins) {
    this._appliedMixins = [];
  }
  if (this._appliedMixins.indexOf(name) == -1) {
    this._appliedMixins.push(name);
    if (typeof name === 'function') {
      name.call(this);
    } else {
      var mixin = Thorax.Mixins[name];
      _.extend(this, mixin[1]);
      //mixin callback may be an array of [callback, arguments]
      if (_.isArray(mixin[0])) {
        mixin[0][0].apply(this, mixin[0][1]);
      } else {
        mixin[0].apply(this, _.toArray(arguments).slice(1));
      }
    }
  }
};

Remove dead code