Skip to content

Commit 424ee3f

Browse files
authored
Don't require setConfig & fix docs (#1052)
1 parent 706b2c4 commit 424ee3f

3 files changed

Lines changed: 5 additions & 22 deletions

File tree

docs/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (macroCondition(isDevelopingApp())) {
1212
}
1313

1414
setConfig({
15-
rootElement: 'body',
15+
rootElement: config.APP['rootElement'] as string | undefined,
1616
});
1717

1818
export default class App extends Application {

docs/app/components/snippets/installation-2.js.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { setConfig } from 'ember-basic-dropdown/config';
33

44
// Basic usage:
55
setConfig({
6-
rootElement: config.APP.rootElement, // Default is 'body' (or '#ember-testing' in tests)
6+
rootElement: config.APP.rootElement, // config.APP.rootElement is by default 'undefined' and '#ember-testing' in tests
77
});
88

99
// Advanced: If you need to override globally the destination element ID (BasicDropdownWormhole), you can do:
1010
setConfig({
1111
destination: 'my-custom-destination-id',
12-
rootElement: config.APP.rootElement, // Default is 'body' (or '#ember-testing' in tests)
12+
rootElement: config.APP.rootElement, // config.APP.rootElement is by default 'undefined' and '#ember-testing' in tests
1313
});

src/config.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
export interface Config {
22
destination?: string;
3-
rootElement: string;
3+
rootElement?: string;
44
}
55

6-
let _config: Config = {
7-
rootElement: '',
8-
};
9-
10-
let configSet = false;
6+
let _config: Config = {};
117

128
export function setConfig(config: Config) {
13-
if (!config.rootElement) {
14-
throw new Error(
15-
"ember-basic-dropdown: 'rootElement' is required in the config. See installation instructions for more details.",
16-
);
17-
}
18-
199
_config = config;
20-
configSet = true;
2110
}
2211

2312
export function getConfig(): Config {
24-
if (!configSet) {
25-
throw new Error(
26-
'ember-basic-dropdown: setConfig was not called before accessing config. See installation instructions for more details.',
27-
);
28-
}
29-
3013
return _config;
3114
}

0 commit comments

Comments
 (0)