Skip to content

Instantly share code, notes, and snippets.

@jdudek jdudek/gist:5085515
Last active Dec 14, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.