Skip to content

Commit 4019f77

Browse files
authored
Merge pull request #179 from ember-learn/fastboot
Use fetch in a FastBoot-compatible way
2 parents b321757 + 570ed76 commit 4019f77

File tree

8 files changed

+178
-114
lines changed

8 files changed

+178
-114
lines changed

addon/adapters/-addon-docs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import DS from 'ember-data';
22
import config from 'dummy/config/environment';
3-
import fetch from 'fetch';
3+
import { inject as service } from '@ember/service';
44

55
export default DS.Adapter.extend({
66
defaultSerializer: '-addon-docs',
77
namespace: `${config.rootURL.replace(/\/$/, '')}/docs`,
8+
docsFetch: service(),
89

910
shouldBackgroundReloadAll() {
1011
return false;
@@ -16,7 +17,7 @@ export default DS.Adapter.extend({
1617

1718
findRecord(store, modelClass, id, snapshot) {
1819
if (modelClass.modelName === 'project') {
19-
return fetch(`${this.namespace}/${id}.json`).then(response => response.json());
20+
return this.get('docsFetch').fetch({ url: `${this.namespace}/${id}.json` }).json();
2021
} else {
2122
return store.peekRecord(modelClass.modelName, id);
2223
}

addon/components/docs-demo/x-live-example/component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Component from '@ember/component';
2-
import Ember from 'ember';
2+
import { compileTemplate } from '@ember/template-compilation';
33
import layout from './template';
44
import snippets from 'dummy/snippets';
55

@@ -23,7 +23,7 @@ export default Component.extend({
2323
let compiledTemplate;
2424
let error = false;
2525
try {
26-
compiledTemplate = Ember.HTMLBars.compile(this.get('rawTemplate'));
26+
compiledTemplate = compileTemplate(this.get('rawTemplate'));
2727
} catch (e) {
2828
console.error(e);
2929
error = e;

addon/services/docs-fetch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'ember-fetch-adapter';

addon/services/docs-search.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import Service from '@ember/service';
1+
import Service, { inject as service } from '@ember/service';
22
import { getOwner } from '@ember/application';
33
import { computed } from '@ember/object';
44
import lunr from 'lunr';
55

66
const { Index, Query } = lunr;
77

88
export default Service.extend({
9+
docsFetch: service(),
10+
911
search(phrase) {
1012
return this.loadSearchIndex()
1113
.then(({ index, documents }) => {
@@ -72,8 +74,7 @@ export default Service.extend({
7274

7375
loadSearchIndex() {
7476
if (!this._searchIndex) {
75-
this._searchIndex = fetch(this.get('_indexURL'))
76-
.then(res => res.json())
77+
this._searchIndex = this.get('docsFetch').fetch({ url: this.get('_indexURL') }).json()
7778
.then(json => {
7879
return {
7980
index: Index.load(json.index),

addon/services/project-version.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import Service from '@ember/service';
1+
import Service, { inject as service } from '@ember/service';
22
import { getOwner } from '@ember/application';
3-
import fetch from 'fetch';
43
import { computed } from '@ember/object';
54
import { task } from 'ember-concurrency';
65

76
export default Service.extend({
7+
docsFetch: service(),
8+
89
_loadAvailableVersions: task(function*() {
9-
let response = yield fetch(`${this.get('root')}versions.json`);
10+
let response = yield this.get('docsFetch').fetch({ url: `${this.get('root')}versions.json` }).response();
1011
let json = yield response.ok ? response.json() : { latest: this.get('currentVersion') };
1112

1213
this.set('versions', Object.keys(json).map(key => {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"ember-component-css": "^0.3.5",
4545
"ember-concurrency": "^0.8.16",
4646
"ember-data": "^2.18.0",
47-
"ember-fetch": "^3.4.4",
47+
"ember-fetch": "^4.0.2",
48+
"ember-fetch-adapter": "^0.4.2",
4849
"ember-href-to": "^1.15.1",
4950
"ember-keyboard": "^3.0.0",
5051
"ember-modal-dialog": "2.4.3",

tests/dummy/app/pods/docs/deploying/template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ This method returns a name for a given version of your documentation. By default
133133

134134
### `shouldUpdateLatest()`
135135

136-
This method determines whether the `/latest` directory will also be updated with the current deploy. By default, this will return true for builds from a tagged commit where the tag is a [semver non-prerelease version]([node-semver](https://github.com/npm/node-semver), and false otherwise. You can explicitly set the `ADDON_DOCS_UPDATE_LATEST` environment variable to `true` or `false` to override this behavior.
136+
This method determines whether the `/latest` directory will also be updated with the current deploy. By default, this will return true for builds from a tagged commit where the tag is a [semver non-prerelease version](https://github.com/npm/node-semver), and false otherwise. You can explicitly set the `ADDON_DOCS_UPDATE_LATEST` environment variable to `true` or `false` to override this behavior.
137137

138138
### `getRootURL()`
139139

0 commit comments

Comments
 (0)