Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Last active July 8, 2016 14:55
Show Gist options
  • Save phillipkregg/20da92d62c8508b2aec473b57a93bab7 to your computer and use it in GitHub Desktop.
Save phillipkregg/20da92d62c8508b2aec473b57a93bab7 to your computer and use it in GitHub Desktop.
EmberBootstrap
import Ember from 'ember';
export default Ember.Component.extend({
property1: undefined,
property2: undefined,
actions: {
coolClick: function() {
this.set('property1', 'Yo');
this.set('property2', 'Sup');
alert('from component')
this.sendAction('action', {
property1: this.get('property1'),
property2: this.get('property2')
});
this.sendAction('customActionName')
},
defaultAction: function() {
this.set('property1', 'Yo');
this.set('property2', 'Sup');
alert('default');
},
sendState: function() {
var property1 = this.get('property1');
var property2 = this.get('property2')
return {
property1: property1,
property2: property2
}
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
defaultAction: function() {
alert('default from component to application controller');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
}
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('first-button-route');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
goHome: function() {
this.transitionTo('index')
},
goToFirst: function() {
this.transitionTo('first-button-route');
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return ['banana', 'apple', 'orange']
}
});
import Ember from 'ember';
export default Ember.Route.extend({
currentViewState: undefined,
actions: {
coolClickAction: function() {
alert('from index route: cool click action')
},
defaultAction: function(viewState) {
alert('default from component to index route' + ' ' + viewState);
// Call an action from within this route
this.send('setupViewState', viewState)
},
setupViewState: function(viewState) {
this.set('currentViewState', viewState);
alert("Current View State: " + JSON.stringify(this.get('currentViewState')));
}
}
});
<h1>Welcome to {{appName}}</h1>
{{cool-component
action="defaultAction"
customActionName="coolClickAction"
}}
<button class="btn btn-default" {{action 'goHome'}}>Home</button>
<button class="btn btn-default" {{action 'goToFirst'}}>First</button>
<button class="btn btn-default">Second</button>
<button class="btn btn-default">Third</button>
<br>
<br>
{{outlet}}
<br>
<br>
{{yield}}
<div class="bg-primary">
<h4>My Cool Component</h4>
<button class="btn btn-default" {{action "coolClick"}}>Cool Component Click</button>
</div>
<h2>First Button Route</h2>
<ul>
{{#each model as |fruit|}}
<li>{{fruit}}</li>
{{/each}}
</ul>
<h2>Here's the application index page</h2>
{{cool-component
action="defaultAction"
customActionName="coolClickAction"
}}
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"bootstrap": "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment