From 20432e6ac989cd6059f47187fe0151496edba2c3 Mon Sep 17 00:00:00 2001 From: Paulus Esterhazy Date: Sat, 24 Dec 2016 14:38:21 +0100 Subject: [PATCH] Work in env without window.location Environments like React Native don't have a window.location. In such an environment, boot-reload fails because window.location.hostname or .protocol does not exist. Use some-> to avoid these exceptions. --- src/adzerk/boot_reload/client.cljs | 2 +- src/adzerk/boot_reload/reload.cljs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adzerk/boot_reload/client.cljs b/src/adzerk/boot_reload/client.cljs index 44c43d0..4d13cb0 100644 --- a/src/adzerk/boot_reload/client.cljs +++ b/src/adzerk/boot_reload/client.cljs @@ -21,7 +21,7 @@ (defn resolve-url [url ws-host] (let [passed-uri (Uri. url) protocol (.getScheme passed-uri) - hostname (.-hostname (.-location js/window)) + hostname (some-> js/window .-location .-hostname) host (cond ws-host ws-host (seq hostname) hostname diff --git a/src/adzerk/boot_reload/reload.cljs b/src/adzerk/boot_reload/reload.cljs index 13d612e..56272d0 100644 --- a/src/adzerk/boot_reload/reload.cljs +++ b/src/adzerk/boot_reload/reload.cljs @@ -77,7 +77,7 @@ (defn reload [changed opts] (let [changed* (->> changed (map (fn [{:keys [canonical-path web-path]}] - (if (= "file:" (.. js/window -location -protocol)) + (if (= "file:" (some-> js/window .-location .-protocol)) canonical-path web-path))) ;; This should probably be empty if serving from file-system