Skip to content

Instantly share code, notes, and snippets.

@abhilashlr
Created January 6, 2017 06:58
Show Gist options
  • Save abhilashlr/226bd1a440c328654759467ca191432a to your computer and use it in GitHub Desktop.
Save abhilashlr/226bd1a440c328654759467ca191432a to your computer and use it in GitHub Desktop.
New Twiddle
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(),
hashData: 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('dummy');
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
this.store.push({
"data": {
"type": "dummy",
"id": "1",
"attributes": {
"name": "JSON API paints my bikeshed!",
"hashData": {
g: 1,
h: 2
}
}
}
});
return this.store.peekRecord('dummy', 1);
},
actions: {
cancel(model) {
model.rollbackAttributes();
},
changeManually(model) {
model.set('hashData', {g: 2, h: 4});
}
}
});
Dummy Route<br />
Name:: {{input type="text" value=model.name}}<br />
G: {{input type="text" value=model.hashData.g}}<br />
H: {{input type="text" value=model.hashData.h}}<br />
Model is dirty: {{model.hasDirtyAttributes}}<br />
<button {{action 'cancel' model}}>Rollback</button>
<button {{action 'changeManually' model}}>Change manually</button>
{
"version": "0.10.7",
"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.10.0",
"ember-data": "2.10.0",
"ember-template-compiler": "2.10.0",
"ember-testing": "2.10.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment