Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltazore committed Mar 22, 2024
1 parent 6a97e6f commit e9050cc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
18 changes: 10 additions & 8 deletions guides/cookbook/incremental-adoption-guide.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Incremental adoption guide for existing projects

Nav links
-[Cookbook](./index.md)

---

This guide is for existing projects that want to adopt the new APIs of the EmberData incrementally. If you are starting a new project, you should use the [new project guide](./new-project-guide.md).
This guide is for existing projects that want to adopt the new APIs of the EmberData incrementally.

## Step 1: Upgrade to EmberData 4.12.x

Expand Down Expand Up @@ -48,11 +46,11 @@ import Fetch from '@ember-data/request/fetch';

/* eslint-disable no-console */
const TestHandler: Handler = {
async request<T>(context: RequestContext, next: NextFn) {
async request<T>(context: RequestContext, next: NextFn<T>) {
console.log('TestHandler.request', context.request);
const newContext = await next(Object.assign({}, context.request));
console.log('TestHandler.response after fetch', newContext.response);
return newContext as T;
const result = await next(Object.assign({}, context.request));
console.log('TestHandler.response after fetch', result.response);
return result;
},
};

Expand Down Expand Up @@ -144,3 +142,7 @@ export default class App extends Application {

loadInitializers(App, config.modulePrefix);
```

---

-[Cookbook](./index.md)
8 changes: 4 additions & 4 deletions tests/example-json-api/app/services/request-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Fetch from '@ember-data/request/fetch';

/* eslint-disable no-console */
const TestHandler: Handler = {
async request<T>(context: RequestContext, next: NextFn) {
async request<T>(context: RequestContext, next: NextFn<T>) {
console.log('TestHandler.request', context.request);
const newContext = await next(Object.assign({}, context.request));
console.log('TestHandler.response after fetch', newContext.response);
return newContext as T;
const result = await next(Object.assign({}, context.request));
console.log('TestHandler.response after fetch', result.response);
return result;
},
};

Expand Down
10 changes: 10 additions & 0 deletions tests/example-json-api/app/services/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import { service } from '@ember/service';

import Store from 'ember-data/store';

import { LifetimesService } from '@ember-data/request-utils';

import CONFIG from '../config/environment';

// NOTE: This file must be JS extension as `ember-data` is still v1 addon,
// and JS declaration will always "win" in final build of application

export default class MyStore extends Store {
@service requestManager;

constructor(args) {
super(args);

this.lifetimes = new LifetimesService(CONFIG);
}
}

0 comments on commit e9050cc

Please sign in to comment.