Skip to content

Instantly share code, notes, and snippets.

@abhilashlr
Created January 6, 2017 05:46
Show Gist options
  • Save abhilashlr/7d99233a037c7204ef3564c4490cc3b0 to your computer and use it in GitHub Desktop.
Save abhilashlr/7d99233a037c7204ef3564c4490cc3b0 to your computer and use it in GitHub Desktop.
Model rollback for custom attr transform
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember 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('string'),
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();
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
Dummy Route
Name:: {{input type="text" value=model.name}}
G: {{input type="text" value=model.hashData.g}}
H: {{input type="text" value=model.hashData.h}}
<button {{action 'cancel' model}}>Rollback</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