-
-
Save locks/466712399c91c26c4ac9 to your computer and use it in GitHub Desktop.
Updates, errors, and the store
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'; | |
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 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 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 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.Route.extend({ | |
model() { | |
this.store.createRecord('line', {name: 'yksi'}); | |
this.store.createRecord('line', {name: 'kaksi'}); | |
this.store.createRecord('line', {name: 'kolme'}); | |
return { | |
lines: this.store.peekAll('line'), | |
newLine: this.store.createRecord('line', {name: '...'}) | |
}; | |
} | |
}); |
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.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