-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chapter 11 EmberData with RequestManager and Builders
--- Commit: ember-learn/super-rentals-tutorial@f766728 Script: https://github.com/ember-learn/super-rentals-tutorial/blob/f76672816e0f8fe5d6bd96e4ffa5e8f81fd2a2e4/.github/workflows/build.yml Logs: https://github.com/ember-learn/super-rentals-tutorial/commit/f76672816e0f8fe5d6bd96e4ffa5e8f81fd2a2e4/checks
- Loading branch information
1 parent
c4f7415
commit 1c4cb49
Showing
13 changed files
with
59 additions
and
33 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import Route from '@ember/routing/route'; | ||
import { service } from '@ember/service'; | ||
import { query } from '@ember-data/json-api/request'; | ||
|
||
export default class IndexRoute extends Route { | ||
@service store; | ||
|
||
async model() { | ||
return this.store.findAll('rental'); | ||
const { content } = await this.store.request(query('rental')); | ||
return content.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import Route from '@ember/routing/route'; | ||
import { service } from '@ember/service'; | ||
import { findRecord } from '@ember-data/json-api/request'; | ||
|
||
export default class RentalRoute extends Route { | ||
@service store; | ||
|
||
async model(params) { | ||
return this.store.findRecord('rental', params.rental_id); | ||
const { content } = await this.store.request( | ||
findRecord('rental', params.rental_id), | ||
); | ||
return content.data; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import BaseRequestManager from '@ember-data/request'; | ||
import Fetch from '@ember-data/request/fetch'; | ||
import { JsonSuffixHandler } from 'super-rentals/utils/handlers'; | ||
|
||
export default class RequestManager extends BaseRequestManager { | ||
constructor(args) { | ||
super(args); | ||
|
||
this.use([JsonSuffixHandler, Fetch]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export { default } from 'ember-data/store'; | ||
// eslint-disable-next-line ember/use-ember-data-rfc-395-imports | ||
import BaseStore from 'ember-data/store'; | ||
import { service } from '@ember/service'; | ||
|
||
export default class Store extends BaseStore { | ||
@service requestManager; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const JsonSuffixHandler = { | ||
request(context, next) { | ||
const { request } = context; | ||
const updatedRequest = Object.assign({}, request, { | ||
url: request.url + '.json', | ||
}); | ||
|
||
return next(updatedRequest); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"data": { | ||
"type": "rentals", | ||
"type": "rental", | ||
"id": "urban-living", | ||
"attributes": { | ||
"title": "Urban Living", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1079,19 +1079,19 @@ | |
minimist "^1.2.0" | ||
|
||
"@csstools/css-parser-algorithms@^2.3.1": | ||
version "2.7.0" | ||
resolved "https://registry.yarnpkg.com/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.7.0.tgz#ee41f252438b97045db2528c1a999e95f15610d8" | ||
integrity sha512-qvBMcOU/uWFCH/VO0MYe0AMs0BGMWAt6FTryMbFIKYtZtVnqTZtT8ktv5o718llkaGZWomJezJZjq3vJDHeJNQ== | ||
version "2.7.1" | ||
resolved "https://registry.yarnpkg.com/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.7.1.tgz#6d93a8f7d8aeb7cd9ed0868f946e46f021b6aa70" | ||
integrity sha512-2SJS42gxmACHgikc1WGesXLIT8d/q2l0UFM7TaEeIzdFCE/FPMtTiizcPGGJtlPo2xuQzY09OhrLTzRxqJqwGw== | ||
|
||
"@csstools/css-tokenizer@^2.2.0": | ||
version "2.4.1" | ||
resolved "https://registry.yarnpkg.com/@csstools/css-tokenizer/-/css-tokenizer-2.4.1.tgz#1d8b2e200197cf5f35ceb07ca2dade31f3a00ae8" | ||
integrity sha512-eQ9DIktFJBhGjioABJRtUucoWR2mwllurfnM8LuNGAqX3ViZXaUchqk+1s7jjtkFiT9ySdACsFEA3etErkALUg== | ||
|
||
"@csstools/media-query-list-parser@^2.1.4": | ||
version "2.1.12" | ||
resolved "https://registry.yarnpkg.com/@csstools/media-query-list-parser/-/media-query-list-parser-2.1.12.tgz#ec7485667efbaad420b3414dc1dc19dc7a49f626" | ||
integrity sha512-t1/CdyVJzOQUiGUcIBXRzTAkWTFPxiPnoKwowKW2z9Uj78c2bBWI/X94BeVfUwVq1xtCjD7dnO8kS6WONgp8Jw== | ||
version "2.1.13" | ||
resolved "https://registry.yarnpkg.com/@csstools/media-query-list-parser/-/media-query-list-parser-2.1.13.tgz#f00be93f6bede07c14ddf51a168ad2748e4fe9e5" | ||
integrity sha512-XaHr+16KRU9Gf8XLi3q8kDlI18d5vzKSKCY510Vrtc9iNR0NJzbY9hhTmwhzYZj/ZwGL4VmB3TA9hJW0Um2qFA== | ||
|
||
"@csstools/selector-specificity@^3.0.0": | ||
version "3.1.1" | ||
|
@@ -4105,9 +4105,9 @@ [email protected]: | |
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== | ||
|
||
electron-to-chromium@^1.4.796: | ||
version "1.4.817" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.817.tgz#da9808e35212408cf4052b51679786fcb54fec39" | ||
integrity sha512-3znu+lZMIbTe8ZOs360OMJvVroVF2NpNI8T5jfLnDetVvj0uNmIucZzQVYMSJfsu9f47Ssox1Gt46PR+R+1JUg== | ||
version "1.4.818" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.818.tgz#7762c8bfd15a07c3833b7f5deed990e9e5a4c24f" | ||
integrity sha512-eGvIk2V0dGImV9gWLq8fDfTTsCAeMDwZqEPMr+jMInxZdnp9Us8UpovYpRCf9NQ7VOFgrN2doNSgvISbsbNpxA== | ||
|
||
ember-auto-import@^2.6.0, ember-auto-import@^2.6.3, ember-auto-import@^2.7.3: | ||
version "2.7.4" | ||
|
@@ -7306,9 +7306,9 @@ lower-case@^2.0.2: | |
tslib "^2.0.3" | ||
|
||
lru-cache@^10.2.0: | ||
version "10.3.0" | ||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.3.0.tgz#4a4aaf10c84658ab70f79a85a9a3f1e1fb11196b" | ||
integrity sha512-CQl19J/g+Hbjbv4Y3mFNNXFEL/5t/KCg8POCuUqd4rMKjGG+j1ybER83hxV58zL+dFI1PTkt3GNFSHRt+d8qEQ== | ||
version "10.3.1" | ||
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.3.1.tgz#a37050586f84ccfdb570148a253bf1632a29ef44" | ||
integrity sha512-9/8QXrtbGeMB6LxwQd4x1tIMnsmUxMvIH/qWGsccz6bt9Uln3S+sgAaqfQNhbGA8ufzs2fHuP/yqapGgP9Hh2g== | ||
|
||
lru-cache@^5.1.1: | ||
version "5.1.1" | ||
|