Skip to content

Commit

Permalink
Merge pull request #136 from xg-wang/ts
Browse files Browse the repository at this point in the history
TypeScript support
  • Loading branch information
xg-wang committed Feb 8, 2019
2 parents 6163b90 + c64bb4c commit c0ea3a1
Show file tree
Hide file tree
Showing 18 changed files with 871 additions and 255 deletions.
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 => {
if (response.ok) {
return response.json();
}
throw response;
})
}
168 changes: 0 additions & 168 deletions addon/mixins/adapter-fetch.js

This file was deleted.

0 comments on commit c0ea3a1

Please sign in to comment.