Skip to content

Commit 0a2dc07

Browse files
efxjenweber
authored andcommitted
rewrite text and example to use getters (ember-learn#578)
Address ember-learn#564
1 parent 059cb8c commit 0a2dc07

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

guides/release/models/customizing-adapters.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,26 +244,22 @@ export default class ApplicationAdapter extends JSONAPIAdapter {
244244
}
245245
```
246246

247-
In some cases, your dynamic headers may require data from some
248-
object outside of Ember's observer system (for example
249-
`document.cookie`). You can use the
250-
[volatile](https://www.emberjs.com/api/ember/release/classes/@ember%2Fobject%2Fcomputed/methods/property?anchor=volatile)
251-
function to set the property into a non-cached mode causing the headers to
252-
be recomputed with every request.
247+
[Getters](../../upgrading/editions/#toc_getters-and-setters) recompute with each access, so you could just as easily rely upon another dynamic value such as
248+
`document.cookie`.
253249

254250
```javascript {data-filename=app/adapters/application.js}
255251
import DS from 'ember-data';
256-
import { computed } from '@ember/object';
257252
import { get } from '@ember/object';
253+
const { JSONAPIAdapter } = DS;
258254

259-
export default DS.JSONAPIAdapter.extend({
260-
headers: computed(function() {
255+
export default class ApplicationAdapter extends JSONAPIAdapter {
256+
get headers() {
261257
return {
262258
'API_KEY': get(document.cookie.match(/apiKey\=([^;]*)/), '1'),
263259
'ANOTHER_HEADER': 'Some header value'
264260
};
265-
}).volatile()
266-
});
261+
}
262+
}
267263
```
268264

269265
#### Authoring Adapters

0 commit comments

Comments
 (0)