Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Lokeh/helix
Browse files Browse the repository at this point in the history
  • Loading branch information
lilactown committed Jan 31, 2020
2 parents e43b5ed + 199552c commit 0ac5b18
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/helix/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/helix/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down
22 changes: 13 additions & 9 deletions src/helix/impl/props.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0ac5b18

Please sign in to comment.