(function() {
  var __hasProp = Object.prototype.hasOwnProperty;

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

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

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

      this.__ctor__ = function Hash(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["@raw"]) this["@raw"] = data && data.data || {};
        this["ready!"]();
        return this;
      }; __method_added(this,"load");

      this.prototype["[]"] = function(field) {
        field = $to_s(field);
        return this["@raw"][field];
      }; __method_added(this,"[]");

      this.prototype["[]="] = function(field, value) {
        var cmd;
        field = $to_s(field);
        if (this["@raw"][field] !== value) {
          this["@raw"][field] = value;
          this.emit('change', field, value);
          cmd = value === nil && ['del', field] || ['set', field, value];
          this["@changes"].push(cmd);
          this["@doc"]["@dirty"].sadd(this["@key"]);
        }
        return value;
      }; __method_added(this,"[]=");

      this.prototype.each_pair = function(blk) {
        var field, val, _ref;
        _ref = this["@raw"];
        for (field in _ref) {
          if (!__hasProp.call(_ref, field)) continue;
          val = _ref[field];
          blk(field, val);
        }
        return this;
      }; __method_added(this,"each_pair");

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

    });

  });

}).call($$base);

