Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns react.helper
- #?(:cljs (:require [cljsjs.react]
- [cljsjs.create-react-class])))
- #?(:cljs
- (defn- react-factory [display-name render]
- (js/React.createFactory
- (js/createReactClass
- #js {:displayName display-name
- :shouldComponentUpdate
- (fn [next-props _]
- (this-as this
- (not= (.. this -props -value) (.-value next-props))))
- :render
- (fn []
- (this-as this
- (apply render (-> this .-props .-value))))}))))
- #?(:cljs
- (defn component [display-name render]
- (let [factory (react-factory display-name render)]
- (fn create-element [& props] (factory #js {:value props})))))
- #?(:cljs
- (defn $ [el & args]
- (let [[opts children] (if (map? (first args))
- [(clj->js (first args)) (rest args)]
- [#js {} args])]
- (apply js/React.createElement el opts children))))
- #?(:clj
- (defmacro defc [name argv & body]
- `(def ~name (react.helper/component (name '~name) (fn ~argv ~@body)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement