Fork me on GitHub
#clojurescript
<
2017-10-19
>
psdp00:10:29

Hi, just wonder how to properly configure cljsbuild to handle loading of external libs which have non-js assets like stylesheets. I'm getting this parse error: ERROR: JSC_PARSE_ERROR. Parse error. primary expression expected at /home/me/cljs-test/node_modules/m-react-splitters/lib/splitters.css line 1 : 1

iku00088800:10:31

@darwin Thanks! Seems like adding tools.reader as a deps was an okay solution for my case then 🙂

val_waeselynck07:10:18

Is (.log js/console ...) supported in a ClojureScript environments? (including bootstrapped CLJS, Planck, Lumo, etc). I'm in a situation where I can't use println and the likes.

myxomatozis07:10:58

@val_waeselynck Sure, you can use it instead of prn println.

vemv09:10:41

what's the trick to get source maps working with advanced optimizations?

vemv09:10:58

I follow https://clojurescript.org/reference/source-maps precisely, but Chrome will give me this:

vemv09:10:46

it's "detected" but not applied

miikka10:10:48

Have you enabled it in the Chrome settings?

miikka10:10:10

Well, I guess you have if you have followed those instructions

vemv10:10:30

yes. I see source maps working with :optimizations :none

alpox11:10:10

Hey all! I tried to import a library (https://github.com/fulcrologic/semantic-ui-wrapper) into an om.next project. My file is a cljc file, not a cljs so i run into the error: >Could not locate fulcrologic/semantic_ui/factories__init.class or fulcrologic/semantic_ui/factories.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name. When i try to use reader conditionals like:

#?(:cljs [fulcrologic.semantic-ui.factories :as f])
    #?(:cljs [fulcrologic.semantic-ui.icons :as i])
I get the error >java.lang.RuntimeException: No such namespace: f Because it still looks for the namespace on clj side. Is dere a way to use this library in cljc anyway?

Arno Rossouw11:10:44

Will adding more cpu's to a server decrease load average?

val_waeselynck11:10:13

@arno what's your definition of "load average"? On the typical web server, adding more CPUs can reduce latency, but probably only marginal affect memory usage.

alpox11:10:17

Actually I managed to use the semantic-ui library now - but i needed an additional reader conditional around each semantic ui element on the page. So my next question would be if there is a way around having to use the reader conditional for every usage of a semantic-ui element

msolli12:10:23

Extract the functions that use js-only stuff into separate .cljs namespace, and implement .clj namespace with the same name that has only dummy versions of the same functions.

msolli12:10:57

Then include the namespace from your .cljc namespace.

msolli12:10:09

For instance, in foo.cljs:

(ns foo
  (:require [goog.object :as o]))

(defn oset!
  [obj k v]
  (o/set obj k v))
And in foo.clj:
(ns foo)

(declare oset!)
From bar.cljc you can now require foo and use oset! without a reader conditional.

msolli12:10:25

@alpox Does this make any sense? I’ve managed to remove much boilerplate reader conditionals using this pattern.

alpox12:10:15

@U06BEJGKD That sounds itself like a lot of boilerplate though. Wouldn’t the library have to do that instead of me for every function in the library?

msolli12:10:39

Well, yes, I agree, but you provide the boilerplate only once, in one place, for your third-party library. In your consuming components there is absolutely no boilerplate.

alpox13:10:42

Hmm so for each function in the library i’d have to make a single entry in two files each?

Arno Rossouw11:10:14

@val like, on linux server uptime, load average

Arno Rossouw11:10:41

by how much can adding more cpu reduce latency?

val_waeselynck12:10:53

There just is no generic answer to that, I'm afraid. Try first to determine wether your workload is CPU-bound, memory-bound, or IO-bound (for most web servers, it's the 3rd option).

lovuikeng12:10:31

@alpox you might want to try om channels #om #om-next

alpox12:10:39

@lovuikeng I don’t think the problem is connected to om

abp12:10:24

Hi, I have created an issue with proposal and a question for my first ClojureScipt patch, maybe someone with knowledge about how node.js specifics are implemented can give me feedback https://dev.clojure.org/jira/browse/CLJS-2386

dnolen13:10:53

@abp I would take it to #cljs-dev, more people hack on the compiler there

abp13:10:12

@dnolen ah ok thank you

tobowers15:10:22

I’m trying to use the buffer npm package from clojurescript and I’m getting a really strange error in .toString(‘base64’) where it’s returing NaN and undefined instead of the actual base64… ‘hex’ is working though… really hard to track that down

tobowers15:10:52

dev-frontend:cljs.user=> (require '[buffer :refer [Buffer]])
nil
dev-frontend:cljs.user=> (new Buffer "0")
#object[Object 0]
dev-frontend:cljs.user=> (.toString (new Buffer "0") "base64")
"undefinedundefined=="
dev-frontend:cljs.user=> 

tobowers16:10:00

well - it’s from a lower-level requirement…

(require '[base64-js :as b64])
nil
dev-frontend:cljs.user=> (.fromByteArray b64 (new js/Uint8Array [0 1]))
"undefinedundefinedundefined="

tobowers16:10:29

how does one even start to debug that in cljs?

pesterhazy16:10:49

this may be neither here nor there but CLJS comes with goog.crypt.base64

tobowers16:10:32

@pesterhazy that’s probably a good call as a workaround

tobowers16:10:43

that bugginess has me worried though 🙂

pesterhazy16:10:53

I'd try it from the node.js repl first (in JS), then lumo

tobowers16:10:50

node works…

> var b64 = require('base64-js');
undefined
> new Uint8Array([0,1])
Uint8Array [ 0, 1 ]
> b64.fromByteArray(new Uint8Array([0,1]))
'AAE='

tobowers16:10:36

lumo works too

cljs.user=> (require '[base64-js :as b64])
nil
cljs.user=> b64
#js {:byteLength #object[byteLength],
     :toByteArray #object[toByteArray],
     :fromByteArray #object[fromByteArray]}
cljs.user=> (.fromByteArray b64 (new js/Uint8Array )) 1]
"AAE="

tobowers16:10:15

this is confusing though…

(goog.crypt.base64.encodeString (new js/Uint8Array [0 1]) false)
"MCwx"

tobowers16:10:24

non-deterministic b64?

dnolen16:10:35

does goog.crypt.base64 take Uint8Array?

tobowers16:10:38

oh because it expects a astring and not a uint8array

tobowers16:10:47

@dnolen yeah… good catch

dnolen16:10:04

Closure Libary generally doesn’t really on newer features

dnolen16:10:13

they need to support a very broad heterogenous set of JS clients

tobowers16:10:33

yeah so a binary string I guess

abs-zero16:10:09

(defonce cref (r/atom nil))
(defn home-page []
  (r/create-class
    {:component-did-mount 
     (println "mounted" @cref)  ; nil

     :component-did-update
     (println "updated" @cref)  ; nil
     
     :reagent-render
      (fn []
        [:div {:style {:display "flex"
                       :justify-content "center"
                       :flex-flow "column"}}
          [:h2 {:style {:text-align "center"}}
              "Welcome to GAME OF LIFE"]
          [:canvas {:height 450
                    :width 450 
                    :style {:border "1px solid black"}
                    :ref (fn [el] 
                          (do
                            (reset! cref el)
                            (println "nooo" @cref)))}]])}))
how do I access dom ref? I am getting nil in component-did-mount

pesterhazy16:10:46

where do you define cref?

pesterhazy16:10:22

also it should be #(println ...). rookie mistake! 🙂

seako22:10:50

why should it be #(println …) ?

pesterhazy09:10:59

fn call v creating an anonymous fn

abs-zero16:10:48

(defonce cref (r/atom nil)) it's at the top.. sorry didn't post it edited now

abs-zero16:10:57

i feel stupid now 😅

pesterhazy16:10:50

it happens to the best of us