diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-08-19 22:59:18 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-08-19 22:59:18 +0100 |
commit | 84dbeaaddae0c5a309c2eaed60ff2cf6b0d8afe7 (patch) | |
tree | 45de4ef18ba2e7c56e49d00e0c8822a1c5b7d37d | |
parent | 13c992d2fb8ba4d4825c452be023da8c53af9488 (diff) | |
download | lustre-84dbeaaddae0c5a309c2eaed60ff2cf6b0d8afe7.tar.gz lustre-84dbeaaddae0c5a309c2eaed60ff2cf6b0d8afe7.zip |
:sparkles: Return an error when components and applications are used outside of a browser-like environment.
-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; |