<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,5 @@
 //= require &lt;transmission&gt;
+//= require &lt;torrent_file&gt;
 //= require &lt;events&gt;
 
 Transmission.Torrent = (function() {
@@ -6,60 +7,34 @@ Transmission.Torrent = (function() {
   
   var getFiles = function() { return this.files; };
   
-  var updateAttributes = function(new_attributes) {
-    var new_attribute_value, callbacks = [];
-    
-    for (var attribute in new_attributes) {
-      new_attribute_value = new_attributes[attribute];
-      if (this.attributes[attribute] != new_attribute_value) {
-        this.attributes[attribute] = new_attribute_value;
-        if (this.attribute_callbacks[attribute]) {
-          this.attribute_callbacks[attribute].each(function(callback) {
-            if (!callbacks.include(callback)) {
-              callbacks.push(callback);
-            }
-          });
-        }
-      }
+  var updateFiles = function(attribute, attributes) {
+    var files = attributes[attribute];
+    if (this.files.length &lt; files.length) {
+      var torrent = this;
+      this.files = files.map(function() {
+        return new Transmission.TorrentFile(torrent);
+      });
     }
-    
-    callbacks.each(function(callback) { callback(); });
-  };
-  
-  var getAttribute = function(attribute) {
-    return this.attributes[attribute];
-  };
-  
-  var addAttributeEventListener = function(attribute, callback) {
-    if (!this.attribute_callbacks[attribute]) {
-      this.attribute_callbacks[attribute] = [];
+    for (var i = 0, len = files.length; i &lt; len; i++) {
+      this.files[i].updateAttributes(files[i]);
     }
-    this.attribute_callbacks[attribute].push(callback);
   };
   
-  var addAttributesEventListener = function(attributes, callback) {
-    for (var i = attributes.length - 1; i &gt;= 0; i--) {
-      this.addAttributeEventListener(attributes[i], callback);
-    }
+  var constructor = function(id) {
+    initialize.bind(this)(id);
   };
   
-  var constructor = function(id) {
+  var initialize = function(id) {
     this.id         = id;
     this.files      = [];
-    this.attributes = {};
-    
-    this.attribute_callbacks = {};
+    this.addAttributeEventListener('files', updateFiles.curry('files').bind(this));
+    this.addAttributeEventListener('fileStats', updateFiles.curry('fileStats').bind(this));
   };
   
-  constructor.prototype = {
+  constructor.prototype = Transmission.extend(Transmission.AttributeEventDispatcher.prototype, {
     getId: getId,
-    getFiles: getFiles,
-    updateAttributes: updateAttributes,
-    getAttribute: getAttribute,
-    
-    addAttributeEventListener: addAttributeEventListener,
-    addAttributesEventListener: addAttributesEventListener
-  };
+    getFiles: getFiles
+  });
   
   return constructor;
   </diff>
      <filename>src/models/torrent.js</filename>
    </modified>
    <modified>
      <diff>@@ -18,54 +18,17 @@ function() { return {
     this.assertSameElements([], torrent.getFiles());
   },
   
-  testUpdateAttributes: function() {
+  testUpdateFiles: function() {
     var torrent = new Transmission.Torrent(1);
     torrent.updateAttributes({
-      hashString: 'b126e1ea1b49c79613f779ac0f36a9714e823fcb'
+      files: [ { name: 'File1' } ]
     });
-    this.assertEqual('b126e1ea1b49c79613f779ac0f36a9714e823fcb', torrent.getAttribute('hashString'));
-  },
-  
-  testAddAttributeEventListener: function() {
-    var torrent = new Transmission.Torrent(1),
-        attribute_updated = false;
-    torrent.addAttributeEventListener('hashString', function() {
-      attribute_updated = true;
-    });
-    torrent.updateAttributes({ hashString: 'b126e1ea1b49c79613f779ac0f36a9714e823fcb' });
-    this.assert(attribute_updated);
-  },
-  
-  testAttributeEventListenerShouldRequireChangeInValue: function() {
-    var torrent = new Transmission.Torrent(1),
-        attribute_updated = false;
-    torrent.updateAttributes({ hashString: 'b126e1ea1b49c79613f779ac0f36a9714e823fcb' });
-    
-    torrent.addAttributeEventListener('hashString', function() {
-      attribute_updated = true;
-    });
-    torrent.updateAttributes({ hashString: 'b126e1ea1b49c79613f779ac0f36a9714e823fcb' });
-    this.assert(!attribute_updated);
-  },
-  
-  testAddAttributesEventListener: function() {
-    var torrent = new Transmission.Torrent(1),
-        attribute_update_count = 0;
-    torrent.addAttributesEventListener([ 'haveUnchecked', 'hashString' ], function() {
-      attribute_update_count++;
-    });
-    
-    torrent.updateAttributes({ hashString: 'b126e1ea1b49c79613f779ac0f36a9714e823fcb' });
-    this.assertEqual(1, attribute_update_count);
     
-    torrent.updateAttributes({ haveUnchecked: 10 });
-    this.assertEqual(2, attribute_update_count);
+    var torrent_file = torrent.getFiles()[0];
+    this.assertNotUndefined(torrent_file,
+      'Expected torrent to have torrent file');
     
-    torrent.updateAttributes({
-      hashString: 'b126e1ea1b49c79613f779ac0f36a9714e823fcc',
-      haveUnchecked: 11
-    });
-    this.assertEqual(3, attribute_update_count);
-  }
-  
+    this.assertEqual('File1', torrent_file.getAttribute('name'),
+      'Expected updateAttributes to update files');
+  }  
 }; }</diff>
      <filename>test/unit/models/torrent_test.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>80d421c5853099e063dfd1310f543abf5cb9ef09</id>
    </parent>
  </parents>
  <author>
    <name>Duncan Beevers</name>
    <email>duncanbeevers@gmail.com</email>
  </author>
  <url>http://github.com/duncanbeevers/transmission-web-ui/commit/89e996b979d3336d668854b36d7e91f11d6a1217</url>
  <id>89e996b979d3336d668854b36d7e91f11d6a1217</id>
  <committed-date>2009-06-23T00:59:37-07:00</committed-date>
  <authored-date>2009-06-23T00:59:37-07:00</authored-date>
  <message>Simplify torrent implementation, use AttributeEventDispatcher.  Observe changes to files and fileStats attributes</message>
  <tree>e470816f7c822fc6af4a7b2fa88a18376a11ce6c</tree>
  <committer>
    <name>Duncan Beevers</name>
    <email>duncanbeevers@gmail.com</email>
  </committer>
</commit>
