framework/ember/app/initializers/find-query-one.js
Toby Zerner 0365ae6c71 Load discussion and posts with one request
Speeds things up a heap.
Also fix a whole bunch of bugs with the post stream.
2015-02-06 10:30:38 +10:30

25 lines
807 B
JavaScript

import DS from 'ember-data';
// This can be removed when
// https://github.com/emberjs/data/pull/2584 is implemented.
export default {
name: 'find-query-one',
initialize: function(container) {
DS.Store.reopen({
findQueryOne: function(type, id, query) {
var store = this;
var typeClass = store.modelFor(type);
var adapter = store.adapterFor(typeClass);
var serializer = store.serializerFor(typeClass);
var url = adapter.buildURL(type, id);
var ajaxPromise = adapter.ajax(url, 'GET', { data: query });
return ajaxPromise.then(function(rawPayload) {
var extractedPayload = serializer.extract(store, typeClass, rawPayload, id, 'find');
return store.push(typeClass, extractedPayload);
});
}
});
}
};