Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (macroCondition(isDevelopingApp())) {
}

setConfig({
rootElement: 'body',
rootElement: config.APP['rootElement'] as string | undefined,
});

export default class App extends Application {
Expand Down
4 changes: 2 additions & 2 deletions docs/app/components/snippets/installation-2.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { setConfig } from 'ember-basic-dropdown/config';

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

// Advanced: If you need to override globally the destination element ID (BasicDropdownWormhole), you can do:
setConfig({
destination: 'my-custom-destination-id',
rootElement: config.APP.rootElement, // Default is 'body' (or '#ember-testing' in tests)
rootElement: config.APP.rootElement, // config.APP.rootElement is by default 'undefined' and '#ember-testing' in tests
});
21 changes: 2 additions & 19 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
export interface Config {
destination?: string;
rootElement: string;
rootElement?: string;
}

let _config: Config = {
rootElement: '',
};

let configSet = false;
let _config: Config = {};

export function setConfig(config: Config) {
if (!config.rootElement) {
throw new Error(
"ember-basic-dropdown: 'rootElement' is required in the config. See installation instructions for more details.",
);
}

_config = config;
configSet = true;
}

export function getConfig(): Config {
if (!configSet) {
throw new Error(
'ember-basic-dropdown: setConfig was not called before accessing config. See installation instructions for more details.',
);
}

return _config;
}