-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: Change signature of request/respond methods to take serialized an…
…d unserialized data (#6285) * Change signature of request/respond methods to take serialized,data Both `requestFor` and `respondFor` methods now take both serialized data and unserialized data. We also leave it upto the adapter author to add (or omit) the serialized data from the request payload, instead of it being automatically added within the http client. Included here is a small refactor to dry out the http adapter slightly. Tests where changed only slightly to follow the new method signature. We spotted missing tests for token cloning, and the self API methods, so whilst refactoring this we added the test for those while we are here. * Drys out custom adapter methods and irons out a few wrinkles Custom adapter methods (like clone and self) needed the full promise chain written out. This can be repetitive and harder to refactor things and make things consitent. We've added a possibly temporary `application.request` method here to dry this out slightly. This may be moved in the future once we decide exactly where it should live. Now everything is much simpler, a few wrinkles are more visible, so we iron out these wrinkles to make everything as consistent as possible.
- Loading branch information
Showing
27 changed files
with
529 additions
and
246 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
import Adapter from './http'; | ||
import { inject as service } from '@ember/service'; | ||
|
||
import { get } from '@ember/object'; | ||
export const DATACENTER_QUERY_PARAM = 'dc'; | ||
export default Adapter.extend({ | ||
repo: service('settings'), | ||
client: service('client/http'), | ||
// TODO: kinda protected for the moment | ||
// decide where this should go either read/write from http | ||
// should somehow use this or vice versa | ||
request: function(req, resp, obj, modelName) { | ||
const client = get(this, 'client'); | ||
const store = get(this, 'store'); | ||
const adapter = this; | ||
|
||
let unserialized, serialized; | ||
const serializer = store.serializerFor(modelName); | ||
// workable way to decide whether this is a snapshot | ||
// Snapshot is private so we can't do instanceof here | ||
if (obj.constructor.name === 'Snapshot') { | ||
unserialized = obj.attributes(); | ||
serialized = serializer.serialize(obj, {}); | ||
} else { | ||
unserialized = obj; | ||
serialized = unserialized; | ||
} | ||
|
||
return client | ||
.request(function(request) { | ||
return req(adapter, request, serialized, unserialized); | ||
}) | ||
.catch(function(e) { | ||
return adapter.error(e); | ||
}) | ||
.then(function(response) { | ||
// TODO: When HTTPAdapter:responder changes, this will also need to change | ||
return resp(serializer, response, serialized, unserialized); | ||
}); | ||
// TODO: Potentially add specific serializer errors here | ||
// .catch(function(e) { | ||
// return Promise.reject(e); | ||
// }); | ||
}, | ||
}); |
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
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
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
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
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
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
Oops, something went wrong.