diff --git a/guides/drafts/incremental-adoption-guide.md b/guides/cookbook/incremental-adoption-guide.md similarity index 95% rename from guides/drafts/incremental-adoption-guide.md rename to guides/cookbook/incremental-adoption-guide.md index d965f384f45..0c1b140c4e7 100644 --- a/guides/drafts/incremental-adoption-guide.md +++ b/guides/cookbook/incremental-adoption-guide.md @@ -40,20 +40,19 @@ First you need to install [`@ember-data/request`](https://github.com/emberjs/dat Here is how your own `RequestManager` service may look like: -```js +```ts +import { LegacyNetworkHandler } from '@ember-data/legacy-compat'; +import type { Handler, NextFn, RequestContext } from '@ember-data/request'; import RequestManager from '@ember-data/request'; import Fetch from '@ember-data/request/fetch'; -import { LegacyNetworkHandler } from '@ember-data/legacy-compat'; - -const TestHandler = { - async request({ request }, next) { - console.log('TestHandler.request', request); - - const newContext = await next(request); +/* eslint-disable no-console */ +const TestHandler: Handler = { + async request(context: RequestContext, next: NextFn) { + console.log('TestHandler.request', context.request); + const newContext = await next(Object.assign({}, context.request)); console.log('TestHandler.response after fetch', newContext.response); - - return next(newContext); + return newContext as T; }, }; @@ -103,7 +102,7 @@ Now you can start refactoring old code to use new APIs. You can start with the ` You most likely would need to add Auth Handler to your request manager to add `accessToken` to your requests. Let's say you have your `accessToken` in the `session` service. Here is how you can add it to the request manager: -```js auth-handler.js +```js import { inject as service } from '@ember/service'; export default class AuthHandler { diff --git a/guides/cookbook/index.md b/guides/cookbook/index.md new file mode 100644 index 00000000000..53df945e865 --- /dev/null +++ b/guides/cookbook/index.md @@ -0,0 +1,3 @@ +# Cookbook + +- [Incremental Adoption Guide](./incremental-adoption-guide.md) diff --git a/guides/index.md b/guides/index.md index 08f5c6c731c..0a7f07f0a53 100644 --- a/guides/index.md +++ b/guides/index.md @@ -3,3 +3,4 @@ - [Relationships](./relationships/index.md) - [Requests](./requests/index.md) - [Terminology](./terminology.md) +- [Cookbook](./cookbook/index.md)