refactor: 💡 remove ember-get-config dep from core

This commit is contained in:
Randall Morey committed 2021-11-05 13:20:45 -04:00
1 parent 3aae7c124b
commit 8000002b1b
8 files changed
+61 -42

No files matched your search

+8 -5
View File
@@ -1,6 +1,9 @@
import { helper } from '@ember/component/helper'; import Helper from '@ember/component/helper';
import config from 'ember-get-config'; import { getOwner } from '@ember/application';
export default helper(function appName() { export default class extends Helper {
return config.appName; compute() {
}); const config = getOwner(this).resolveRegistration('config:environment');
return config.appName;
}
}
@@ -1,7 +1,10 @@
import { helper } from '@ember/component/helper'; import Helper from '@ember/component/helper';
import config from 'ember-get-config'; import { getOwner } from '@ember/application';
export default helper(function companyCopyright() { export default class extends Helper {
const currentYear = new Date().getFullYear(); compute() {
return `© ${currentYear} ${config.companyName}`; const config = getOwner(this).resolveRegistration('config:environment');
}); const currentYear = new Date().getFullYear();
return `© ${currentYear} ${config.companyName}`;
}
}
+8 -5
View File
@@ -1,6 +1,9 @@
import { helper } from '@ember/component/helper'; import Helper from '@ember/component/helper';
import config from 'ember-get-config'; import { getOwner } from '@ember/application';
export default helper(function companyName() { export default class extends Helper {
return config.companyName; compute() {
}); const config = getOwner(this).resolveRegistration('config:environment');
return config.companyName;
}
}
+20 -17
View File
@@ -1,20 +1,23 @@
import { helper } from '@ember/component/helper'; import Helper from '@ember/component/helper';
import { getOwner } from '@ember/application';
import { assert } from '@ember/debug'; import { assert } from '@ember/debug';
import config from 'ember-get-config';
export default helper(function docUrl(params /*, hash*/) { export default class extends Helper {
const baseURL = config.documentation.baseURL; compute(params) {
const docKey = params[0] || ''; const config = getOwner(this).resolveRegistration('config:environment');
const configuredPath = config.documentation.topics[docKey]; const baseURL = config.documentation.baseURL;
if (docKey) { const docKey = params[0] || '';
assert( const configuredPath = config.documentation.topics[docKey];
` if (docKey) {
Documentation for "${docKey}" could not be found. Please ensure that assert(
this key exists under "documentation" in your app config. `
`, Documentation for "${docKey}" could not be found. Please ensure that
configuredPath this key exists under "documentation" in your app config.
); `,
configuredPath
);
}
const path = configuredPath || '';
return `${baseURL}${path}`;
} }
const path = configuredPath || ''; }
return `${baseURL}${path}`;
});
@@ -1,9 +1,8 @@
import { registerDeprecationHandler } from '@ember/debug'; import { registerDeprecationHandler } from '@ember/debug';
import config from 'ember-get-config';
const isTesting = config.environment === 'test'; export function initialize(application) {
const config = application.resolveRegistration('config:environment');
export function initialize(/* application */) { const isTesting = config.environment === 'test';
if (isTesting) { if (isTesting) {
// Disable all deprecations for now in tests. // Disable all deprecations for now in tests.
registerDeprecationHandler((/*message, options, next*/) => { registerDeprecationHandler((/*message, options, next*/) => {
+10 -2
View File
@@ -3,7 +3,7 @@ import { filterBy } from '@ember/object/computed';
import { A } from '@ember/array'; import { A } from '@ember/array';
import { tracked } from '@glimmer/tracking'; import { tracked } from '@glimmer/tracking';
import { defer, resolve } from 'rsvp'; import { defer, resolve } from 'rsvp';
import config from 'ember-get-config'; import { getOwner } from '@ember/application';
/** /**
* A simple service that emits Confirmation instances and * A simple service that emits Confirmation instances and
@@ -17,13 +17,21 @@ import config from 'ember-get-config';
export default class ConfirmationsService extends Service { export default class ConfirmationsService extends Service {
// =attributes // =attributes
#enabled;
/** /**
* When the confirm service is disabled, it always returns resolving promises. * When the confirm service is disabled, it always returns resolving promises.
* By default the service is enabled but it is useful to disable it for test * By default the service is enabled but it is useful to disable it for test
* purposes. * purposes.
* @type {boolean} * @type {boolean}
*/ */
enabled = config.enableConfirmService ?? true; get enabled() {
const config = getOwner(this).resolveRegistration('config:environment');
return this.#enabled ?? config.enableConfirmService ?? true;
}
set enabled(value) {
this.#enabled = value;
}
/** /**
* @type {Array} * @type {Array}
-1
View File
@@ -34,7 +34,6 @@
"ember-cli-babel": "^7.26.6", "ember-cli-babel": "^7.26.6",
"ember-cli-htmlbars": "^5.7.1", "ember-cli-htmlbars": "^5.7.1",
"ember-feature-flags": "^6.0.0", "ember-feature-flags": "^6.0.0",
"ember-get-config": "^0.3.0",
"ember-intl": "^5.7.0", "ember-intl": "^5.7.0",
"ember-loading": "^0.4.0", "ember-loading": "^0.4.0",
"ember-route-action-helper": "^2.0.8", "ember-route-action-helper": "^2.0.8",
@@ -2,13 +2,13 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit'; import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers'; import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars'; import { hbs } from 'ember-cli-htmlbars';
import config from 'ember-get-config';
module('Integration | Helper | doc-url', function (hooks) { module('Integration | Helper | doc-url', function (hooks) {
setupRenderingTest(hooks); setupRenderingTest(hooks);
test('it renders a URL generated from the documentation config', async function (assert) { test('it renders a URL generated from the documentation config', async function (assert) {
assert.expect(3); assert.expect(3);
const config = this.owner.resolveRegistration('config:environment');
const baseURL = config.documentation.baseURL; const baseURL = config.documentation.baseURL;
const path = config.documentation.topics.account; const path = config.documentation.topics.account;
await render(hbs`{{doc-url 'account'}}`); await render(hbs`{{doc-url 'account'}}`);
@@ -19,7 +19,8 @@ module('Integration | Helper | doc-url', function (hooks) {
test('it throws an error if the specified documentation path cannot be found', async function (assert) { test('it throws an error if the specified documentation path cannot be found', async function (assert) {
assert.expect(2); assert.expect(2);
const helper = this.owner.lookup('helper:doc-url'); const Helper = this.owner.lookup('helper:doc-url');
const helper = new Helper(this.owner);
assert.ok(helper.compute(['account']), 'Specified document exists.'); assert.ok(helper.compute(['account']), 'Specified document exists.');
assert.throws(() => { assert.throws(() => {
helper.compute(['no.such.doc']); helper.compute(['no.such.doc']);