From 8ddc115f92368a29ef710977f3a377ad4d854c48 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sat, 19 Aug 2023 23:02:22 +0100 Subject: :sparkles: Add additional errors for other cases. --- lib/src/lustre.ffi.mjs | 8 ++++++-- lib/src/lustre.gleam | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/src/lustre.ffi.mjs b/lib/src/lustre.ffi.mjs index 2d07394..c7008ed 100644 --- a/lib/src/lustre.ffi.mjs +++ b/lib/src/lustre.ffi.mjs @@ -1,6 +1,8 @@ import { - ElementNotFound, + AppAlreadyStarted, + AppNotYetStarted, ComponentAlreadyRegistered, + ElementNotFound, NotABrowser, } from "./lustre.mjs"; import { from } from "./lustre/effect.mjs"; @@ -31,7 +33,7 @@ export class App { start(selector, flags) { if (!is_browser()) return new Error(new NotABrowser()); - if (this.#root) return this; + if (this.#root) return new Error(new AppAlreadyStarted()); const el = document.querySelector(selector); @@ -65,6 +67,8 @@ export class App { } destroy() { + if (!this.#root) return new Error(new AppNotYetStarted()); + this.#root.remove(); this.#state = null; this.#queue = []; diff --git a/lib/src/lustre.gleam b/lib/src/lustre.gleam index dcfe76a..ec04f3e 100644 --- a/lib/src/lustre.gleam +++ b/lib/src/lustre.gleam @@ -50,6 +50,8 @@ import lustre/element.{Element} pub type App(flags, model, msg) pub type Error { + AppAlreadyStarted + AppNotYetStarted ComponentAlreadyRegistered ElementNotFound NotABrowser -- cgit v1.2.3