lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
631 stars 52 forks source link

components wrapped in HOC can't refer to themselves w/o fully qualified name #89

Closed lilactown closed 3 years ago

lilactown commented 3 years ago

Since we create the inner fn of the component with the same name as var we are defing, if you wrap the component in an HOC and call it recursively you end up getting the unwrapped component 😓

example psuedo-code of the bug:

(def node-view (-> (fn node-view [props]
                     ;; this refers to the inner fn, not the top-level def node-view!!
                     ($ node-view ,,,))
                   (helix.core/memo)))
SevereOverfl0w commented 3 years ago

Are you talking about what the macro expands to, rather than the expected behaviour?

I think that's the normal Clojure behaviour?

user=> (defn hof [f] (fn [& args] (println "hof") (apply f args)))
#'user/hof
user=> (def foo (-> (fn foo [x] (if (zero? x) x (foo (dec x)))) hof))
#'user/foo
user=> (foo 3)
hof
0

hof is called once on the layer (The literal (foo 3)), but not on the nested calls.

lilactown commented 3 years ago

the snippet in the OP is an example of what the macro expands to in order to remind me why this is happening.

the actual example macro call is:

(defnc node-view
  [props]
  {:wrap [(helix.core/memo)]}
  ($ node-view ,,,))

and I think it's surprising that the nested node-view won't be wrapped in the helix.core/memo HOC.