Skip to content

Commit

Permalink
fix double-calling HoCs and also don't wrap them in a list
Browse files Browse the repository at this point in the history
  • Loading branch information
lilactown committed Mar 26, 2019
1 parent e503744 commit aa1b090
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
6 changes: 4 additions & 2 deletions examples/workshop/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,17 @@
hoc))

(defn hoc-example2 [color]
(fn [c]
(fn example2 [c]
(let [hoc (hx/fnc Example [_]
[:div {:style {:color color}} [c]])]
(set! (.-displayName hoc) (str "Color(" (.-displayName c) ")"))
hoc)))

(hx/defnc HoCWrapper [_]
{:wrap [hoc-example
(hoc-example2 "green")]}
(react/memo =)
((hoc-example2 "green"))
]}
[:span "HoC should be header and green"])

(dc/defcard hoc-wrapper
Expand Down
23 changes: 10 additions & 13 deletions src/hx/react.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
(map (fn [x] `(assert ~x)) (:pre (first body))))
(hx.react/parse-body
;; post-conditions
~(if (and opts-map? (:post (first body)))
;; save hiccup value of body
`(let [~ret (do ~@(rest body))]
;; apply post-conditions
~@(map (fn [x] `(assert ~(replace {'% ret} x)))
(:post (first body)))
~ret)
~(if opts-map?
(if (:post (first body))
;; save hiccup value of body
`(let [~ret (do ~@(rest body))]
;; apply post-conditions
~@(map (fn [x] `(assert ~(replace {'% ret} x)))
(:post (first body)))
~ret)
`(do ~@(rest body)))
;; if no post-conditions, do nothing
`(do ~@body)))))))

Expand All @@ -60,12 +62,7 @@
(when js/goog.DEBUG
(set! (.-displayName ~wrapped-name) ~(str *ns* "/" display-name)))
(def ~display-name (-> ~wrapped-name
~@(-> body first :wrap
;; wrap as a list so that you can do
;; like `[hocA (returns-hocB some-config)]`
;; and `(returns-hocB some-config)` will be
;; called to return an HoC
(as-> w (map list w)))))))
~@(-> body first :wrap)))))

`(do (def ~display-name ~(fnc* display-name props-bindings body))
(when js/goog.DEBUG
Expand Down

0 comments on commit aa1b090

Please sign in to comment.