mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 11:57:33 +08:00
Merge pull request #21742 from inkless/master
[ember-data] add ajax and ajaxOptions to RESTAdapter
This commit is contained in:
8
types/ember-data/index.d.ts
vendored
8
types/ember-data/index.d.ts
vendored
@@ -1033,6 +1033,14 @@ declare namespace DS {
|
||||
* should use the REST adapter.
|
||||
*/
|
||||
class RESTAdapter extends Adapter implements BuildURLMixin {
|
||||
/**
|
||||
* Takes a URL, an HTTP method and a hash of data, and makes an HTTP request.
|
||||
*/
|
||||
ajax(url: string, type: string, options?: object): Promise<any>;
|
||||
/**
|
||||
* Generate ajax options
|
||||
*/
|
||||
ajaxOptions(url: string, type: string, options?: object): object;
|
||||
/**
|
||||
* By default, the RESTAdapter will send the query params sorted alphabetically to the
|
||||
* server.
|
||||
|
||||
@@ -23,3 +23,34 @@ const AuthTokenHeader = DS.JSONAPIAdapter.extend({
|
||||
};
|
||||
})
|
||||
});
|
||||
|
||||
const UseAjax = DS.JSONAPIAdapter.extend({
|
||||
query(store: DS.Store, type: string, query: object) {
|
||||
const url = 'https://api.example.com/my-api';
|
||||
return this.ajax(url, 'POST', {
|
||||
param: 'foo'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const UseAjaxOptions = DS.JSONAPIAdapter.extend({
|
||||
query(store: DS.Store, type: string, query: object) {
|
||||
const url = 'https://api.example.com/my-api';
|
||||
const options = this.ajaxOptions(url, 'DELETE', {
|
||||
foo: 'bar'
|
||||
});
|
||||
return Ember.$.ajax(url, {
|
||||
...options
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const UseAjaxOptionsWithOptionalThirdParams = DS.JSONAPIAdapter.extend({
|
||||
query(store: DS.Store, type: string, query: object) {
|
||||
const url = 'https://api.example.com/my-api';
|
||||
const options = this.ajaxOptions(url, 'DELETE');
|
||||
return Ember.$.ajax(url, {
|
||||
...options
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user