scittle

2022-05-20T13:15:11.616379Z

What do you think about exposing dynamic imports in scittle? There are CDNs like https://www.skypack.dev/ which might resolve some of the trickier aspects of very modular packages

borkdude 2022-05-20T13:17:32.849469Z

@tgg I think it might be possible to use those modules from other <script> tags and then use them from scittle, right?

2022-05-20T13:18:09.635399Z

You're 100% correct, I typed too soon... just having a fiddle now

borkdude 2022-05-20T13:22:00.535909Z

@tgg Trying myself now too. This kind of works:

<html>
  <head>
    <script type="module">
      import confetti from '';
      globalThis.confetti = confetti;
    </script>
    <script src="" type="application/javascript"></script>
    <script type="application/x-scittle">
      (js/confetti)
    </script>
  </head>
  <body>
  </body>
</html>

borkdude 2022-05-20T13:24:01.864509Z

We could support

(require '["" :as confetti])
probably but this requires a different way of evaluation

borkdude 2022-05-20T13:24:25.377949Z

the hack above probably is sufficient for now

borkdude 2022-05-20T13:27:27.006259Z

I'm writing sci.async and migrating to that makes the require + skypack possible

😍 1
2022-05-20T13:30:46.391919Z

Nice, I wound up with something like this:

<script type="text/javascript">
     var ChakraUI = import('');
    </script>
    <script src="app.cljs" type="application/x-scittle"></script>
and then:
(.then js/ChakraUI
       (fn [chakra]
         (let [ChakraProvider (.-ChakraProvider chakra)
               Button (.-Button chakra)
               my-component (fn []
                              [:> ChakraProvider
                               [:div
                                [:p "Clicks: " (:clicks @state)]
                                [:p [:> Button {:on-click #(swap! state update :clicks inc)}
                                     "Click me!"]]]])]
           (rdom/render [my-component] (.getElementById js/document "app")))))
However, more refinement required!

borkdude 2022-05-20T13:33:09.719169Z

Ah this is a but ugly since confetti will be a promise. The approach I had doesn't require that

2022-05-20T13:34:32.396599Z

Ah, I had thought the modules were asynchronously loaded, I was using the promise based syntax to guarantee ordering.

2022-05-20T13:36:56.975149Z

Ideally I would love it to be synchronously loaded and added to the global context, I feel like I'm suffering the asynchrony purely as a result of the module syntax here. The real solve would be to package up the dependency so it's a UMD type thing and available in the same way as other packages like react, but that doesn't seem to be the modern approach thinking-face

2022-05-20T13:37:35.744079Z

I'm happy with either of the approaches above though! 😀

borkdude 2022-05-20T13:38:16.428489Z

<html>
  <head>
    <script type="module">
      import confetti from '';
      window.confetti = confetti;
    </script>
    <script src="" type="application/javascript"></script>
    <script type="application/x-scittle">
      (js/confetti)
    </script>
  </head>
  <body>
  </body>
</html>
Yeah, so here confetti is the already imported module, not a promise

2022-05-20T13:47:45.591829Z

Ah, I wonder if it's just the latency in acquiring all the resources for the package I'm pulling in.

<script type="module">
     import * as ChakraUI from "";
     console.log(ChakraUI);
     globalThis.ChakraUI = ChakraUI;
    </script>
    <script type="text/javascript">
     console.log(globalThis.ChakraUI);
     setTimeout(() => console.log(globalThis.ChakraUI), 1000);
     setTimeout(() => console.log(globalThis.ChakraUI), 2000);
    </script>
=>
index.html:16 undefined
index.html:17 undefined
index.html:12 Module {…}
index.html:18 Module {…}

2022-05-20T13:49:08.415639Z

And here I was thinking HTTP2|3 had solved all my problems!

borkdude 2022-05-20T13:49:41.041859Z

aaah interesting

borkdude 2022-05-20T13:49:54.951509Z

but when scittle is being kicked off it should be there

borkdude 2022-05-20T13:50:50.105779Z

right...? now I'm not sure ;)

2022-05-20T13:51:38.094409Z

I'm sort of surprised skypack isn't using server push come to think of it; there seems to be a cascade of dependencies 🤔

borkdude 2022-05-20T13:52:16.341639Z

I think it might make sense to expose promesa.core in scittle anyways, to deal with promises, like nbb and joyride

2022-05-20T13:53:19.827859Z

Do you think you'll split it into a separate require as with reagent or default scittle? I can't imagine it adds too much to the payload

borkdude 2022-05-20T13:53:28.349779Z

yes

borkdude 2022-05-20T13:53:33.137739Z

everything will be split

2022-05-20T13:54:08.666909Z

It makes a lot of sense

borkdude 2022-05-20T13:54:30.519189Z

This allows use to add a plethora of libraries without worrying about size and load times

🙏 1
1
borkdude 2022-05-20T13:54:58.556099Z

Perhaps when we migrate to sci.async we could make pulling those libraries automatic ;)

borkdude 2022-05-20T13:57:07.637969Z

https://github.com/babashka/scittle/issues/25

mkvlr 2022-05-20T14:04:42.731749Z

the wonders of an open system