Last active
December 14, 2015 12:19
-
-
Save jdudek/5085515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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