(function() {

  this.def_class('Rome',DObject,function(__scope,__class){

    if(!this.__ctor__){this.__ctor__= function Rome(){}; this.__ctor__.prototype = this.prototype; }

    this.def_class('List',__scope.Struct,function(__scope,__class){

      this.__ctor__ = function List(doc, key, options) {
        this["@doc"] = doc;
        this["@key"] = key;
        this["@options"] = options;
        this["@changes"] = [];
        return this;
      }; this.__ctor__.prototype = this.prototype;;

      this.prototype.load = function(data) {
        if (!this["@array"]) {
          this["@array"] = data && data.data || [];
          this.observe(this["@array"]);
        }
        this["ready!"]();
        return this;
      }; __method_added(this,"load");

      this.prototype["[]"] = function(index) {
        return this["@array"][index];
      }; __method_added(this,"[]");

      this.prototype["[]="] = function(index, value) {
        return this["@array"][index] = value;
      }; __method_added(this,"[]=");

      this.prototype.each = function(block) {
        return this["@array"].forEach(block);
      }; __method_added(this,"each");

      this.prototype.rpush = function(value) {
        var i;
        i = this["@array"].push(value);
        this.emit('add', value, i);
        return i;
      }; __method_added(this,"rpush");

      this.prototype.index = function(value) {
        return this["@array"].indexOf(value);
      }; __method_added(this,"index");

      this.prototype.size = function() {
        return this["@array"].length;
      }; __method_added(this,"size");

      this.prototype.move = function(value, opts) {
        this.p('trying to move!!!!');
        this["@array"].move(value, opts);
        return this;
      }; __method_added(this,"move");

      this.prototype.add = function(value, opts) {
        this.p('trying to add!!!!');
        return this["@array"].add(value, opts);
      }; __method_added(this,"add");

      this.prototype["include?"] = function(value) {
        return this["@array"]["include?"](value);
      }; __method_added(this,"include?");

      this.prototype.emit = function(event) {
        __class.__super__.prototype.emit.apply(this, arguments);
        if (event === 'move') {
          this["@changes"].push(['move', arguments[1], arguments[2]]);
          this.p('picked up move event!!', this["@changes"]);
          return this["@doc"].save();
        } else if (event === 'add') {
          this["@changes"].push(['add', arguments[1], arguments[2]]);
          this.p('picked up add event!!', this["@changes"]);
          return this["@doc"].save();
        }
      }; __method_added(this,"emit");

      this.prototype.flush = function() {
        var changes;
        changes = this["@changes"];
        this["@changes"] = [];
        return changes;
      }; __method_added(this,"flush");

    });

  });

}).call($$base);

