This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-11
Channels
- # announcements (1)
- # aws (5)
- # beginners (8)
- # biff (7)
- # calva (32)
- # cider (26)
- # clj-kondo (6)
- # clojure (100)
- # clojure-europe (6)
- # clojure-greece (1)
- # clojurescript (15)
- # core-logic (3)
- # fulcro (2)
- # honeysql (4)
- # hoplon (39)
- # hyperfiddle (11)
- # lsp (12)
- # other-languages (2)
- # podcasts-discuss (1)
- # squint (30)
This ☝️ PR adds a provider that uses the dom apis directly. I added an experimental :smart-class
attribute that can remove classes when using strings or vectors. But it doesn't compose well as multiple calls would remove classes that shouldn't be removed.
Wouldn't it make sense to load that dom namespace by default? It's not like it's going to add much extra weight to the library? I wonder if removing the multimethod indirection altogether would make stuff perform better. It seems the multimethod was only there to offer a choice between jquery and goog but now that isn't necessary anymore?
I'm not sure if applied-science.js-interop adds more size to the bundle, but probably not since they are mostly macros that emit direct JS interop code when used properly
I did a build report and the dom provider is smaller than goog and js-interop adds 45 bytes.
this 45 bytes is probably a mis-representation, because it's just a dummy module that refers to its real function in another module
> Wouldn't it make sense to load that dom namespace by default? It's not like it's going to add much extra weight to the library? I wonder if removing the multimethod indirection altogether would make stuff perform better. It seems the multimethod was only there to offer a choice between jquery and goog but now that isn't necessary anymore? That would be a potential breaking change for projects that depend on jquery that is the current default so I want to make sure that this is working as it should before changing it. Multimethods predate the goog provider and are a mechanism for users to add custom attributes and I'm not sure of a good way to provide that without using them (considering the ergonomics of using this extension mechanism).
> I can take a look if you tell me how to build
The way I'm testing this is not something I'm proud yet but it works 😅
• clone hoplon locally https://github.com/hoplon/hoplon and checkout the dom-provider
branch
• clone hoplon-demos locally https://github.com/hoplon/demos and checkout the hoplon-local-counter
branch.
• go to the counters directory on hoplon-demos:
◦ npm install
◦ npx shadow-cljs watch app
The file src/demo/counter.cljs
on the counters demo has the requires for the providers. I comment the providers that I don't want and leave only the one I want.
To build the report the command is npx shadow-cljs run shadow.cljs.build-report app report.html
I think that the core namespace could be bigger because of the macro expansion, but not sure about how to confirm this.
although in some cases, like get-in
you will get bigger code because of nil checks:
cljs.user=> (macroexpand '(j/get-in x [:foo :bar]))
(let* [obj1617 (clojure.core/let [obj1616 x] (if (clojure.core/some? obj1616) (cljs.core/unchecked-get obj1616 "foo") js/undefined))] (if (clojure.core/some? obj1617) (cljs.core/unchecked-get obj1617 "bar") js/undefined))
> well, good job, hope the PR gets merged Thanks! It will. I will revert the namespace change on the goog provider and will merge it soon and make a release.
I wanted to replace goog.obj/set
. I will see what would be other options for that. To access attributes, I will not use js-interop anymore.
cljs.user=> (str (fn [obj] (unchecked-set obj "foo" 1)))
"function (obj){\nreturn (obj[\"foo\"] = (1));\n}"
or:
cljs.user=> (str (fn [obj] (set! (.-foo obj) 1)))
"function (obj){\nreturn (obj.foo = (1));\n}"
unchecked-set bypasses advanced compilation, but I think if you add a ^js
type hint for the argument you pass to set
it will also do the same. shadow-cljs will warn you if it can't infer that it is a JS value or not