Skip to content

Instantly share code, notes, and snippets.

@matthewconstantine
Created August 17, 2016 01:14
Show Gist options
  • Save matthewconstantine/fdab72d8e3040c48616312791ed24056 to your computer and use it in GitHub Desktop.
Save matthewconstantine/fdab72d8e3040c48616312791ed24056 to your computer and use it in GitHub Desktop.
Component Factory
import Ember from 'ember';
const NewPostModalSetup = Ember.Object.extend({
isActive: false,
posts: null,
withOpenModal() {
return NewPostModalSetup.create({
isActive: true
});
},
withDataLoading() {
return NewPostModalSetup.create({
posts: Ember.RSVP.defer().promise
});
},
withDataLoaded() {
return NewPostModalSetup.create({
posts: FactoryGuy.makeList('posts', 3)
});
},
render(context) {
context.setProperties({
isActive: this.get('isActive'),
posts: this.get('posts'),
});
context.render(hbs`{{new-post-modal
isActive=isActive
posts=posts
}}`)
}
});
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
const x = NewPostModalSetup.create().withOpenModal().withDataLoading();
console.log(x.posts);
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment