Fork me on GitHub
#shadow-cljs
<
2024-03-01
>
magra13:03:17

I also asked in datascript, but now I think it is more shadow-cljs related. I am passing the function includes? to datascript.

(d/q '[:find [(pull ?e ?pattern) ...]
        :in $ ?sf ?pattern includes?
        :where
        [?e :person/firstname ?f]
        [(includes? ?f ?sf)]
        [?e :person/id ?i]]
      db search-firstname pattern includes?)
This works in development, but returns [] in production compiled with shadow-cljs in a webworker. What do I have to do to the function so it works in advanced compilation? ^:export seems not to be it.

magra13:03:45

This works:

(d/q `[:find [(~'pull ~'?e ~'?pattern) ...]
           :in ~'$ ~'?sf ~'?pattern
           :where
           [~'?e :person/firstname ~'?f]
           [(~includes? ~'?f ~'?sf)]
           [~'?e :person/id ~'?i]]
        db search-firstname pattern)

thheller14:03:37

do you include the datascript externs? only guess I have

thheller14:03:58

don't know much about how datascript works internally, maybe it expects parameters to all start with a ?

magra15:03:35

:compiler-options {:externs ["datascript/externs.js"]} did it! Thanks!!!

Felipe14:03:02

hey 👋 I have three little helper functions:

(defn js-append [^array array val] (.concat array #js [val]))
(defn js-add-at [^array array idx val] (.toSpliced array idx 0 val))
(defn js-remove-at [^array array idx] (.toSpliced array idx 1))
I originally didn't type hint array and got a externs inference warning, so added ^array . that made the warning go away. on production, though, js-append works fine but js-add-at and js-remove-at try to invoke array.$toSpliced$ instead of array.toSpliced. my questions: 1. why does the hinting work for concat and not for toSpliced? newer function? 2. when should I use ^array vs. ^js? ^js makes the code compile correctly. 3. is this a shadow or clojurescript thing? I'm assuming shadow has its own externs inference logic for some reason

1
thheller14:03:59

^array means no externs are getting generated

thheller14:03:05

use ^js instead I guess

thheller14:03:23

I suspect that toSpliced is not part of the standard browser externs

thheller14:03:50

looks like that is pretty new?

Felipe14:03:45

oh yeah, last year it seems. I assumed all green on caniuse meant it was ancient, but browsers seem to be adopting stuff quickly nowadays

Felipe14:03:04

why does ^js work though?

Felipe14:03:22

and where do the standard browser externs come from?

thheller14:03:04

js and anything js/ tells the compiler: generate externs

👍 1
thheller14:03:14

every other tag tells it: do not generate externs

Felipe14:03:47

got it. thanks!

martinklepsch17:03:04

I have a file data.json that I'd like to inline into my build, is there a way to do this using :require ? I'm using :js-provider :import

martinklepsch17:03:54

I also noticed that the :import option is not documented here: https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider Not sure if it should be?

thheller20:03:10

it is documented here https://shadow-cljs.github.io/docs/UsersGuide.html#_third_party_tool_integration since that is the only target it works in

thheller20:03:23

and no, there is no way to do this via :require

thheller20:03:40

well, I guess if you make it an npm package

thheller20:03:51

but you should really consider loading it at runtime unless it is extremely tiny

martinklepsch20:03:34

Okay, was just wondering since this is so easy with tools like vite. But it's actually not that small so I'll just load at runtime 🙂

thheller07:03:59

well shadow-cljs can do it for .json files in node_modules because it kinda has to. doesn't change that I think its a bad idea and almost always the wrong choice. especially if its gets larger.