Skip to content

Commit

Permalink
Merge pull request #43 from mbland/make-component-classes-static
Browse files Browse the repository at this point in the history
Make Placeholder.init() static, remove main.start
  • Loading branch information
mbland committed Dec 15, 2023
2 parents 31591d9 + 780b5d4 commit 3063291
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
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))

0 comments on commit 3063291

Please sign in to comment.