Skip to content

Commit

Permalink
$.ajax() uses deferreds & Deferred.success() is on completion or after
Browse files Browse the repository at this point in the history
This means we can simplify the code here as it will get fired when the ajax
request completes successfully or has *already* completed successfully!
  • Loading branch information
garrett committed Jul 18, 2011
1 parent 1f8daa8 commit 4e2e742
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
12 changes: 2 additions & 10 deletions data/html/sparkleshare.coffee
Expand Up @@ -27,7 +27,7 @@
@ajax
@changes = {}
@repo

constructor: (@repo = 'all') ->
@update()

Expand All @@ -38,18 +38,10 @@
"spec.json"

render: ->
_compileTemplate = =>
@ajax.success =>
template = Handlebars.compile $('#changeset-template').html()
$('#content').html template @changes

###
* Either template it now, or when a pending ajax request finishes
###
if @ajax?.readyState
@ajax.complete -> _compileTemplate()
else
_compileTemplate()


changes = new ChangeSet
changes.render()
Expand Down
15 changes: 2 additions & 13 deletions data/html/sparkleshare.js
Expand Up @@ -38,22 +38,11 @@
return "spec.json";
};
ChangeSet.prototype.render = function() {
var _compileTemplate, _ref;
_compileTemplate = __bind(function() {
return this.ajax.success(__bind(function() {
var template;
template = Handlebars.compile($('#changeset-template').html());
return $('#content').html(template(this.changes));
}, this);
/*
* Either template it now, or when a pending ajax request finishes
*/
if ((_ref = this.ajax) != null ? _ref.readyState : void 0) {
return this.ajax.complete(function() {
return _compileTemplate();
});
} else {
return _compileTemplate();
}
}, this));
};
return ChangeSet;
})();
Expand Down

0 comments on commit 4e2e742

Please sign in to comment.