Skip to content

Instantly share code, notes, and snippets.

@jdudek
Last active December 14, 2015 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdudek/5085515 to your computer and use it in GitHub Desktop.
Save jdudek/5085515 to your computer and use it in GitHub Desktop.
var map = function (fn) { return function (arr) { return jQuery.map(arr, fn); } };
var each = function (fn) { return function (arr) { jQuery.each(arr, fn); } };
loadReplies: function() {
var _this = this, request;
request = jQuery.getJSON('/posts/' + this.get('id') + '/replies')
.then(map(Discourse.Post.create))
.then(each(function (post) { post.set('topic', _this.get('topic'); }))
this.set('replies', []);
request.done(function (replies) { _this.set('replies', replies); });
this.set('loadingReplies', true);
request.done(function () { _this.set('loadingReplies', false); });
return request;
}
map = (fn) -> (arr) -> jQuery.map(arr, fn)
each = (fn) -> (arr) -> jQuery.each(arr, fn)
loadReplies: =>
request = jQuery.getJSON("/posts/#{@get('id')}/replies")
.then(map(Discourse.Post.create))
.then(each((post) => post.set('topic', @get('topic'))))
@set('replies', [])
request.done (replies) => @set('replies', replies)
@set('loadingReplies', true)
request.done => @set('loadingReplies', false)
return request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment