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('posts.@each.comments') ? []).reduce (a, b) -> | |
# b is a lazy hasMany collection of comments, so we must cast to array. | |
(a ? []).concat((b ? []).toArray()) | |
, [] | |
).property('posts.@each.comments') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment