Last active
March 26, 2016 00:42
-
-
Save pablobm/8c3cbe9e718551ce5bc6 to your computer and use it in GitHub Desktop.
Updates, errors, and the store
This file contains hidden or 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'; | |
| import DS from 'ember-data'; | |
| export default DS.RESTAdapter.extend({ | |
| ajax(url, type, options) { | |
| const requestData = { | |
| url: url, | |
| method: type | |
| }; | |
| const payload = { | |
| errors: [ | |
| { | |
| detail: 'KPOW!', | |
| source: { | |
| pointer: 'data/attributes/name', | |
| }, | |
| }, | |
| ], | |
| }; | |
| // This line to FAIL | |
| const response = this.handleResponse(422, {}, payload, response); | |
| // This line to SUCCEED | |
| //const response = this.handleResponse(200, {}, {}, response); | |
| return new Ember.RSVP.Promise(function(resolve, reject) { | |
| Ember.run.join(null, reject, response); | |
| }, "Dummy request"); | |
| }, | |
| }); |
This file contains hidden or 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({ | |
| init() { | |
| this._super(); | |
| this.store.createRecord('line', {name: 'yksi'}); | |
| this.store.createRecord('line', {name: 'kaksi'}); | |
| this.store.createRecord('line', {name: 'kolme'}); | |
| }, | |
| newLine: Ember.computed(function() { | |
| return this.store.createRecord('line', {name: '...'}); | |
| }), | |
| lines: Ember.computed(function() { | |
| return this.store.findAll('line'); | |
| }), | |
| actions: { | |
| save() { | |
| const line = this.get('newLine'); | |
| line.save().then( | |
| function() {}, | |
| function() { line.deleteRecord(); }, | |
| ); | |
| }, | |
| cancel() { | |
| this.get('newLine').deleteRecord(); | |
| }, | |
| }, | |
| }); |
This file contains hidden or 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 DS from 'ember-data'; | |
| export default DS.Model.extend({ | |
| name: DS.attr('string'), | |
| }); |
This file contains hidden or 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.7.0", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember.debug.js", | |
| "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js", | |
| "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.3/ember-template-compiler.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment