-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hardcodes export-application-global
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Application from '@ember/application' | ||
import { classify } from '@ember/string' | ||
|
||
// @ts-ignore: because TS doesn't like this import | ||
import config from "../config/environment" | ||
|
||
export function initialize(application: Application): void { | ||
if (config.exportApplicationGlobal !== false) { | ||
let theGlobal | ||
|
||
if (typeof window !== 'undefined') { | ||
theGlobal = window | ||
} else if (typeof global !== 'undefined') { | ||
theGlobal = global | ||
} else if (typeof self !== 'undefined') { | ||
theGlobal = self | ||
} else { | ||
return | ||
} | ||
|
||
const value = config.exportApplicationGlobal | ||
|
||
let globalName | ||
|
||
if (typeof value === 'string') { | ||
globalName = value | ||
} else { | ||
globalName = classify(config.modulePrefix) | ||
} | ||
|
||
// @ts-ignore: until there's a way to access a dynamic propertyName of window in TS | ||
if (!theGlobal[globalName]) { | ||
// @ts-ignore: until there's a way to set a dynamic propertyName to the window in TS | ||
theGlobal[globalName] = application | ||
} | ||
} | ||
} | ||
|
||
export default { | ||
name: 'export-application-global', | ||
initialize | ||
} |