From 37564e471b81247412fa837d1729ac0ca6d7a846 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sat, 19 Aug 2023 23:00:38 +0100 Subject: :recycle: Tidy up app start logic. --- lib/src/lustre.ffi.mjs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'lib/src/lustre.ffi.mjs') 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) { -- cgit v1.2.3