Last active
October 23, 2017 23:39
-
-
Save workmanw/7cfe7142524edb3a03755fb913dc035f to your computer and use it in GitHub Desktop.
ember-data#4918 / UnloadRecord State
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
store: Ember.inject.service('store'), | |
errorMsgs: null, | |
init() { | |
this._super(...arguments); | |
let store = this.get('store'); | |
store.push({ | |
data: [{ | |
"type": "post", | |
"id": "1", | |
"attributes": { | |
"name": "JSON API paints my bikeshed!" | |
} | |
}] | |
}); | |
this.set('post', store.peekRecord('post', 1)); | |
this.set('errorMsgs', []); | |
Ember.onerror = (error) => { | |
this.get('errorMsgs').pushObject(error.message); | |
}; | |
}, | |
actions: { | |
dirty() { | |
this.get('post').set('name', 'dirty'); | |
}, | |
rollback() { | |
this.get('post').rollbackAttributes(); | |
}, | |
unload() { | |
this.get('post').unloadRecord(); | |
} | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.error-container { | |
color: #a94442; | |
background-color: #f2dede; | |
border-color: #ebccd1; | |
padding: 6px; | |
} | |
.error-container .message { | |
margin: 8px 0; | |
display: block; | |
font-size: 13px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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.13.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment