Changeset 101

Show
Ignore:
Timestamp:
04/25/08 22:05:36 (4 months ago)
Author:
nickstenning
Message:

Refactor ThreadController? to behave in a more obviously asynchronous manner. This should be done to FactletController? as well.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/microfacts/public/app/controllers/thread_controller.js

    r99 r101  
    77                // id out of the ElementStore. See master.js to see where 
    88                // it was put in. 
    9                 this.data = this.element.retrieve('thread:data'); 
     9                this.id = this.element.retrieve('thread:id'); 
    1010                 
    1111                // Store data object in the ElementStore. See 
    1212                // factlet_controller.js for comments about this. 
    1313                this.element.store('thread:controller', this); 
    14                  
    15                 // Get our own copy of our data from the server. This saves 
    16                 // us parsing HTML. 
    17                 Thread.entityGet(this.data.id).callback(function (reqData) { 
    18                     this.data = Thread.entities[this.data.id]; 
    19                 }, this).send(); 
    20                  
    2114                 
    2215                if(this.getElement('.thread-factlets')) { 
     
    3629                    }).unmarshal(this.getElement('.thread-factlets')); 
    3730 
    38                     this.deckController = new DeckController(this.deck, $('thread-control-'+this.data.id)); 
     31                    this.deckController = new DeckController(this.deck, $('thread-control-'+this.id)); 
    3932                     
    4033                    // TODO: Ideally somehow factor these two out of here. 
     
    6053        } 
    6154    }, 
     55    data: function () { 
     56        return Thread.entityGet(this.id); 
     57    }, 
    6258    appendFactlet: function (id) { 
    63         var reqData = $deepClone(this.data); 
    64         reqData.factlets = reqData.factlets.extend([id]); 
    65         Thread.entityPut(reqData.id).callback(function () { 
    66             this.data = Thread.get(reqData.id); 
    67             this.redraw(); 
    68         }, this).send(JSON.encode(reqData)); 
     59        this.data().callback(function(data) { 
     60            var reqData = $deepClone(data); 
     61            reqData.factlets = reqData.factlets.extend([id]); 
     62            Thread.entityPut(reqData.id).callback(function (respData) { 
     63                this.redraw(respData); 
     64            }, this).send(JSON.encode(reqData)); 
     65        }, this).send(); 
    6966    }, 
    70     redraw: function () { 
    71         var renderData = $deepClone(this.data); 
    72         renderData.factlets = renderData.factlets.map(function (id) { 
    73             return Factlet.get(id); 
    74         }); 
    75         this.renderViewTo(this.getElement('.thread-factlets'), 'thread/factlet-list', renderData); 
     67    redraw: function (threadData) { 
     68        var len = threadData.factlets.length; 
     69        threadData.factlets.each(function (id, idx) { 
     70            Factlet.entityGet(id).callback(function(factlet) { 
     71                threadData.factlets[idx] = factlet; 
     72                if (idx === (len - 1)) { 
     73                    this.renderViewTo(this.getElement('.thread-factlets'), 'thread/factlet-list', threadData); 
     74                } 
     75            }, this).send(); 
     76        }, this); 
    7677    } 
    7778}); 
  • trunk/microfacts/public/app/master.js

    r88 r101  
    3636    $$('.thread').each(function (elem) { 
    3737        var id = elem.get('id').split('-').at(-1); 
    38         elem.store('thread:data', {id: id}); 
     38        elem.store('thread:id', id); 
    3939        threadControllers[id] = new ThreadController(elem); 
    4040    });