Fork me on GitHub

@adam678 Has anybody used io.helins/timer.cljs compiled with advanced optimizations? I recently added a profile with advanced optimizations to my project, and 3 new problems came up, 2 of which were resolved by infer-externs and then referring to the resulting file in :externs ["inferred_externs.js"] in the uberjar that compiled with advanced optimizations. I am having trouble resolving the 3rd problem, which shows up in timer.cljs code. app.js:30125 Uncaught TypeError: $this$$1$jscomp$inline_2739$$.$helins$timer$ITimer$in$$arity$3$ is not a function at $helins$timer$t_helins$0timer17812$$.$JSCompiler_prototypeAlias$$.$helins$timer$ITimer$every$arity$4$ (app.js:30125:97) at $helins$timer$t_helins$0timer17812$$.$JSCompiler_prototypeAlias$$.$helins$timer$ITimer$every$arity$3$ (app.js:30122:15) at $mbweb$connect_ui$polling$start_polling$$ (app.js:30212:101) at app.js:30237:10 at app.js:17261:385 at $re_frame$interceptor$invoke_interceptors$$ (app.js:17015:503) at $re_frame$events$handle$$ (app.js:17090:9) at $JSCompiler_StaticMethods_re_frame$router$IEventQueue$process1st_event_in_queue$arity$1$$ (app.js:17190:5) at $JSCompiler_StaticMethods_re_frame$router$IEventQueue$runqueue$arity$1$$ (app.js:17112:5) at app.js:17155:16 I used :pseudo-names true and pretty-print true so the error message is more readable. The timer works great in dev profile, where my optimizations are none. I tried adding definitions to the externs file for all the javascript calls made by timer.cljs, such as js/ and js/queueMicrotask. Instead of using timer.cljs as a library from local maven repo, I tried compiling it with my source code. Neither experiment helped in any way. Any ideas on what I need to do to get it to work?

Adam Helins07:01:36

That's a puzzler, I have used advanced optimization and never had any problem :thinking_face: But that arity error is mysterious. How are you compiling, with Shadow? Maybe try upgrading?


Good to know it has worked before. Thanks. I am using lein -cljsbuild.

Adam Helins10:01:34

In any case, I strongly recommend Shadow-Cljs. Much more capable 🙂 I'd be curious to know if you still have problems using Shadow. I think there are a couple differences when it comes to advanced builds (WRT to inference)


Some good news... if I use (timer/worker) instead of timer/main-thread, it works with no errors, in both my dev and prod profiles! And I will need the timer to run sub-1sec when in background anyhow. I know people love Shadow-Cljs, but I struggled with it. I learned a lot from "Web Development in Clojure" by Sotnikov/Brown, but once I had to serve via HTTPS, it was difficult to adjust. The recommended solution was to use a nginx proxy server. A core part of my solution is Web Serial, which for security reasons, only works with HTTPS. I wasn't sure if the proxy would satisfy Web Serial security and it sounded complicated compared to the simple examples I was seeing with leiningen/jetty/cljsbuild. I'd like to revisit Shadow-CLJS someday, but for now, I need to use whatever allows me to add features to my prototype as fast as possible.

Adam Helins20:01:18

Whatever floats your boat 🙂