Skip to content

Commit

Permalink
re-implement figwheel.client.utils/feature? as a macro
Browse files Browse the repository at this point in the history
The previous implementation wrapped cljs.core/exists? (a macro) in a function, meaning that a ReferenceError would throw before exists? can do its thing.
  • Loading branch information
milt committed Mar 2, 2018
1 parent e41aaa9 commit d5dbb3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 5 additions & 0 deletions support/src/figwheel/client/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@
(defmacro dev-assert [& body]
`(dev
~@(map (fn [pred-stmt] `(assert ~pred-stmt)) body)))

(defmacro feature?
[obj feature]
`(and (cljs.core/exists? ~obj)
(cljs.core/exists? (cljs.core/aget ~obj ~feature))))
13 changes: 3 additions & 10 deletions support/src/figwheel/client/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
[goog.userAgent.product :as product])
(:import [goog]
[goog.async Deferred]
[goog.string StringBuffer]))
[goog.string StringBuffer])
(:require-macros [figwheel.client.utils :refer [feature?]]))

;; don't auto reload this file it will mess up the debug printing

Expand Down Expand Up @@ -110,19 +111,11 @@
deferred coll)
(fn [_] (.succeed Deferred @results)))))


(defn- feature? [obj feature]
(and (exists? obj)
(exists? (aget obj feature))))


;; persistent storage of configuration keys

(defonce local-persistent-config
(let [a (atom {})]
(when (case (host-env?)
:worker (feature? (.-localStorage js/self) "setItem")
(feature? js/localStorage "setItem"))
(when (feature? js/localStorage "setItem")
(add-watch a :sync-local-storage
(fn [_ _ _ n]
(mapv (fn [[ky v]]
Expand Down

0 comments on commit d5dbb3e

Please sign in to comment.