Skip to content

Instantly share code, notes, and snippets.

@thheller
Created August 24, 2017 13:51
Show Gist options
  • Save thheller/7f530b34de1c44589f4e0671e1ef7533 to your computer and use it in GitHub Desktop.
Save thheller/7f530b34de1c44589f4e0671e1ef7533 to your computer and use it in GitHub Desktop.

Revisions

  1. thheller created this gist Aug 24, 2017.
    18 changes: 18 additions & 0 deletions es6-class.cljs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    (defn my-component [props context updater]
    (cljs.core/this-as this
    (js/React.Component.call this props context updater)
    ;; anything else you want to set-up. use goog.object/set on this
    this))

    (gobj/extend
    (.. my-component -prototype)
    js/React.Component.prototype)

    ;; cljs-specific properties on constructor
    ;; just so (prn my-component) works properly, not actually required
    (set! (.-cljs$lang$type my-component) true)
    (set! (.-cljs$lang$ctorStr my-component) "MyComponent")
    (set! (.-cljs$lang$ctorPrWriter my-component)
    (fn [this writer opt]
    (cljs.core/-write writer "MyComponent")))
    (set! (.. component-fn -prototype -constructor) my-component)