Created
October 16, 2012 18:40
-
-
Save joliss/3901154 to your computer and use it in GitHub Desktop.
This file contains 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
# 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('[email protected]') ? []).reduce (a, b) -> | |
# b is a lazy hasMany collection of comments, so we must cast to array. | |
(a ? []).concat((b ? []).toArray()) | |
, [] | |
).property('[email protected]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment