Skip to content

Commit

Permalink
cleanup feature-flags for refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
lilactown committed Feb 9, 2020
1 parent 84e979c commit 7edfe88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/helix/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,25 @@
hooks (hana/find-hooks body)
sig-sym (gensym "sig")
fully-qualified-name (str *ns* "/" display-name)
feature-flags (:helix/features opts)]
feature-flags (:helix/features opts)

;; feature flags
flag-fast-refresh? (:fast-refresh feature-flags)]
(when (:check-invalid-hooks-usage feature-flags)
(when-some [invalid-hooks (->> (map hana/invalid-hooks-usage body)
(flatten)
(filter (comp not nil?))
(seq))]
(throw (ex-info "Invalid hooks usage"
{:invalid-hooks invalid-hooks}))))
`(do ~(when (:fast-refresh feature-flags)
`(do ~(when flag-fast-refresh?
`(if ^boolean goog/DEBUG
(def ~sig-sym (signature!))))
(def ~display-name
~@(when-not (nil? docstring)
(list docstring))
(-> ~(fnc* display-name props-bindings
(cons (when (:fast-refresh feature-flags)
(cons (when flag-fast-refresh?
`(if ^boolean goog/DEBUG
(when ~sig-sym
(~sig-sym))))
Expand All @@ -156,8 +159,8 @@
(doto (goog.object/set "displayName" ~fully-qualified-name)))
~@(-> opts :wrap)))

~(when (:fast-refresh feature-flags)
`(if ^boolean goog/DEBUG
~(when flag-fast-refresh?
`(when ^boolean goog/DEBUG
(when ~sig-sym
(~sig-sym ~display-name ~(string/join hooks)
nil ;; forceReset
Expand Down
2 changes: 1 addition & 1 deletion src/helix/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,4 @@
(defn signature! []
;; grrr `maybe` bug strikes again
(and (exists? (.-$$Signature$$ js/window))
(.$$Signature$$ js/window)))
(.$$Signature$$ js/window)))

0 comments on commit 7edfe88

Please sign in to comment.