From c52f2d87ccfceb71669676d4a5ef4a376bfb2e86 Mon Sep 17 00:00:00 2001 From: Thomas Wang Date: Wed, 22 May 2019 23:48:08 -0700 Subject: [PATCH 1/2] Deprecate adapterFetch mixin --- README.md | 3 +++ addon/mixins/adapter-fetch.ts | 11 +++++++++++ tests/test-helper.js | 7 +++++++ types/index.d.ts | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 types/index.d.ts diff --git a/README.md b/README.md index 6900c879..ab679c23 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ To use `ember-fetch` with TypeScript or enable editor's type support, You can ad ``` ### Use with Ember Data + +> ember-data@3.9.2 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 diff --git a/addon/mixins/adapter-fetch.ts b/addon/mixins/adapter-fetch.ts index 7362033f..d725eb09 100644 --- a/addon/mixins/adapter-fetch.ts +++ b/addon/mixins/adapter-fetch.ts @@ -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'; @@ -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; _ajaxRequest( @@ -60,6 +62,15 @@ export interface FetchAdapter { export default Mixin.create({ 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 */ diff --git a/tests/test-helper.js b/tests/test-helper.js index 0382a848..c6aa709c 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -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(); diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..a24c21e1 --- /dev/null +++ b/types/index.d.ts @@ -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; +} \ No newline at end of file From ac01195f17556a04b0c0bb0bd0f32f33b208a46e Mon Sep 17 00:00:00 2001 From: Thomas Wang Date: Wed, 12 Jun 2019 22:00:11 -0700 Subject: [PATCH 2/2] Manual add typing for @ember/debug --- tsconfig.json | 1 + types/deprecate.d.ts | 81 ++++++++++++++++++++++++++++++++++++++++++++ types/index.d.ts | 18 ---------- 3 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 types/deprecate.d.ts delete mode 100644 types/index.d.ts diff --git a/tsconfig.json b/tsconfig.json index 188b3807..05206589 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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/*"] } }, diff --git a/types/deprecate.d.ts b/types/deprecate.d.ts new file mode 100644 index 00000000..296ede09 --- /dev/null +++ b/types/deprecate.d.ts @@ -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 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 +// 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; diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index a24c21e1..00000000 --- a/types/index.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -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; -} \ No newline at end of file