added a comment - - edited
What do you think of this approach based on
based on http://www.50ply.com/blog/2012/07/08/extending-closure-from-clojurescript/
While it may not preserve enough of gen-class's semantics. This would be enough for us to start gradually porting our large GClosure code base to Clojurescript. The code size reduction would be enormous.
(ns com.example
(:require [goog.ui.tree.TreeControl :as TreeControl]))
(gen-class
:name DemoTree
:extends goog/ui.tree.TreeControl
:constructor ([name config]
(goog/base (js* "this") name config))
:methods [[handleKeyEvent [e]
(goog/base (js* "this") "handleKeyEvent" e)
;; my special code to handle the key event
]])
here is a untested mock implementation modified from http://www.50ply.com/blog/2012/07/08/extending-closure-from-clojurescript/
I changed constructors to constructor because there can be only one in js
This unfortunately has different semantics from gen-class because the original did not include the definition of the methods and constructor inline. It tried to read the Clojure gen-class source,but I still do not yet understand how the :prefix grabbing of functions from the current namespace works from within a macro.
For Google Closure interop each class should have its own provide
(defmacro gen-class [{new-type :name base-type :extends ctor :constructor methods :methods}]
`(do
;(goog/provide ~@(str *ns* "." new-type))
(defn ~new-type ~@ctor)
(goog/inherits ~type ~base-type)
~@(map
(fn [method]
`(set! (.. ~type -prototype ~(to-property (first method)))
(fn ~@(rest method))))
methods)))
What do you think of this approach based on
based on http://www.50ply.com/blog/2012/07/08/extending-closure-from-clojurescript/
While it may not preserve enough of gen-class's semantics. This would be enough for us to start gradually porting our large GClosure code base to Clojurescript. The code size reduction would be enormous.
here is a untested mock implementation modified from http://www.50ply.com/blog/2012/07/08/extending-closure-from-clojurescript/
I changed constructors to constructor because there can be only one in js
This unfortunately has different semantics from gen-class because the original did not include the definition of the methods and constructor inline. It tried to read the Clojure gen-class source,but I still do not yet understand how the :prefix grabbing of functions from the current namespace works from within a macro.
For Google Closure interop each class should have its own provide
(defmacro gen-class [{new-type :name base-type :extends ctor :constructor methods :methods}] `(do ;(goog/provide ~@(str *ns* "." new-type)) (defn ~new-type ~@ctor) (goog/inherits ~type ~base-type) ~@(map (fn [method] `(set! (.. ~type -prototype ~(to-property (first method))) (fn ~@(rest method)))) methods)))(defmacro gen-class [{new-type :name base-type :extends ctor :constructor methods :methods}] `(do ;(goog/provide ~@(str *ns* "." new-type)) (defn ~new-type ~@ctor) (goog/inherits ~type ~base-type) ~@(map (fn [method] `(set! (.. ~type -prototype ~(to-property (first method))) (fn ~@(rest method)))) methods)))