Skip to content

Commit

Permalink
Deprecate ember-data support utils
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed May 23, 2019
1 parent 340200d commit 6744b22
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions addon/utils/determine-body-promise.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { deprecate } from '@ember/debug';

/**
* Function that always attempts to parse the response as json, and if an error is thrown,
* returns `undefined` if the response is successful and has a status code of 204 (No Content),
Expand All @@ -7,6 +9,10 @@ export default function determineBodyPromise(
response: Response,
requestData: JQueryAjaxSettings
): Promise<object | string | undefined> {
deprecate('determineBodyPromise is deprecated, it is no longer required for ember-data>=3.9.2', false, {
id: 'deprecate-fetch-ember-data-support',
until: '7.0.0'
});
return response.text().then(function(payload) {
let ret: string | object | undefined = payload;
try {
Expand Down
5 changes: 5 additions & 0 deletions addon/utils/mung-options-for-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assign } from '@ember/polyfills';
import { deprecate } from '@ember/debug';
import { serializeQueryParams } from './serialize-query-params';
import {
Method,
Expand All @@ -13,6 +14,10 @@ import {
export default function mungOptionsForFetch(
options: AjaxOptions
): FetchOptions {
deprecate('mungOptionsForFetch is deprecated, it is no longer required for ember-data>=3.9.2', false, {
id: 'deprecate-fetch-ember-data-support',
until: '7.0.0'
});
const hash = assign(
{
credentials: 'same-origin'
Expand Down
5 changes: 5 additions & 0 deletions addon/utils/serialize-query-params.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecate } from '@ember/debug';
import { isPlainObject } from 'ember-fetch/types';

const RBRACKET = /\[\]$/;
Expand All @@ -9,6 +10,10 @@ const RBRACKET = /\[\]$/;
export function serializeQueryParams(
queryParamsObject: object | string
): string {
deprecate('serializeQueryParams is deprecated, it is no longer required for ember-data>=3.9.2', false, {
id: 'deprecate-fetch-ember-data-support',
until: '7.0.0'
});
var s: any[] = [];

function buildParams(prefix: string, obj: any) {
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 6744b22

Please sign in to comment.