Skip to content

Commit

Permalink
work around react/createElement dynamic arity dispatch
Browse files Browse the repository at this point in the history
I have an interesting problem here, I require react as an npm module. I have a macro which emits `react/createElement`. I cannot do that in my macro because compiler complains (I guess due to that “react” is not normal namespace, it is coming from npm, with normal namespaces this normally works). When I create some alias `(def my-create-element react/createElement)` and emit `my-ns/my-create-element` instead. All works, but release build suffers from generating dynamic arity dispatch. Even if I specify explicit fixed arity `(defn my-create-element [x] (react/createElement x))` it does not get inlined in advanced mode (verified with --pseudo-names).

Any ideas, how could I reference react/createElement in my macro directly? `js/React.createElement` does not work. “React” is not avail at runtime due to way how shadow isolates npm modules (?)
  • Loading branch information
darwin committed Feb 1, 2020
1 parent 77aea99 commit 1d23a50
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/src/app/react_three_fiber/examples/lib/ui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
`(helix.core/defnc ~@args))

(defn gen-create-element [type & args]
`^js/React.Element (helix.core/create-element ~type ~@args))
`^js/React.Element (js/reactCreateElement ~type ~@args))

; TODO: wait for https://github.com/Lokeh/helix/issues/9
(defmacro $ [type & args]
Expand Down
1 change: 1 addition & 0 deletions examples/src/app/react_three_fiber/examples/lib/ui.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

(def <canvas> Canvas)
(def <dom> Dom)
(set! (.-reactCreateElement js/window) react/createElement)

(defn render! [react-el dom-el]
(rdom/render react-el dom-el))
Expand Down

0 comments on commit 1d23a50

Please sign in to comment.