aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2023-08-19 23:00:38 +0100
committerHayleigh Thompson <me@hayleigh.dev>2023-08-19 23:00:38 +0100
commit37564e471b81247412fa837d1729ac0ca6d7a846 (patch)
treec670c8f0b112846319b01ef57699ab0fbee1cdc8
parent84dbeaaddae0c5a309c2eaed60ff2cf6b0d8afe7 (diff)
downloadlustre-37564e471b81247412fa837d1729ac0ca6d7a846.tar.gz
lustre-37564e471b81247412fa837d1729ac0ca6d7a846.zip
:recycle: Tidy up app start logic.
-rw-r--r--lib/src/lustre.ffi.mjs28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/src/lustre.ffi.mjs b/lib/src/lustre.ffi.mjs
index 5cf5058..2d07394 100644
--- a/lib/src/lustre.ffi.mjs
+++ b/lib/src/lustre.ffi.mjs
@@ -33,24 +33,20 @@ export class App {
if (!is_browser()) return new Error(new NotABrowser());
if (this.#root) return this;
- try {
- const el =
- selector instanceof HTMLElement
- ? selector
- : document.querySelector(selector);
- const [next, effects] = this.#init(flags);
-
- this.#root = el;
- this.#state = next;
- this.#effects = effects[0].toArray();
- this.#didUpdate = true;
+ const el = document.querySelector(selector);
- window.requestAnimationFrame(() => this.#tick());
+ if (!el) return new Error(new ElementNotFound());
- return new Ok((msg) => this.dispatch(msg));
- } catch (_) {
- return new Error(new ElementNotFound());
- }
+ const [next, effects] = this.#init(flags);
+
+ this.#root = el;
+ this.#state = next;
+ this.#effects = effects[0].toArray();
+ this.#didUpdate = true;
+
+ window.requestAnimationFrame(() => this.#tick());
+
+ return new Ok((msg) => this.dispatch(msg));
}
dispatch(msg) {