Skip to content

Commit

Permalink
Split send into separate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vvscode committed Nov 30, 2016
1 parent 1488a26 commit 4a672fe
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions addon/adapters/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,43 @@ export default DS.RESTAdapter.extend({
* @returns {Ember.RSVP.Promise}
*/
send: function(type, requestType, hash) {
hash = this.buildRequest(type, requestType, hash);
this.onBeforeSendHash(hash);
const connection = this.getConnection(type);
const requestsPool = get(this, 'requestsPool');
const requestId = this.generateRequestId();
const modelName = type.modelName;
const deffered = Ember.RSVP.defer('DS: SocketAdapter#emit ' + requestType + ' to ' + modelName);
const logRequests = get(this, 'logRequests');
const modelName = type.modelName;
const collectRequestResponseLog = get(this, 'collectRequestResponseLog');
if (!(hash instanceof Object)) {
hash = {};
}
const deffered = Ember.RSVP.defer('DS: SocketAdapter#emit ' + requestType + ' to ' + modelName);
deffered.requestType = requestType;
hash.request_id = requestId;
if (collectRequestResponseLog) {
requestResponseLogger.logRequest({
modelName,
operation: requestType,
hash
});
}
requestsPool[requestId] = deffered;
requestsPool[hash.request_id] = deffered;
if (logRequests) {
printRequestStack(hash);
}
connection.emit(requestType, hash);
return deffered.promise;
},

buildRequest(type, requestType, hash) {
const requestId = this.generateRequestId();
if (!(hash instanceof Object)) {
hash = {};
}
hash.request_id = requestId;
return hash;
},

onBeforeSendHash(/*hash*/) {

},

/**
* Fetching all resources of a given type from server, can't be called with params.
* Returns resources without full relations.
Expand Down

0 comments on commit 4a672fe

Please sign in to comment.