Fork me on GitHub
#shadow-cljs
<
2022-07-05
>
john00:07:09

Okay, here's an early crack at it: https://github.com/johnmn3/in.mesh

stagmoose09:07:46

in https://cljs.github.io/api/syntax/dot says (js/console.log "HELLO") and (.log js/console "HELLO") are equivalent. Can this also be applied to module imported with shadow? I have ["slate-react" :refer (ReactEditor Slate Editable withReact)] under my namespace, and: ā€¢ (ReactEditor.focus editor) didn't work. ā€¢ (.focus ReactEditor editor) works. Is this the difference I need to notice between normal cljs and shadow?

thheller16:07:24

@s0930161 my own personal rule for this is to only use the . when using namespace qualified symbols. which also happens to play nice with my other rule of barely ever :refer. so I would to ["slate-react" :as sr] then (sr/ReactEditor.focus)

šŸ‘Œ 1
stagmoose00:07:14

I see. thanks for the help!

thheller16:07:55

or you can also so ["slate-react$ReactEditor" :as sre] and (sre/focus)

thheller16:07:19

no intended difference between cljs and shadow in this. should all behave the same.

thheller16:07:26

@john nothing stops you from doing a separate build for the worker in shadow-cljs. the final result is larger than it needs to be so I don't recommend it but you can. as for the REPL the editors just don't support picking the runtime. you can REPL into the workers just fine. has nothing to do with modules though. (shadow/repl-runtimes :the-build) then (shadow/repl :the-build {:runtime-id 123}) using the :client-id listed in the previous command. (unfortunate renaming incident left in those thats why the names differ)

john19:07:34

Okay, that's pretty awesome

john19:07:38

I'm trying to imagine what it would look like to reduce friction as much as possible wrt letting users spawn webworkers, without having to necessarily deal with build configs. But, in the default quickstart scenarios that may be easy, but when a user is preferring to use multiple build ids and/or multiple modules, then we don't know where to target that webworker spawn fn without more input from the user, right? Two questions: 1. Would it be possible, from within the lib, to issue a request to spawn a webworker build for an existing build, if one doesn't already exist? (say, in the default quickstart scenario) So that in simple cases users don't have to change build configs? and 2. For more complex scenarios, would it be possible to let user's pass build id and/or module id in on the spawn fn to allow them to generate a new build or module (not yet existing in the build config) based on whatever is passed in?

john19:07:20

Like, does shadow expose a programmatic API such that a lib that one brings in could optionally extend their current build configuration? And how hairy would that be?

john20:07:26

Hmm, that requires changing one's build config though... My feeling is that, in the default situation, users shouldn't have to make augmentations to their build config in order to use webworkers in clojurescript. I feel like spawning workers should be a supported use case after completing any of the quick start directions for raw cljs, shadow or figwheel.

john20:07:26

Having a lib that provides it's own worker script with importScripts that pulls down things in the correct way would be fine, but IDK how much other stuff shadow and figwheel are doing throughout the rest of the build to accommodate workers, so I wouldn't want to break the build tool's expectations

john20:07:45

Option 1: depend on the build tool's worker-import-script for pulling down dependencies, potentially requiring the user to make build config changes, Option 2: provide a default worker-import-script that tries to do the right thing for all the different build tools, independent from their own configs

john20:07:22

If worker-import-script is mostly just a small thing, and most of the build is the same, why don't we just always ship a worker-import-script for every build? As long as it can reuse all the existing code in the non-worker build artifact, it's just an extra KB or two

john20:07:35

And if the user wants to learn how to go through adding more build ids or modules to their build config, then they can easily just pass the same IDs to their spawn fn, like (spawn {:build-id ..., or module id. Currently, there's really no way to ship libs that provide web worker capabilities without forcing their users to learn advanced build ceremony, which is different for every build tool

john20:07:08

In an ideal world, CLJS could have some worker fn in core, and the different build tools could fulfill some contract that makes it work. Few other languages impose this much ceremony to achieve programmatically spawning parallelism

john20:07:57

But short of that, maybe we can provide that via a lib, so that's what I'm exploring now

john22:07:34

I see I can get shadow/active-builds and then shadow/get-build-config for the active builds. But can I then update those build configs at runtime?

john22:07:49

I'd potentially want to duplicate existing modules with sister worker module configs, just adding :web-worker true, allowing you to connect to them via a worker optionally

john22:07:48

With maybe a shared module between them, so the worker is just adding the shim code

john22:07:03

Or maybe I can just have the worker :depend on the non-worker one