diff options
-rw-r--r-- | lib/src/lustre.ffi.mjs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/src/lustre.ffi.mjs b/lib/src/lustre.ffi.mjs index 998c598..5cf5058 100644 --- a/lib/src/lustre.ffi.mjs +++ b/lib/src/lustre.ffi.mjs @@ -1,4 +1,8 @@ -import { ElementNotFound, ComponentAlreadyRegistered } from "./lustre.mjs"; +import { + ElementNotFound, + ComponentAlreadyRegistered, + NotABrowser, +} from "./lustre.mjs"; import { from } from "./lustre/effect.mjs"; import { map } from "./lustre/element.mjs"; import { morph } from "./runtime.ffi.mjs"; @@ -26,6 +30,7 @@ export class App { } start(selector, flags) { + if (!is_browser()) return new Error(new NotABrowser()); if (this.#root) return this; try { @@ -137,6 +142,7 @@ export const setup_component = ( render, on_attribute_change ) => { + if (!is_browser()) return new Error(new NotABrowser()); if (customElements.get(name)) { return new Error(new ComponentAlreadyRegistered()); } @@ -204,3 +210,7 @@ export const setup_component = ( ); return new Ok(null); }; + +// UTLS ------------------------------------------------------------------------ + +export const is_browser = () => window && window.document; |