Fork me on GitHub
#sci
<
2021-05-26
>
David Pham07:05:03

With sci-tag, is there a way to export a map of function to JS Land?

David Pham07:05:43

so that we have the ability to group our functions into namespace like object/data structure)

David Pham07:05:05

I got it, use js-obj 🙂

borkdude07:05:15

@neo2551 You can make a JavaScript object with functions using clj->js and then use set! to set it to the window object

David Pham07:05:12

Perfect! 🙂

David Pham07:05:25

haha, this is clearly some super power you provided us xD

borkdude07:05:37

@d.ian.b You need to add a <div id="app"></div>

clojure-spin 3
Ian Fernandez13:05:26

duh, I was tired hahaha thx

borkdude09:05:09

@jeroenvandijk a thought: I guess we could distribute both advanced and simple builds, then people can choose. If they only need sci + maybe reagent, they can use the advanced ones. If they want plugins from third parties they can use the simple ones.

jeroenvandijk09:05:37

Yeah I think the advanced is necessary to keep it light weight. And like with Babashka, the most used libraries can be part of your repo through PRs? Not sure about this maintenance burden. If it grows too big for one repo, maybe a similar approach a with the pods could work?

borkdude09:05:19

> most used libraries can be part of your repo through PRs yes, definitely

borkdude09:05:46

maintenance burden, I'm not too concerned about this

borkdude09:05:05

if the project grows bigger, then more maintainers can be added

borkdude09:05:34

the pod approach isn't so nice for CLJS since each part has to bring its own implementation of CLJS core, data structures etc

borkdude09:05:54

at least not if you implement those pods in CLJS as well

borkdude09:05:37

with bb pods this is also the case, but less of a problem since you can cache the downloads pretty well and on servers downloads are less problematic than on web pages

borkdude09:05:23

and the minimum pod size with clojure is about 10mb which is not so big for a binary you have to download, but for a JS file it is

jeroenvandijk09:05:01

yeah I guess you could do a lot with caching and cdn’s, but it would be very unfriendly for first time visitors

jeroenvandijk09:05:21

Do you think we could create a core that exports all vars from namespaces? https://github.com/borkdude/sci/blob/master/src/sci/impl/namespaces.cljc#L730

jeroenvandijk09:05:35

And then only do a small part advanced?

jeroenvandijk09:05:01

I mean renamed via advanced. Maybe the plugins don’t need to repeat that much in that case

borkdude09:05:12

I discussed this in #clojurescript, best to read that

👍 3
borkdude09:05:25

tl;dr: advanced doesn't only do renaming but also inlining etc

borkdude09:05:29

so it isn't that easy

jeroenvandijk09:05:10

Maybe wait indeed until we have enough motivation to explore this

borkdude09:05:26

also I want to rename the project so something nicer. perhaps scittle or something

jeroenvandijk09:05:12

I’ll ask you for naming suggestions when I create a new project 💪

jeroenvandijk09:05:58

Btw, not sure if you think it’s useful but I think some bookmarklet examples are also cool. I played with it last year https://gist.github.com/jeroenvandijk/2c54cfcfacd61a97962c0504a77cacc3

borkdude09:05:26

Perhaps you can make a PR with a bookmarklet.html page (we already have a tictactoe.html page)

jeroenvandijk09:05:29

Yeah I’ll try to come up with something fun

borkdude10:05:45

a heads up, you now must provide your own React when using the reagent plugin:

<script crossorigin src=""></script>
<script crossorigin src=""></script>
<script src="" type="application/javascript"></script>

borkdude10:05:03

to make things even more modular

borkdude10:05:38

you can also provide a development React version, for better error messages this way

jeroenvandijk10:05:16

Is there are a way to evaluate Sci code after the dom has loaded? Maybe I need evalString for my bookmarklet

jeroenvandijk10:05:16

I.e. this triggers an alert

s=document.createElement("script");s.innerText="alert('js')";document.body.appendChild(s)
but this doesn’t
s=document.createElement("script");s.setAttribute('type', 'application/x-sci');s.innerText="(js/alert \"cljs\")";document.body.appendChild(s)
I’m not sure if you can add dom events for loading custom application types. Otherwise I need something like sci.evalString

borkdude10:05:27

this is now done implicitly when the dom content is done loading

borkdude10:05:36

but perhaps it's better to make it explicit

borkdude10:05:24

Same as the highlight JS plugin, it has

hljs.highlightAll();
Perhaps that's more flexible than doing it automatically

jeroenvandijk10:05:51

I think the implicit way is fine for most users. The bookmarklet case is very specific. I just need a way 😅

borkdude10:05:34

maybe we can expose a function that evaluates a dom node

borkdude10:05:54

or a selection of dom nodes

jeroenvandijk10:05:35

maybe eval-string is actually cleaner for my use case. I don’t know about other use cases

borkdude10:05:07

in that case you don't even have to make a script node right?

jeroenvandijk10:05:15

yeah correct. Only for the plugins (scittle and scittle-reagent)

borkdude10:05:32

ok, let's expose it, commit coming

metal 3
borkdude10:05:27

this now works:

scittle.core.eval_string("(prn :hello)");
scittle.js:16 :hello

👌 3
borkdude10:05:30

in the browser console

borkdude10:05:48

The project is now renamed to scittle: https://borkdude.github.io/scittle/

borkdude10:05:01

should we use application/x-scittle too?

borkdude10:05:45

yeah, looks like fun right

borkdude11:05:56

ok, pushing that change

jeroenvandijk13:05:23

@borkdude I have a basic bookmarklet example. What is a good place to put it?

borkdude14:05:55

perhaps you can put it in resources?

borkdude14:05:11

I'll take a look after I cut out 300kb from the build ;)

😎 3
jeroenvandijk15:05:57

FYI, i added two small fixes for a better editting experience 🙂 https://github.com/borkdude/scittle/pull/2

jeroenvandijk15:05:35

I was missing the nice debugging experience of babashka. <---- stacktraces i mean. Maybe something to add later

borkdude15:05:23

@jeroenvandijk how is the bookmarklet working if you navigate away from the page?

borkdude15:05:56

I don't think it does

jeroenvandijk15:05:01

You drag the link to your bookmark page and you can use it on any page (that doesn’t set restrictions)

jeroenvandijk15:05:25

It will throw an error if the scittle js can’t be loaded due to restrictions (e.g. try http://github.com)

borkdude15:05:11

I was trying it in an empty browser page

borkdude15:05:30

oh it does work in CircleCI :)

jeroenvandijk15:05:11

I had some handy ones before in js, but stopped using it. Now with Scittle i’m motivated to write some myself