Fork me on GitHub
#clojurescript
<
2018-09-07
>
Matt Butler09:09:24

Anyone know a lightweight/good lib for doing modals in cljs (im using rum)?

borkdude10:09:08

@marcin.k.chmiel do you mean lower cased attributes?

mewa10:09:40

And dashed, like <div custom-attr />. Does it make any difference how they're spelt?

rtacconi11:09:46

is there a framework or tool to build webapps and mobile app from a single code base (using react.js)

kennytilton12:09:51

For those curious about Matrix, I discovered one more intro piece (for lifecycle stuff ala Component) was integral to the whole Matrix idea. Never really thought about it as special, but looking at Component made me realize a carveout intro was mertited: https://github.com/kennytilton/matrix/tree/master/cljs/fluxchallenge

👍 4
kennytilton12:09:10

Now mebbe I can start on some formal doc.

sulami12:09:30

@rtacconi I’ve used re-natal with some success, though it’s a bit brittle in places

rtacconi13:09:05

Thanks. So a website front-end written with reagent, could be compiled to a native/mobile app (using re-natal)?

sulami13:09:37

I don’t think 100%, but you can probably share a lot of logic

richiardiandrea14:09:01

Is there a way to get a cause of an ex-info out in cljs? Or you would usually use gobj/get ?

dnolen14:09:15

ex-info is a deftype, you can access fields

dnolen14:09:26

gobj/get won’t work under advanced compilation

richiardiandrea14:09:42

Ok so field access - no helpers like ex-data, just wanted to make sure I wasn't missing anything

richiardiandrea14:09:59

Thanks a lot as usual ;)

Ramzi15:09:27

If I have a global var in a Javascript file that is imported at the top of a Clojurescript file, how come I can't see that global var in clojurescript? It says it's not defined.

hlolli16:09:39

I need to convert uint16array to js array with js objects, basically #js ["a" "b" "c"] => #js [ #js {:value "a" :index 0} #js {:value "b" :index 1}], there's a plotter library I'm using that needs the data this way. With reduce I get the uint array is not seqable. Maybe loop is a good tool for this?

john16:09:36

areduce may work. The semantics are a bit different though

Ramzi16:09:35

How come Object.keys(jsonObj) is returning "0", "1", ..., "5", rather than the keys of the JSON object?

hlolli16:09:29

@john you should have been 2 min quickler, good to know about areduce, probably more perfomant than what I did here

(defn arraybuffer-to-data [arrbuf]
  (let [length (.-length arrbuf)]
    (loop [index   0
           out-arr []]
      (if (< index length)
        (recur (inc index)
               (conj out-arr #js {:value (aget arrbuf index)
                                  :index index}))
        (clj->js out-arr)))))

john16:09:55

You may have a js array there, which uses indexes as they keys

Ramzi16:09:13

Ugh, I was doing keys(n) rather than keys(n[i])

hlolli16:09:00

I forgot if clj->js traverses deeply or not.

john16:09:18

@hlolli probably a little more performant

john16:09:32

clj->js is the deep one

hlolli16:09:56

ok, then I grab the reader macro in the last step there. Just can't think of good conj alternetive in js, of course muteable fluff like push, which I'd avoid like fire in cljs.

john16:09:12

But if you're going from js arrays to js arrays, it'll probably be hard to beat the speed of just using some interop, instead of converting back and forth.

john16:09:05

areduce and amap don't convert things, so they'll be pretty fast. But there's plenty of native interop fns to accomplish that too

hlolli16:09:55

yes, I guess this version is bit faster

(defn arraybuffer-to-data [arrbuf]
  (let [length  (.-length arrbuf)
        out-arr #js []]
    (loop [index 0]
      (if (< index length)
        (do
          (.push out-arr #js {:value (aget arrbuf index)
                              :index index})
          (recur (inc index)))
        out-arr))))
areduce high on the list to try out

john17:09:14

@hlolli try banging on this:

(defn ab->data [ab]
   (let [na #js []]
     (areduce ab i _ na
       (.push na
         #js {:value (aget ab i) :index i}))))

hlolli17:09:49

@john doesn't bang in first try 🙂 going to debug...

hlolli17:09:32

the return value is the length of the object 😕

hlolli17:09:02

ah you just need to return the na

john17:09:07

what the

john17:09:21

Ah I pasted wrong

hlolli17:09:26

it's just javascript, the result of mutation isn't the new object state

hlolli17:09:03

now it bangs! didn't benchmark, but it's more readable !

john17:09:09

This is what worked in my repl I think

(defn ab->data [ab]
   (let [na #js []]
     (areduce ab i _ na
       (.push na
         #js {:value (aget ab i) :index i}))
     na))

👍 4
john17:09:42

There was some chatter that areduce could beat JS's native .reduce in some situations, but that was a long time ago. Not sure about these days.

richiardiandrea17:09:37

oh cool I have never seen that thank you!

johnj18:09:29

What's the output size of cljs with react and say a minimalist blog?

dnolen18:09:44

if you’re not doing that much pulling in lots of other components probably 70-80K gzipped

👍 4
deliciousowl18:09:47

clojurescript itself I think is slightly smaller than jquery (?)

deliciousowl18:09:08

saw that in a talk but that might be old/incorrect

dnolen18:09:18

well the old jQuery was ~30K

dnolen18:09:28

ClojureScript by itself is a bit smaller than that

dnolen18:09:33

but honestly given how people use React components it’s hard for me to even believe people care anything about size anymore

👍 4
dnolen18:09:20

pulling even one serious standalone React component seems to really balloon the payload

mfikes18:09:31

@john @hlolli A tidbit slower, but amap looks simpler

(amap #js [1 2] i a #js {:value (aget a i) :index i})

hlolli18:09:25

nice, thanks!

lilactown18:09:39

I am upset that I cannot convince Chrome to display an application/edn content type

✔️ 4
john18:09:19

@mfikes I do like that better

Ramzi19:09:53

How can I define global vars across Javascript and Clojurescript files?

john19:09:12

(set! js/hi "hi") and then js/hi #_=> "hi"

john19:09:39

But there's lots of ways to do it. You can do it on the JS side too, then just access it from cljs using js/hi

john19:09:52

Be mindful of name clobbering in advanced compilation though. It's sometimes safer to set with (goog.object/set obj "foo" "bar")

Ramzi19:09:05

I have a javascript file called myGrid.js. In it it has a function which is supposed to retrieve data from the database. I would like for this function to work with a variable called page, and that this variable would get set on every page that loads.

Ramzi19:09:40

But I am thinking that the grid is initialized before the page variable is set.

Ramzi19:09:19

When I define a global var in my myGrid.js file, it is undefined when I try to see it from my Clojurescript file.

john20:09:42

Yeah, I'm not sure anyone here is going to be familiar with that grid thing. But, worst case, you could build a repro of the problem you're having, put it up on youtube github (lol), and then others will have more context about what you're trying to do. If you dump too much code in the repro though, folks might not have time to review it, so if you can boil it down to the most minimal repro possible, it may get looked at.

Ramzi20:09:46

Okay thanks.

john20:09:00

90% of the time, you discover your solution just by building a minimal repro

Ramzi20:09:07

Everything was just working, and now it's not, and i dont know what changed. I tried undoing but it's not returning to a working state. 😞

Ramzi20:09:29

It's like, I'm including a js file at the top of my cljs file, but none of the printlns are coming out. When they were before. I dont know what changed.

john21:09:32

Not sure what it means to include a js file at the top of your cljs file. Could mean a number of things. For others to know, you'd either have to be pedantically specific about what you mean, or toss up a repro. Once you get more used to the environment, you'll have a better handle on what is and isn't implicit knowledge to the community.

xiongtx21:09:54

What's the reason we need a "runner" ns in cljs? https://clojurescript.org/tools/testing#running-tests We don't need that for clj doo also needs a runner ns: https://github.com/bensu/doo#plugin

john21:09:22

@xiongtx I think it's a matter of convenience. From what I understand, the latest figwheel.main actually finds your tests for you, without a runner

xiongtx21:09:48

Interesting--is there an example of that?

john21:09:33

The latest template for figwheel.main I believe comes with some test stuff pre-setup. You may find some good example material in there.

john21:09:14

You can pull in templates using the clj-new tool