Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Placeholder.init() static, remove main.start #43

Merged
merged 1 commit into from
Dec 15, 2023
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 strcalc/src/main/frontend/components/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class Placeholder {
* @param {Window} window - the browser window object
* @param {Document} document - a Document or DocumentFragment
*/
init(window, document) {
static init(window, document) {
document.querySelector('#app').append(...Template({
message: 'Hello, World!',
url: 'https://en.wikipedia.org/wiki/%22Hello,_World!%22_program'
Expand Down
2 changes: 1 addition & 1 deletion strcalc/src/main/frontend/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import Placeholder from './components/placeholder'
* @param {Document} document - a Document or DocumentFragment
*/
export default function initApp(window, document) {
new Placeholder().init(window, document)
Placeholder.init(window, document)
}
16 changes: 5 additions & 11 deletions strcalc/src/main/frontend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ import initApp from './init'
/**
* Calls the application initializer with the global window and document.
*
* In addition to demonstrating how ECMAScript modules are linked together,
* this shows how to introduce a shim between globalThis and the initApp()
* function. Most tests can then call initApp() directly, and only two tests are
* needed to validate that start() is or isn't called.
* Wraps the initApp() call in a DOMContentLoaded event listener.
* - main.test.js uses PageLoader to validate that initApp() fires on
* DOMContentLoaded.
* - init.test.js tests the initApp() method directly.
* @param {Window} window - the browser window object
* @param {Document} document - a Document or DocumentFragment
*/
export default function start(window, document) {
document.addEventListener('DOMContentLoaded', () => initApp(window, document))
}

if (globalThis.window !== undefined) {
start(globalThis.window, globalThis.window.document)
}
document.addEventListener('DOMContentLoaded', () => initApp(window, document))