Created
April 10, 2019 10:05
-
-
Save boogie666/c3eb668dffe6c0bb725b74820ac4d8bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn- -create-react-component | |
"create a 'inline' component and set the display name to the same name as the function" | |
[f] | |
(let [component (fn [js-props] | |
(let [args (.-uixprops js-props)] | |
(hiccup->react (apply f args))))] | |
(set! (.-displayName component) (.-name f)) | |
component)) | |
;; obvious optimization if obvious | |
(defonce ^:private create-react-component (memoize -create-react-component)) | |
;; compile method for components | |
(defmethod compile-hiccup-ast :component [[_ {:keys [type args] :as c}]] | |
(react/createElement (create-react-component type) | |
#js{:uixprops args})) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment