I'm trying to write an adapter and serializer for back-end with JSON-RPC, but I have some problems with the understanding of how Ember.js works (I use ember-cli). I think, I have to use DS.Adapter instead DS.JSONAPIAdapter or DS.RESTAdapter, right? In that case I have to implement some methods of abstract class DS.Adapter, but for JSON-RPC we don't need deleteRecord or updateRecord, for example. How to do it better? Maybe someone has already done the adapter for JSON-RPC. It would be great if you tell what is the best practice.
And one more question, please tell me about the 'snapshot' what the function 'createRecord' takes in example:
export default DS.Adapter.extend({
createRecord: function(store, type, snapshot) {
var data = this.serialize(snapshot, { includeId: true });
var url = type;
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.$.ajax({
type: 'POST',
url: url,
dataType: 'json',
data: data
}).then(function(data) {
Ember.run(null, resolve, data);
}, function(jqXHR) {
jqXHR.then = null; // tame jQuery's ill mannered promises
Ember.run(null, reject, jqXHR);
});
});
}
});
What is a snapshot in simple words?
Aucun commentaire:
Enregistrer un commentaire