Fork me on GitHub
#clojurescript
<
2019-01-04
>
Kelly Innes01:01:14

Is there a semi-canonical list of heavily used ClojureScript libraries in need of better documentation?

dnolen03:01:32

@lilactown that's what I was saying earlier, can't work

dnolen03:01:46

the same problem exists for any JS application with custom data structures

dnolen03:01:52

nothing to do w/ ClojureScript at all

dnolen03:01:16

this problem also arises when communicating between multiple JS contexts

dnolen03:01:23

where Array != Array etc.

lilactown03:01:23

well, I think I can probably get around this by creating my own JS event bus and just accessing it through goog.object

lilactown03:01:54

or using something native to the browser :thinking_face:

lilactown03:01:08

looks like core.async uses window.MessagePort

dnolen03:01:43

if I recall it only uses that for dispatching

dnolen03:01:02

it's not used as a communication channel

lilactown03:01:24

I’ll have to fiddle with this. serializing and reading the data I want to send on the channel is not a big deal

lilactown03:01:37

I’ll have to do some research

dnolen03:01:40

well I'll just offer my opinion that I don't think getting multiple ClojureScript builds to work together is worth the trouble

lilactown03:01:04

well, with the way I’ve written the application right now I feel like it’s worth it.

lilactown03:01:42

it’s a dev tool, meant to be used alongside your app. but it has it’s own set of dependencies, e.g. it’s using an alpha version of React, that I don’t want to burden the user with configuring

lilactown03:01:16

much easier to just put a script tag on the page and include a dependency that does the bit of interop to setup the communication channel

dnolen03:01:44

if you're going down this path then I think the only thing that won't lead to a lot of headaches is to completely isolate the different builds and have them talk via JSON/Transit/EDN

lilactown03:01:35

which is fine. the idea is to have it run in a separate window, or maybe even a chrome extension, later on. plus, I want to support Node.js and (stretch goal) JVM Clojure which would necessarily have to serialize the data anyway

lilactown03:01:31

I was trying to cheat a bit in the meantime

lilactown03:01:59

while they were still technically in the same process 😄

lilactown03:01:53

I appreciate the advice and information @dnolen. it’s helped a lot

sova-soars-the-sora05:01:12

Uncaught Error: No protocol method IAssociative.-assoc defined for type cljs.core/IndexedSeq: ({:number-of-ratings 0, :title "You can listen to lots of audiobooks for free online at librivox", :posted-by "jade", :link 

dpsutton05:01:21

You're associng onto a sequence of maps not a map it seems

sova-soars-the-sora05:01:57

so i have a collection of maps

sova-soars-the-sora05:01:03

and i want to conj on all these maps i have

sova-soars-the-sora05:01:27

but they come packaged as ({:maps ""} {:maps "x"} {:maps "z"})

sova-soars-the-sora05:01:47

how can i conj all those maps into my clientside atom?

lilactown06:01:13

You want to conj something to the value of the :maps key? Or onto each map in the list?

martinklepsch14:01:51

I'm looking for this thing that analyzes CLJS source maps and spits out how much each namespace etc takes up — anyone has a pointer to that?

sova-soars-the-sora15:01:28

@lilactown just trying to join two vectors of maps into one. but one looks like [ { } {} {} {} {} ] and the other like ( {}{}{} )

john21:01:09

Also for this try into

mfikes15:01:25

@sova A tiny example of the two inputs and the desired output would help sort out exactly what is needed

mfikes15:01:05

(The example can use minimal fake data.)

sova-soars-the-sora15:01:06

(def daytuh (atom [{:id 7 :summary "Zed" :comments [   ] }
                     {:id 8 :summary "Penguin" :comments [   ] }]))
Now a user initiates an action to write! a new comment to the db. new comments have their own :id, like 99. At the end of an action where the user is commenting on post with :id 8 the atom should look like:
@daytuh= [{:id 7 :summary "Zed" :comments [ ] }
                     {:id 8 :summary "Penguin" :comments [ 99 ] }]))
And at the end of another action where another user makes a new comment with :id 177 on post with :id 8
@daytuh= [{:id 7 :summary "Zed" :comments [ ] }
        {:id 8 :summary "Penguin" :comments [ 99  177 ] }]

mfikes15:01:03

Dang. Too bad your data isn’t a map keyed by ID instead, then you could just directly do

(update-in {7 {:summary "Zed" :comments []} 8 {:summary "Penguin" :comments []}} [8 :comments] conj 99)

mfikes16:01:49

@sova With the shape of your data, it seems that you will have to do a scan. For example,

(defn scan-idx [k v coll]
  (reduce-kv (fn [_ idx m] (when (= v (k m)) (reduced idx)))
   nil
   coll))
then
(let [data [{:id 7, :summary "Zed", :comments []} {:id 8, :summary "Penguin", :comments []}]]
  (update-in data [(scan-idx :id 8 data) :comments] conj 99))
But that’s less than ideal.

metal 5
🐝 5
parens 5
sova-soars-the-sora16:01:12

I'm fine with it for the time-being. Putting some sort of index on the data is too opinion'd a stance for the moment

sova-soars-the-sora16:01:23

and thank you, that helps a lot

sova-soars-the-sora16:01:42

Okay I keep getting errors on

sova-soars-the-sora16:01:46

ncaught Error: No protocol method IKVReduce.-kv-reduce defined for type cljs.core/IndexedSeq:

mfikes16:01:49

Smells like something turned your vector into a seq

nathanmarz16:01:58

@sova this is bread and butter use case for specter:

user=> (def data
         (atom
          [{:id 7 :summary "Zed" :comments [ ] }
           {:id 8 :summary "Penguin" :comments [ 99 ] }]))

user=> (setval [ATOM ALL #(= 8 (:id %)) :comments AFTER-ELEM] 177 data)

user=> @data
[{:id 7, :summary "Zed", :comments []} {:id 8, :summary "Penguin", :comments [99 177]}]

sova-soars-the-sora16:01:41

@mfikes (swap! tv-state vec) solved my problem

rachit18:01:54

Is it possible to assign a clojure to a javascript property from cljs? I want to do something of the form:

obj.f = (x) => x + 1

thheller18:01:50

(let [obj #js {:f (fn [x] (+ x 1))}] ...)

rachit18:01:00

Does that create a JS function called obj?

thheller18:01:45

no. it creates a js object with a .f property which is a function

rachit18:01:57

Ah, but how do I assign to a preexisting obj?

thheller18:01:26

(goog.object/set obj "f" (fn [..] ...))

rachit18:01:33

Got it, thanks!

mseddon18:01:27

I am thinking of trying to build a self-hosting clojurescript page with a custom web-based repl using cljs.js/eval-str, but I've not tried this before. Are there any caveats or limitations I should know of running clojurescript this way (aside from obviously having a fixed set of dependencies, large download, potential to hang the browser tab...), or should it all 'just work'?

mseddon18:01:17

basically something like https://jscl-project.github.io/ (which has all the issues mentioned above, too).

lilactown18:01:55

pretty much all of clojurescript core is self-host compatible

mseddon18:01:30

nice, I will have a mess about with that soon then, thanks 🙂

dnolen19:01:25

note fixed set of dependencies is not really a limitation - bootstraped ClojureScript was designed to load dependencies after the fact

dnolen19:01:09

well we won't load them for you, just it assumes they will have to loaded asynchronously somehow

mfikes19:01:54

@mseddon If you are doing it for fun / learning, then cool! If you need this for something else and want to quickly end up with a working solution, this stuff under this page is a reusable library https://clojurescript.io

mseddon19:01:51

@mfikes fun all the way! But that looks like it may be worth peeking at, thanks!

mfikes19:01:09

Cool. Self-hosted ClojureScript is still the deep-end of the pool, where the opportunity for maximal learning exists 🙂

mseddon19:01:05

😀 breaking things is fun

borkdude19:01:56

@mseddon I have just made https://re-find.it which is a really limited REPL (only the READ EVAL PRINT part, not the Loop). It was the first time I used self-hosted CLJS and it was pretty easy to get going

borkdude19:01:59

http://app.klipse.tech is more advanced in terms of REPL experience and it also supports loading libraries from external sources from the web

mseddon19:01:22

http://repl-interactor.netlify.com is the beginnings of my web based repl. Except currently I've basically built a clojure syntax highlighting/auto indenting edit box from scratch atm

mfikes19:01:41

There are other cool applications of self-hosted too https://ctford.github.io/klangmeister/ for music Timothy Pratley’s turtle thing https://www.youtube.com/watch?v=0fKpGy2QuMM

mseddon19:01:01

😀 these are all great!

borkdude19:01:03

just mentioned that one

borkdude19:01:14

I was trying to lower the size of the compiled artifact, it’s now around 8MB in size un-gzipped, 1MB gzipped

mseddon19:01:50

That's good enough I think, I am surprised ClojureScript can fit into that

borkdude19:01:55

yeah, it’s already pretty good. most mobile phones can download 1 MB below a second I reckon

mseddon19:01:22

Thanks! That was my first stop, worth knowing up front..

mseddon19:01:41

Yeah, and it can be cached and PWA'd nicely

borkdude19:01:57

how would you PWA self-hosted cljs?

mseddon19:01:33

Well. A little cljs repl that sits on the home screen. I don't think service workers would really add much other than being manditory to get there

borkdude19:01:13

@mseddon for highlighting, paren matching, etc. I used codemirror, it’s what Klipse also uses

borkdude19:01:27

there’s also a parinfer mode for it

mseddon19:01:35

Ah yea, I have all that written myself in the link above

mseddon19:01:44

Though I did it from scratch since I can perf tune it a little better. Codemirror on mobile is a bit slow on account of being quite backwards compatible

mseddon19:01:03

Parinfer is coming, but I have cljfmt compatible incremental auto indent already

mseddon19:01:33

It's rather early days yet, I am sure it is riddled with bugs :)

borkdude19:01:56

maybe something re-usable comes out of it 🙂

borkdude19:01:53

you’re doing this all in typescript?

mseddon19:01:37

Currently. A bit crazy I know but this is all so... stateful

mseddon19:01:38

Also I can see this being useful for people hosting python etc. Typescript makes it a bit more accessible

mseddon19:01:55

That said I would love to migrate it over to cljs proper in time.

lilactown19:01:06

I’m very interested in a maximally-embeddable CLJS browser REPL

lilactown19:01:39

something that handles pretty-printing, syntax highlighting, and all the fancy input problems. that I can embed in an application

borkdude19:01:08

@lilactown FWIW codemirror + parinfer plugin gets you there already?

lilactown19:01:05

I’ve played with codemirror but not sure how it handles all of the interactions one wants at a REPL yet. so maybe I’m already 80% there 🙂

lilactown19:01:45

I just think it would be cool to be able to install a single CLJS dep, setup the bootstrapping, and have an embedded REPL in a drawer or separate browser window

borkdude19:01:26

@lilactown you can already embed Klipse right?

lilactown19:01:25

klipse seems optimized for embedding within a blog-like thing. there’s a lot of work to be done to create a more terminal-repl-esque UI.

lilactown19:01:53

I’m not lamenting the lack of options for running CLJS in the browser. I’m talking about the fiddly UI problems 😉

borkdude19:01:05

you can open the browser console and maybe this chrome plugin does it already? 😉

borkdude19:01:37

would be cool on http://clojure.org or something 😉

mseddon19:01:53

Hell yeah!

dnolen19:01:13

well it would make sense on https://clojurescript.org first

👍 10
dnolen19:01:17

still waiting for takers

borkdude19:01:42

or something -> http://clojurescript.org makes sense 🙂

borkdude19:01:28

maybe Replete (iOS / Android) is easily portable to the browser @mfikes?

mfikes19:01:08

That’s what http://clojurescript.io essentially was

mfikes19:01:21

(The code in there ultimately came from Replete)

mfikes19:01:40

At least lots of it 🙂

borkdude19:01:50

why “was”, it’s not maintained? it’s actually the first time I see it

mfikes19:01:11

Oh, just speaking to the dev history

mfikes19:01:18

Not sure about current status

borkdude19:01:37

maybe it’s just finished 😉

Adrian Smith19:01:33

Is Replete available for Android now?

mfikes19:01:43

It is being developed

john21:01:27

This is pretty slick too https://jaredforsyth.com/reepl/

👍 5
john21:01:15

Neither works great in Android chrome for me though. Parinfer issues

john21:01:13

Maria.cloud is the slickest thing I've seen though

λustin f(n)23:01:38

Are there any guides on how to build Javascript npm package around a ClojureScript library?