Skip to content

Instantly share code, notes, and snippets.

@whatthewhat
Created June 21, 2016 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatthewhat/921fcb3b54138583bf78bb0ca907a25a to your computer and use it in GitHub Desktop.
Save whatthewhat/921fcb3b54138583bf78bb0ca907a25a to your computer and use it in GitHub Desktop.
rollbackAttributes
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
actions: {
createItems() {
this.store.createRecord('item', {name: 'item 1'});
this.store.createRecord('item', {name: 'item 2'});
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
rollback() {
this.get('model').rollbackAttributes();
}
}
});
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')
});
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('item', {path: '/:item_id'});
});
export default Router;
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.peekAll('item');
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
<ul>
{{#each model as |item|}}
<li>{{link-to item.name "item" item}}</li>
{{/each}}
</ul>
<button {{action "createItems"}}>Create Items</button>
{{outlet}}
<br>
<br>
<br><br>
Current item: <strong>{{model.name}}</strong>
<br><br>
hasDirtyAttributes: {{model.hasDirtyAttributes}}
<br><br>
<button {{action "rollback"}}>Rollback</button>
{
"version": "0.9.3",
"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.6.0",
"ember-data": "release",
"ember-template-compiler": "2.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment