Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayphelps/ember-computed-content-controller
A computed property for injecting a unique instance of a content controller (ObjectController, ArrayController, etc) into an Ember class instance. Useful for nested ArrayControllers, among other things.
https://github.com/jayphelps/ember-computed-content-controller
Last synced: 9 days ago
JSON representation
A computed property for injecting a unique instance of a content controller (ObjectController, ArrayController, etc) into an Ember class instance. Useful for nested ArrayControllers, among other things.
- Host: GitHub
- URL: https://github.com/jayphelps/ember-computed-content-controller
- Owner: jayphelps
- License: mit
- Created: 2014-04-25T21:57:20.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-13T10:24:25.000Z (almost 10 years ago)
- Last Synced: 2024-10-19T17:58:20.054Z (19 days ago)
- Language: JavaScript
- Homepage:
- Size: 238 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ember-computed-content-controller
========================A computed property for injecting a unique instance of a content controller (`ObjectController`, `ArrayController`, etc) into an Ember class instance. Useful for nested `ArrayControllers` and cleaning up your templates.
## Usage
Ember.computed.contentController(controllerName: *String*, contentPath: *String*): *ComputedProperty*
#### ES5 (traditional)
```javascript
App.IndexController = Ember.ObjectController.extend({
posts: Ember.computed.contentController('posts', 'blog.posts')
});App.PostsController = Ember.ArrayController.extend({
itemController: 'post'
});
App.PostController = Ember.ObjectController.extend({
comments: Ember.computed.contentController('comments', 'content.comments')
});
App.CommentsController = Ember.ArrayController.extend({
itemController: 'comment',
anySelected: function() {
return this.anyBy('isSelected');
}.property('@each.isSelected')
});
App.CommentController = Ember.ObjectController.extend({
isSelected: false
});
``````handlebars
{{#each post in posts}}
<div {{bind-attr class="post.comments.anySelected:highlighted"}}>
<p>{{post.body}}</p>
<p>{{post.comments}}</p>
{{#each comment in post.comments}}
<p>{{input type="checkbox" checked=comment.isSelected}} {{comment.body}}</p>
{{/each}}
</div>
{{/each}}```
**By default, a unique instance will be created**. You can provide an options hash to change this behavior:```javascript
App.PostController = Ember.ObjectController.extend({
comments: Ember.computed.contentController('comments', 'content.comments', { singleton: true })
});
```## Any gotchas?
Only for users who stray outside the Ember-idiomatic beaten path and manually create class instances.
Instances must have an `Ember.Container` assigned at `this.container`. Ember will handle this for you when resolving routes, controllers, views, etc but if you manually `.create()` a class, it does not come with a container, so it won't be able to resolve your dependency. You can either pass an existing container along or use the container itself to create your class instances. [Learn more](https://github.com/emberjs/website/pull/1293)
## Credit
[@mmum](https://github.com/mmun) came up with this technique in a [rejected Pull Request](https://github.com/emberjs/ember.js/pull/3424) but gave me permission to steal it.
## License
MIT Licensed