Fork me on GitHub
#clojurescript
<
2017-06-01
>
joelsanchez00:06:44

Hey, hi to everyone

Tom H.00:06:17

I've been thinking of using the new https://github.com/Jarzka/stylefy in my next project, it's a wrapper around Garden for Reagent

joelsanchez00:06:21

I made a CSS modules library for cljs over the last four days (not really css modules as you will see) for my own project, I'd like to get some feedback, Daniel Compton likes it!

joelsanchez00:06:39

It seems that you were even talking about this!

joelsanchez00:06:23

fqcss can be used with plain CSS, SCSS, or Garden, and Reagent, Rum, or anything else, since it only replaces CSS in a string and provides a generic class resolution function

joelsanchez00:06:53

(I use it with reagent and scss)

joelsanchez00:06:12

So: "I'd like for there to be a CSS classname auto-gen solution that -isn't- CSS-in-JS for people who aren't into that" - This is a very generic auto-gen solution indeed

joelsanchez00:06:31

Sorry if I'm spamming this too much but it seems very relevant 🙂

joelsanchez00:06:08

I also have a "let's-improve-bidi's-complex-syntax" namespace if anyone's interested, among other things that came up during the development of a large re-frame app

mike_ananev11:06:13

hi! I'm looking for good clojurescript lib for UML-like drawing. I want to be able to draw entities and relations between them. any advice?

robert-stuttaford11:06:09

@mike1452 js interop is pretty good, and i’m sure there must be something D3.js based out there that’ll do the trick

dominicm12:06:32

@joelsanchez how does that compare with the new verbose syntax for bidi?

dominicm12:06:45

@malcolmsparks would probably take a PR to add it to bidi in it's own amespace if you wanted

pseud12:06:52

@mike1452 ClojureScript->JavaScript interop is super nice to work with, so you can use regular JS libraries without much issue. The only exercise might be in writing some wrapper code to make the API you use in the rest of your app more clojure-like - but that is entirely optional. The best CLJS->JS Interop intro I've seen is https://lambdaisland.com/episodes/clojurescript-interop If you compile code intended for the front-end, you'll likely use ":optimizations :advanced" in your CLJS compiler config, if so, everything goes through Google's Closure compiler which cuts away unused code resulting in a smaller JS bundle. If that is the case, you'll have a little work defining an "externs" file, basically clojurescript file wherein you list the functions of the js lib(s) you want the bundle to contain. Sometimes, this work is already done by others, the best place to look for "wrapped" JS libraries, that is, libraries available at clojars etc which contain these externs files already is http://cljsjs.github.io/

mike_ananev12:06:38

@pseud @robert-stuttaford thanks! mxGraph looks good from JS world.

carter.andrewj13:06:15

I'm having an issue with go-loops (which I'm using to help components communicate across the tree) - it doesn't seem like you can print to the console from within them (which is making things a nightmare to debug). Is there a workaround for this?

thheller13:06:48

@carter.andrewj logging should just work?

carter.andrewj13:06:14

Nope - tried that, nothing reaches the console

thheller13:06:26

are you sure the code gets executed? 🙂

carter.andrewj13:06:27

(But the loop actions are still occurring)

carter.andrewj13:06:44

Yeah, it's still changing things in the app state

thheller13:06:29

there really is nothing in core.async that would interfere with that

carter.andrewj13:06:49

The go loop (in question) is for analytics components to request data from a central manager - all the components are registering themselves successfully and the data is being pulled down, but then no data reaches the components

carter.andrewj13:06:27

I can print at the beginning and end of the go-loop chain, but nothing inside the individual go blocks comes out

carter.andrewj13:06:55

There's probably just a simple bug somewhere in there that's causing the data to become nil, but I can't track it down because I can't find where that's occurring

thheller13:06:58

that sounds like they are getting executed then?

carter.andrewj13:06:22

Yes, they're doing what they should - but any attempt to output to the console just doesn't appear

thheller13:06:22

can you share some code?

thheller13:06:39

did you try (js/console.log "foo") instead of printing?

carter.andrewj14:06:32

Yeah, still nothing

thheller14:06:44

yeah your code isn’t getting executed the way you think

carter.andrewj14:06:01

So the map there executes fine

carter.andrewj14:06:24

The state isn't updating properly (which is what I'm trying to diagnose) and the print doesn't do anything

thheller14:06:47

there is no recur in there

carter.andrewj14:06:52

The recur is lower down

carter.andrewj14:06:03

There are different when statements

carter.andrewj14:06:20

The (recur) hits at the end

thheller14:06:41

{:keys [:register :refresh :deregister :kill]} that should be symbols not keywords

thheller14:06:50

{:keys [register refresh deregister kill]}

carter.andrewj14:06:51

Multiple components register themselves successfully with the 'update-query!' call, so I can confirm it's executing

carter.andrewj14:06:29

Both are valid and work - I'd been informed that specifying the mapping with keywords told the compiler to use keywords for access, which is quicker

thheller14:06:57

that is wrong

carter.andrewj14:06:27

Well I've no idea if it's any more efficient or not, but those two lines above both work

thheller14:06:07

if you print directly as the first thing in the when-let?

thheller14:06:45

;; Register new views there or so?

carter.andrewj14:06:26

Prints at the start, but then not again

carter.andrewj14:06:42

Same whether its inside out outside of the when-let

thheller14:06:54

so no more messages arrive?

carter.andrewj14:06:50

Not from that print statement

thheller14:06:11

just trust me that the print is not the issue here

thheller14:06:59

you should try to reduce the code in the go-loop anyways, its doing way too much stuff that doesn’t need to be async

thheller14:06:07

should make things much easier to debug as well

captainlexington14:06:48

I tried to make a project in Elm. Their union types aren't polymorphic. I'm sorry I ever doubted you, ClojureScript ❤️

michaellindon15:06:33

@captainlexington @dnolen , in case you are still interested in the (take 100 (take-nth 10 (iterate update-fn initial-state))) discussion from yesterday. I rolled my own function

(defn take-thin [take thin transition initial-state]
  (loop [iter 0
         acc '()
         acclen 0
         state initial-state]
    (if (= take acclen)
      acc
      (if (zero? (mod iter thin))
        (recur (inc iter) (conj acc state) (inc acclen) (transition state))
        (recur (inc iter) acc acclen (transition state))))))
and it appears the garbage collector is kicking in from time to time

michaellindon15:06:15

for basic example, the following agree

(take-thin 10 15 inc 1)
(take 10 (take-nth 15 (iterate inc 1)))
just the new function seems to allow the garbage collector to free up heap space for me

michaellindon15:06:33

this is all ive been able to come up with 🙂

josesanch18:06:07

Hi everybody. Anyone knows why this is not working?

thheller18:06:13

(dom/getWindow) there is no :require for dom

thheller18:06:23

also dont use that namespace 😛

josesanch18:06:44

When when I use (.addEventListener js/window "scroll" scroll-fn) works, but is not working with advanced compilation. I can see Uncaught Error: [object Event] is not ISeqable. I don't know why. If i turn on peudo-names to see where is the problem works again.

thheller18:06:23

sounds like missing externs although those are standard

josesanch18:06:27

Sorry I miss the (:require [goog.dom :as dom]) in the snippet, but is in my code

thheller18:06:40

are you sure that its that line?

josesanch18:06:49

Yes, I think so. Because, if I turn pseudo names or change the compilation mode works

thheller18:06:17

pseudo-names shouldn’t fix that case

thheller18:06:41

are you sure the error is in that exact line and not something else?

josesanch18:06:58

Yes, I know but It works. Is the only diference

josesanch18:06:46

I'm using 1.9.562

thheller18:06:56

:advanced will rename unknown things, :pseudo-names will rename it as well, just give it different names

thheller18:06:15

so if it were to rename (.addEventListener js/window "scroll" scroll-fn) anything in here

thheller18:06:27

it would have no effect

josesanch18:06:43

Yes, I know. I've use other times to resolve externs problemfs

thheller18:06:47

since nothing in that calls something that checks ISeqable

thheller18:06:57

so the issue is somewhere else

thheller18:06:15

as I said .. sounds like missing externs

thheller18:06:24

but not for those calls, something else

thheller18:06:45

I’d say run shadow-cljs --check but you are probably not using that 😛

josesanch18:06:01

And regarding the snippet, using clojure.browser.event. Why is not working

josesanch18:06:38

No, sorry. I know is yours. But, I haven't use it before.

josesanch18:06:56

However, I could try it.

thheller18:06:11

the problem could be that you are missing some externs

thheller18:06:31

and the generated code uses a variable that is shouldn’t

thheller18:06:40

which is then replaced by something else in your page

thheller18:06:47

prime example is google analytics without externs

thheller18:06:17

since that creates a variable but the :advanced output frequently produces a ga

josesanch18:06:23

The iseqable error happens only when I scroll

josesanch18:06:36

and scroll-fn is

thheller18:06:48

so your scroll-fn has the bug?

josesanch18:06:19

I don't use externs there

thheller18:06:30

how do you use on-scroll?

thheller18:06:36

{:keys [position node multiplier]} doesnt work if that is called by the native event handler

josesanch18:06:50

I'm pasting the complete code

josesanch18:06:25

Is a parallax component for images

josesanch18:06:49

It works perfectly in simple, but in advanced I have that problem

thheller18:06:50

(.addEventListener js/window "scroll" scroll-fn) needs to be missing something

thheller18:06:28

there is an extra arg in scroll-fn, it will only get e

thheller18:06:44

which isn ISeqable and the map desctructure will fail

thheller18:06:05

weird that it only fails in :advanced though?

josesanch18:06:17

scroll-fn is a partial

josesanch18:06:28

has a first argument

thheller18:06:29

oh yeah sorry I’m blind

thheller18:06:25

I need a break 😛

josesanch18:06:29

It's very weird. That is why I'm asking.

thheller18:06:42

I’m still blaming externs

josesanch18:06:01

@thheller Thank you very much. I'm going to try different clojurescript versions

thheller18:06:29

unlikely that that would change something?

josesanch18:06:14

Probably not! 😝

josesanch18:06:16

with 1.9.293 is the same

thheller18:06:15

do you have any non CLJS JS in your page? anything external at all?

josesanch18:06:11

the site is complex

thheller18:06:12

do you have externs for that?

josesanch18:06:26

not for the parallax

josesanch18:06:44

Have some externs

josesanch18:06:50

For other things

josesanch18:06:56

the parallax code is the new one

josesanch18:06:50

No error without the line ;; _ (.addEventListener js/window "scroll" scroll-fn) in advanced compilation. So, should be that. The thing is that I don't know why.

thheller18:06:00

well the error is in scroll fn and that doesn’t get called then

thheller18:06:51

I’d love to know if --check would find the error but probably too much work just to test

josesanch18:06:55

I'm going to learn a little bit about shadow-cljs. I'll report you later

thheller19:06:21

you could try with source maps as well

joelsanchez20:06:07

@dominicm Tried to mimic Angular's routes, a little bit

joelsanchez20:06:20

The focus is readability.

dominicm20:06:48

joelsanchez: Do you nest at all?

joelsanchez20:06:29

The routes are nested using their names

joelsanchez20:06:34

{:route :backend :name "Administración" :url "admin/"} {:route :backend.users :name "Usuarios" :url "users/"}

joelsanchez20:06:44

The second route has this url:

joelsanchez20:06:57

I find it very convenient!

joelsanchez20:06:58

I'll generate those routes for you to see

joelsanchez20:06:12

cljs.user=> routes ["/" {"admin/" {"" :backend, "users/" {"" :backend.users, [:id "/edit"] {"" :backend.users.edit}}, "login/" {"" :backend.login}, "register/" {"" :backend.register}, "playground/" {"" :backend.playground}}, "" {"" :frontend, "/index" {"" :frontend.index}, ["/product/" :id] {"" :frontend.product}}, true {"" :not-found}}] cljs.user=>

joelsanchez20:06:09

Sorry I do not know how to send core

joelsanchez20:06:32

I see, what do you think? You find it useful? Is it worth publishing it or something? Idk

dominicm20:06:58

I've pinged it over to bidi maintainer for you 🙂 I think it's a novel approach. Worth having out there. People have issues with bidi's syntax.

puzzler20:06:50

Quick naive question: If I want to deliver a clojurescript program to a customer using node.js, will the js output of clojurescript's compiler suffice, or is there an additional step required to "package" the javascript in some way for node.js?

darwin20:06:41

depends on your customer, if they are able to install node and run it from command-line with your javascript as an argument you don’t have to package it

puzzler20:06:21

In Clojure, "lein deploy clojars" lets you deploy something for public consumption. "lein uberjar" lets you build a jar to deliver to a customer who is not running Clojure. What are the equivalents in node.js world? Most of the npm docs I've found seem to be more about consuming modules and publishing for the public, rather than creating a private module for a single user, so I'm not sure what to search on to find the right kind of docs (or if it's even needed).

thheller20:06:24

@puzzler if you do anything above :none you should just a get a single file

thheller20:06:41

that should run standalone

thheller20:06:02

only gets complicated if you use npm packages 😛

thheller20:06:40

you can also npm pack something and the client can npm install the-packed.tgz

josesanch20:06:36

@thheller I found it. It was cljsjs.raven (sentry client). But don't ask me why.

samcf23:06:59

any hints on creating a custom writer for cljs.pprint/pprint? for example I'd like to write the pretty string using document.write

darwin23:06:18

@samcf with-out-str is not good enough?

joelsanchez23:06:20

+1: cljs.user=> (with-out-str (cljs.pprint/pprint {:a 1})) "{:a 1}\n"

samcf23:06:53

ah that should work then, thank you

joelsanchez23:06:07

wondering if out is a thing in cljs

joelsanchez23:06:06

nevermind: (core/defmacro with-out-str [& body] `(let [sb# (js/goog.string.StringBuffer.)] (binding [cljs.core/print-newline true cljs.core/print-fn (fn [x#] (.append sb# x#))] ~@body) (cljs.core/str sb#)))

joelsanchez23:06:42

looking at that maybe you could bind print-fn to document.write