Last active
September 2, 2017 13:48
-
-
Save alexlafroscia/5523c451fa871770c8c84eaeb01a1fcb to your computer and use it in GitHub Desktop.
Presentation & Container Components in Ember
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
import Ember from 'ember'; | |
const BlogCommentComponent = Ember.Component.extend({ | |
}); | |
BlogCommentComponent.reopenClass({ | |
positionalParams: ['comment'] | |
}); | |
export default BlogCommentComponent; |
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
import Ember from 'ember'; | |
import { task, timeout } from 'ember-concurrency'; | |
const COMMENTS = [ | |
{ body: 'This is a comment' }, | |
{ body: 'This is another comment' } | |
]; | |
export default Ember.Component.extend({ | |
tagName: '', | |
init() { | |
this._super(...arguments); | |
this.set('comments', []); | |
}, | |
didInsertElement() { | |
this._super(...arguments); | |
this.get('loadComments').perform(); | |
}, | |
loadComments: task(function* () { | |
// We use a timeout here to simulate the fact that fetching the comments takes some time | |
// If we did not lazily load them, the initial page load would be extended by this 1000ms instead | |
yield timeout(1000); | |
this.set('comments', COMMENTS); | |
}) | |
}); |
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
import Ember from 'ember'; | |
const { computed } = Ember; | |
const BlogPostComponent = Ember.Component.extend({ | |
title: computed.alias('blogPost.title'), | |
body: computed.alias('blogPost.body') | |
}); | |
BlogPostComponent.reopenClass({ | |
positionalParams: ['blogPost'] | |
}); | |
export default BlogPostComponent; |
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
blogPost: { | |
title: 'This is the blog post', | |
body: 'We want to render the comments later on, after the main content has loaded. This makes a better experience for the user, since they get the content they care about immediately, and we can fill in less important stuff after the initial page load.' | |
} | |
}); |
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
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": true, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-concurrency": "0.8.7" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment