Skip to content

Instantly share code, notes, and snippets.

Created Oct 16, 2012
What would you like to do?
# Implementing the `comments` property in CoffeeScript.
# Note the lack of `flatten` and the heavy guarding
# against objects being undefined.
App.Blog = Ember.Object.extend
comments: (->
# Return all comments of all posts by flattening.
   (@get('posts.@each.comments') ? []).reduce (a, b) ->
# b is a lazy hasMany collection of comments, so we must cast to array.
(a ? []).concat((b ? []).toArray())
, []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment