Fork me on GitHub
#cljs-dev
<
2022-07-01
>
john03:07:07

So it looks like the rules around js/SharedArrayBuffer are starting to settle down. You have to add COOP/COEP headers to your server. So I updated my tau.alpha lib https://gitlab.com/johnmn3/tau and got the old demo working https://simultaneous.netlify.app/ on netlify. The whole lib needs a re-write, and decomposition into smaller libs, one of which is a small lib that can spawn workers programmatically, which reminded me of this response I gave to a question about https://clojureverse.org/t/webworker-as-a-librarys-dependency/8277/3?u=john_newman on Clojureverse. For tau.alpha, I got it working in both simple and advanced compile mode https://gitlab.com/johnmn3/tau/-/blob/master/src/tau/alpha/util.cljs#L80. For a rewrite though, I'd like build a thing that works in all compile modes, and works for vanilla, figwheel and shadow-cljs build systems. I think leaning into CLJS modules/code splits might be the best way to make a thing that can be used from all different build systems and compile modes. I wanted to check in here though and see if I could get any pointers. Any gotchas to look out for? Any shortest-paths I haven't considered? Any work desired for addition to CLJS core? On that note, I'm thinking about making a PR to allow vanilla CLJS to take a map of optional headers in the compiler options / build.edn, so you can enable COOP/COEP for enabling development with SABs - in figwheel, I'm using a custom ring.handler. Let me know if anything comes to mind.

john03:07:15

Removing all the tau stuff, that spawn fn boils down to:

(defn create-worker-body [require-ns]
  (let [multi-loader
        (str "CLOSURE_BASE_PATH = '" goog/basePath "';\n"
             "this.CLOSURE_IMPORT_SCRIPT = (function(global) {\n"
             "    return function(src) {\n"
             "        global['importScripts'](src);\n"
             "        return true;\n"
             "    };\n"
             "})(this);\n"
             "if(typeof goog == 'undefined') importScripts(CLOSURE_BASE_PATH + 'base.js');\n"
             "importScripts('" (str goog/basePath "../cljs_deps.js") "');\n"
             "goog.require('" require-ns "');\n")
        single-loader
        (str
          "importScripts('" (last (scripts-src)) "');\n")]
    (if (empty? goog/basePath) single-loader multi-loader)))
Wondering if there's a better, more resilient way to go about that, perhaps using code-splitting modules, that'll work in both advanced compiled mode and simple (or none), across all build tools.

john03:07:56

And that was written over 4 years ago, so there might be a better way these days