Skip to content

Commit

Permalink
Deprecate ember-data support utils (#308)
Browse files Browse the repository at this point in the history
Deprecate ember-data support utils
  • Loading branch information
xg-wang authored Jun 28, 2019
2 parents 4147205 + ac01195 commit f7d17be
Show file tree
Hide file tree
Showing 5 changed files with 103 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();
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"ember-fetch/*": ["addon/*"],
"ember-fetch/test-support": ["addon-test-support"],
"ember-fetch/test-support/*": ["addon-test-support/*"],
"@ember/debug": ["types/deprecate.d"],
"*": ["types/*"]
}
},
Expand Down
81 changes: 81 additions & 0 deletions types/deprecate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// TODO: This file should be removed once https://github.com/emberjs/ember.js/issues/17185 close

// 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;

/**
* Alias an old, deprecated method with its new counterpart.
*/
export function deprecateFunc<Func extends ((...args: any[]) => any)>(
message: string,
options: DeprecationOptions,
func: Func
): Func;

// Type definitions for non-npm package @ember/debug 3.0
// Project: https://emberjs.com/api/ember/3.4/modules/@ember%2Fdebug
// Definitions by: Mike North <https://github.com/mike-north>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

/**
* Define an assertion that will throw an exception if the condition is not met.
*/
export function assert(desc: string, test?: boolean): void | never;
/**
* Display a debug notice.
*/
export function debug(message: string): void;

/**
* Convenience method to inspect an object. This method will attempt to
* convert the object into a useful string description.
*/
export function inspect(obj: any): string;
/**
* Allows for runtime registration of handler functions that override the default deprecation behavior.
* Deprecations are invoked by calls to [Ember.deprecate](http://emberjs.com/api/classes/Ember.html#method_deprecate).
* The following example demonstrates its usage by registering a handler that throws an error if the
* message contains the word "should", otherwise defers to the default handler.
*/
export function registerDeprecationHandler(handler: (message: string, options: { id: string, until: string }, next: () => void) => void): void;
/**
* Allows for runtime registration of handler functions that override the default warning behavior.
* Warnings are invoked by calls made to [Ember.warn](http://emberjs.com/api/classes/Ember.html#method_warn).
* The following example demonstrates its usage by registering a handler that does nothing overriding Ember's
* default warning behavior.
*/
export function registerWarnHandler(handler: (message: string, options: { id: string }, next: () => void) => void): void;

/**
* Run a function meant for debugging.
*/
export function runInDebug(func: () => any): void;

/**
* Display a warning with the provided message.
*/
export function warn(message: string, test: boolean, options: { id: string }): void;
export function warn(message: string, options: { id: string }): void;
/**
* @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options
*/
export function warn(message: string, test: boolean, options?: { id?: string }): void;
/**
* @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options
*/
export function warn(message: string, options?: { id?: string }): void;

0 comments on commit f7d17be

Please sign in to comment.