Skip to content

Commit

Permalink
Deprecate adapterFetch mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed Jun 13, 2019
1 parent 340200d commit 71ffdb8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ To use `ember-fetch` with TypeScript or enable editor's type support, You can ad
```

### Use with Ember Data

> [email protected] was released with built-in fetch support, this mixin is no longer needed and will be removed in next major bump.
To have Ember Data utilize `fetch` instead of jQuery.ajax to make calls to your backend, extend your project's `application` adapter with the `adapter-fetch` mixin.

```js
Expand Down
11 changes: 11 additions & 0 deletions addon/mixins/adapter-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Mixin from '@ember/object/mixin';
import { assign } from '@ember/polyfills';
import { deprecate } from '@ember/debug';
import RSVP, { reject } from 'rsvp';
import fetch from 'fetch';
import mungOptionsForFetch from '../utils/mung-options-for-fetch';
Expand Down Expand Up @@ -33,6 +34,7 @@ export function headersToObject(headers: Headers) {

export interface FetchAdapter {
headers: undefined | PlainHeaders;
init(): void;
ajaxOptions(url: string, type: Method, options: object): FetchOptions;
ajax(url: string, type: Method, options: object): RSVP.Promise<void>;
_ajaxRequest(
Expand Down Expand Up @@ -60,6 +62,15 @@ export interface FetchAdapter {

export default Mixin.create<FetchAdapter, DS.RESTAdapter>({
headers: undefined,

init() {
this._super(...arguments);
deprecate('FetchAdapter is deprecated, it is no longer required for ember-data>=3.9.2', false, {
id: 'deprecate-fetch-ember-data-support',
until: '7.0.0'
});
},

/**
* @override
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import { registerDeprecationHandler } from '@ember/debug';

setApplication(Application.create(config.APP));

registerDeprecationHandler((msg, options, next) => {
if (options.id !== 'deprecate-fetch-ember-data-support') {
next(msg, options);
}
})

start();
18 changes: 18 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
declare module "@ember/debug" {
// tslint:disable-next-line:strict-export-declare-modifiers
interface DeprecationOptions {
id: string;
until: string;
url?: string;
}

/**
* Display a deprecation warning with the provided message and a stack trace
* (Chrome and Firefox only).
*/
export function deprecate(
message: string,
test: boolean,
options: DeprecationOptions
): any;
}

0 comments on commit 71ffdb8

Please sign in to comment.