Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OCTANE] rewrite text and example to use getters #578

Merged
merged 1 commit into from Mar 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions guides/release/models/customizing-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,22 @@ export default class ApplicationAdapter extends JSONAPIAdapter {
}
```

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

```javascript {data-filename=app/adapters/application.js}
import DS from 'ember-data';
import { computed } from '@ember/object';
import { get } from '@ember/object';
const { JSONAPIAdapter } = DS;

export default DS.JSONAPIAdapter.extend({
headers: computed(function() {
export default class ApplicationAdapter extends JSONAPIAdapter {
get headers() {
return {
'API_KEY': get(document.cookie.match(/apiKey\=([^;]*)/), '1'),
'ANOTHER_HEADER': 'Some header value'
};
}).volatile()
});
}
}
```

#### Authoring Adapters
Expand Down