Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript support #136

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ module.exports = {
'no-console': ["error", { allow: ['warn'] }]
},
overrides: [
// TypeScript files
{
files: ['addon/**/*.ts'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-undef': 'off',
'no-unused-var': 'off'
}
},
// node files
{
files: [
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ Available imports:
import fetch, { Headers, Request, Response, AbortController } from 'fetch';
```

### Use with TypeScript
To use `ember-fetch` with TypeScript or enable editor's type support, You can add `"fetch": ["node_modules/ember-fetch"]` to your `tsconfig.json`.

```json
{
"compilerOptions": {
"paths": {
"fetch": [
"node_modules/ember-fetch"
]
}
}
}
```

### Use with Ember Data
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.

Expand Down Expand Up @@ -106,7 +121,8 @@ The way you do import remains same.

## Q & A
### Does it work with pretender?
Yes, [pretender v2.1](https://github.com/pretenderjs/pretender/tree/v2.1.0) comes with `fetch` support.

* Yes, [pretender v2.1](https://github.com/pretenderjs/pretender/tree/v2.1.0) comes with `fetch` support.

### Does this replace ic-ajax?

Expand Down
11 changes: 0 additions & 11 deletions addon/ajax.js

This file was deleted.

14 changes: 14 additions & 0 deletions addon/ajax.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import fetch from 'fetch';

export default function ajax(
input: RequestInfo,
init?: RequestInit
): Promise<Response> {
return fetch(input, init).then(response => {
xg-wang marked this conversation as resolved.
Show resolved Hide resolved
if (response.ok) {
return response.json();
}
throw response;
})
}
168 changes: 0 additions & 168 deletions addon/mixins/adapter-fetch.js

This file was deleted.