Skip to content

Instantly share code, notes, and snippets.

@sivakumar-kailasam
Created November 30, 2017 07:06
Show Gist options
  • Save sivakumar-kailasam/2ae35fc6a0a066943470bed5dffa18a2 to your computer and use it in GitHub Desktop.
Save sivakumar-kailasam/2ae35fc6a0a066943470bed5dffa18a2 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
console.clear();
this.get('store').createRecord('profile', {id: 0, name: 'Captain America'});
},
profile: Ember.computed(function() {
return this.get('store').peekRecord('profile', 0);
})
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
changeHero() {
const x = this.get('store').peekRecord('profile', 0);
x.set('name', 'Iron Man');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
changeHero() {
const x = this.get('store').peekRecord('profile', 0);
x.set('name', 'SpiderMan');
}
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr()
});
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-route')
this.route('second-route')
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').peekRecord('profile', 0);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').peekRecord('profile', 0);
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
My name is {{profile.name}}
<br>
<br>
edit in the application level: {{input value=profile.name}}
<br>
<br>
{{#link-to 'first-route'}}First route{{/link-to}}
{{#link-to 'second-route'}}Second route{{/link-to}}
<br>
<br>
{{outlet}}
<br>
<br>
<h2>First Route</h2>
current hero: {{model.name}}
<br>
<button {{action 'changeHero'}}>It clearly should be Iron Man</button>
<h2>Second Route</h2>
current hero: {{model.name}}
<br>
<button {{action 'changeHero'}}>It should be SpiderMan</button>
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment