squint icon indicating copy to clipboard operation
squint copied to clipboard

defclass static methods and fields

Open brandonstubbs opened this issue 1 year ago • 5 comments

It would be great if defclass could support static methods and fields as it's widely available now.

At the moment as a workaround I am doing the following as mentioned here (https://clojureverse.org/t/modern-js-with-cljs-class-and-template-literals/7450/6):

(defclass DisplayVar
  (extends HTMLElement)
  (constructor [this]
    (super))

  Object
  (attributeChangedCallback [this name old-val new-val]
    (js/console.log name old-val new-val)))

(set! (.-observedAttributes DisplayVar) ["variable"])

brandonstubbs avatar Mar 26 '24 15:03 brandonstubbs

Agreed

borkdude avatar Mar 26 '24 15:03 borkdude

Is there any prior art of this in shadow-cljs? the defclass syntax stuff in squint is mostly borrowed ffrom shadow.

borkdude avatar Mar 26 '24 15:03 borkdude

No, as he mentioned in that linked Clojureverse thread there weren't standards about it at the time. There is also issues in the Closure compiler for static and private class extensions. So this is probably the reason he never extended the functionality

This is actually one of the big reasons I am using squint. Using shadow with the Google Closure Compiler has issues with a lot of modern libraries that are starting to use these features and it doesn't look like they will be resolved soon.

brandonstubbs avatar Mar 26 '24 15:03 brandonstubbs

Perhaps just:

Object
(^:static foobar []
    (js/fetch "https://clojure.org"))

would be ok-ish?

borkdude avatar Mar 26 '24 15:03 borkdude

Perhaps just:

Object
(^:static foobar []
    (js/fetch "https://clojure.org"))

would be ok-ish?

Yeah I think that would be ok

brandonstubbs avatar Mar 26 '24 15:03 brandonstubbs