diff --git a/src/helix/core.clj b/src/helix/core.clj index a07ec80..5c78b96 100644 --- a/src/helix/core.clj +++ b/src/helix/core.clj @@ -133,17 +133,17 @@ (throw (ex-info "Invalid hooks usage" {:invalid-hooks invalid-hooks})))) `(do ~(when (:fast-refresh feature-flags) - `(when goog/DEBUG + `(if ^boolean goog/DEBUG (def ~sig-sym (signature!)))) (def ~wrapped-name (-> ~(fnc* wrapped-name props-bindings (cons (when (:fast-refresh feature-flags) - `(when goog/DEBUG + `(if ^boolean goog/DEBUG (when ~sig-sym (~sig-sym)))) body)) - (cond-> goog/DEBUG - (doto (goog.object/set "displayName" ~fully-qualified-name))) + (cond-> + (true? ^boolean goog/DEBUG) (goog.object/set "displayName" ~fully-qualified-name)) ~@(-> opts :wrap))) (def ~display-name @@ -152,7 +152,7 @@ ~wrapped-name) ~(when (:fast-refresh feature-flags) - `(when goog/DEBUG + `(if ^boolean goog/DEBUG (when ~sig-sym (~sig-sym ~wrapped-name ~(string/join hooks) nil ;; forceReset diff --git a/src/helix/core.cljs b/src/helix/core.cljs index 03ea548..d79d46c 100644 --- a/src/helix/core.cljs +++ b/src/helix/core.cljs @@ -38,16 +38,21 @@ [type & args] (let [?p (first args) ?c (rest args) - native? (string? type)] + native? (or (keyword? type) + (string? type) + (:native (meta type))) + type' (if (keyword? type) + (name type) + type)] (if (map? ?p) (apply create-element - type + type' (if native? (impl.props/-native-props ?p) (impl.props/-props ?p)) ?c) (apply create-element - type + type' nil args)))) diff --git a/src/helix/impl/props.cljc b/src/helix/impl/props.cljc index 2f8e6b5..063ec3b 100644 --- a/src/helix/impl/props.cljc +++ b/src/helix/impl/props.cljc @@ -4,21 +4,25 @@ [goog.object :as gobj]])) #?(:cljs (:require-macros [helix.impl.props]))) +(def aria-data-special-case-re #"^(aria-|data-).*") + (defn camel-case "Returns camel case version of the string, e.g. \"http-equiv\" becomes \"httpEquiv\"." [s] (if (or (keyword? s) (string? s) (symbol? s)) - (let [[first-word & words] (string/split s #"-")] - (if (or (empty? words) - (= "aria" first-word) - (= "data" first-word)) - s - (-> (map string/capitalize words) - (conj first-word) - string/join))) - s)) + (let [name-str (name s)] + ; this is hot path so we want to use low-level interop + #?(:clj (cond + (some? (re-matches aria-data-special-case-re name-str)) name-str + (= (subs name-str 0 1) "'") (subs name-str 1) + :else (string/replace name-str #"-(\w)" #(string/upper-case (second %)))) + :cljs (cond + (some? (.match name-str aria-data-special-case-re)) name-str + (= (.substring name-str 0 1) "'") (.substring name-str 1) + :else (.replace name-str #"-(\w)" #(.toUpperCase %2))))) + s)) (defn kw->str [kw] (let [kw-ns (namespace kw)