var BindableObject = require("../object"),
computed           = require("../utils/computed");

/**
 */
 
function BindableCollection(source) {
  BindableObject.call(this, this);
  this._source = source || [];
  this.length = this._source.length;
}

/**
 */

BindableObject.extend(BindableCollection, {

  /**
   */

  source: function (source) {
    this._source = source;
    this._updateInfo();
    this.emit("reset", source);
  },

  /**
   */

  indexOf: function (item) {
    return this._source.indexOf(item);
  },

  /**
   */

  at: function (index) {
    this._source[index];
  },

  /**
   */

  push: function (item) {
    this._source.push(item);
    this._updateInfo();
    this.emit("insert", { item: item, index: this._source.length - 1 });
  },

  /**
   */

  unshift: function (item) {
    this._source.push(item);
    this._updateInfo();
    this.emit("insert", { item: item, index: 0 });
  },

  /**
   */

  splice: function (index, count) {
    var newItems = Array.prototype.slice.call(arguments, 2),
    oldItems     = this._source.splice.apply(this._source, arguments);
    this.emit("replace", { newItems: newItems, oldItems: oldItems, index: index });
  },

  /**
   */

  remove: function (item) {
    var i = this.indexOf(item);
    if (!~i) return false;
    this._source.splice(i, 1);
    this._updateInfo();
    this.emit("remove", { item: item, index: i });
  },

  /**
   */

  _updateInfo: function () {
    this.set("length", this._source.length);
  }
});

module.exports = BindableCollection;

@@ -96,17 +96,16 @@
 /**%0A */%0A
- 
 %0Afunctio
@@ -596,16 +596,111 @@
 %0A   */%0A%0A
+  each: computed(%5B%22length%22%5D, function (fn) %7B%0A    this._source.forEach(fn);%0A  %7D),%0A%0A  /**%0A   */%0A%0A
   push: 

define each as a computed property