Fork me on GitHub
#clojurescript
<
2017-08-08
>
noisesmith00:08:28

but actually, for something like a NodeList, there's likely a utility somewhere that already does this...

athomasoriginal00:08:56

yeah, I was thinking there would be a utility.

athomasoriginal00:08:04

Any suggestions on anything that I could read further to understand this process a little better?

athomasoriginal00:08:19

I quickly reviewed, but I am so new to clojure that some of it goes over my head lol. I will read through more carefully

athomasoriginal00:08:26

I see what they are doing

athomasoriginal00:08:43

(extend-type js/NodeList
    ISeqable
    (-seq [array] (array-seq array 0))

deadghost10:08:15

how's cljs for the backend?

deadghost10:08:43

I want to put up a simple site without the ram consumption of the jvm

noisesmith16:08:13

if you avoid lib bloat, it’s easy to run clojure / ring and stay under 128 megs ram usage, and node won’t do much better than that (with less stability and performance due to being single threaded to boot)

mathieu11:08:18

as a following to my question yesterday, I got Preact working without framework; posted the simplest example here: https://github.com/mathieulegrand/Preact-with-ClojureScript-and-no-framework – will be trying to make it look cooler now

roman01la11:08:13

@mathieu I’ve been playing with Preact+CLJS a while ago, unfortunately Preact doesn’t support ES6 Iterable protocol that is used in ClojureScript to iterate over data structures, which doesn’t allow to render collections of components easily

roman01la11:08:28

you’ll have to convert cljs collections of child nodes into JS arrays before passing them to Preact

dnolen12:08:32

@symfrog I cannot reproduce the problem with the first repo from yesterday - React loads fine, no errors

symfrog12:08:20

@dnolen It fails silently to load the module, the error can be seen in Chrome when "Pause on caught exceptions" is ticked under Sources in Chrome DevTools

dnolen12:08:33

@symfrog I don’t see this

dnolen12:08:37

React loads fine

dnolen12:08:43

it’s there and I can reference it

dnolen12:08:51

I tried many different thing - no issues

dnolen12:08:09

I will add this was one of the very first things I tested when I developed :modules

symfrog12:08:19

odd, I get the issue on a clean clone with Chrome 60.0.3112.90, will see if there are other environments I can reproduce it on

dnolen12:08:28

if you mean you only see the error when you click Pause on caught exceptions

dnolen12:08:34

then I don’t see how that’s relevant

dnolen12:08:43

how the loading Closure module machinery works is not our concern

dnolen12:08:35

I’m on Chrome 60.0.3112.90 OS X

symfrog12:08:50

Same environment on my side, I can see the module manager failing to load the module and attempting retries, so the module is failing to load, might be something else specific to my environment, will continue to look

symfrog12:08:29

@dnolen On my side the issue also occurs on Safari (10.1.2) and Firefox (55.0), is this the repo you are using https://github.com/symfrog/cljs-modules-react ?

dnolen12:08:46

@symfrog I cloned your repo

dnolen12:08:54

and I don’t really have any more time to look at this

dnolen12:08:04

I’m now looking at the order bug

symfrog12:08:46

ok, thanks for checking, I will continue to check for something specific on my side

dnolen12:08:05

fwiw, other people have tried this feature with foreign-libs React and nothing has been reported

dnolen12:08:21

it’s not to say that there isn’t an issue but it’s hard to know what’s going on

symfrog12:08:25

I have found it only occurs when using optimizations :none

dnolen12:08:30

it would preferable that you can repro with something more minimal

dnolen12:08:41

@symfrog people are testing with all the optimization settings

dnolen12:08:47

including myself

dnolen12:08:01

by more minimal - I mean make something w/o Lein

dnolen12:08:10

React is not relevant here

symfrog12:08:16

ok, will do

dnolen12:08:26

Quick Start Uberjar is the only thing you should be using

dnolen12:08:35

@symfrog I do see the foreign-lib order issue

dnolen12:08:57

not a show-stopper for this case, since nothing breaks

dnolen12:08:13

but looking into fixing this since this would affect other libs

symfrog12:08:23

@dnolen fwiw, React is available for the first issue, but the module manager considers the module to have failed to load and the module loaded callback is not called, the module manager invokes the error handler

symfrog12:08:57

If the module loaded successfully, you should see "Module B init" in the console

dnolen12:08:46

right this is the kind of information that should be in the repo

dnolen12:08:52

otherwise I spend a lot of time

symfrog12:08:23

yes, sorry, should have added that

symfrog13:08:23

great, thanks

alex-dixon13:08:44

Still looking for a custom JSON serialization method that doesn’t require a consumer to know transit. Is there such a thing?

pesterhazy13:08:22

@alex-dixon what are your requirements?

alex-dixon13:08:46

Fast as possible. Publicly consumable as possible. Convertible to EDN. Data may contain compiled Clojurescript functions, so I’d like to test for that and supply a map with information about the function instead of the default #object reader tag that is generated for them.

dnolen13:08:34

@alex-dixon as long you don’t use the more complex features, I don’t see the problem with Transit

dnolen13:08:38

there’s a verbose mode

alex-dixon13:08:17

Looking here https://github.com/cognitect/transit-cljs/wiki/Getting-Started#writing I thought the "~:some-keyword" was transit-y. I guess I could deal with it but is there an option to stringify keywords without the tilde?

dnolen13:08:34

@alex-dixon I think that would be the only issue, but to me if you want JSON why bother keywords anyway

dnolen13:08:46

there’s nothing particularly idiomatic about kebab case

pesterhazy13:08:12

we've recently had significant performance problems relating to consuming JSON. We did these steps: - JSON.parse - js->clj - turn string keys into keywords - kebabize-keywords That turns out to be really slow

pesterhazy13:08:18

What helped was to give up on kebabization and to use string keys rather than keywords

pesterhazy13:08:48

It's not too painful because you can use {:strs [abc]} and just replace keyword calls with get

dnolen13:08:22

good rule of thumb, if you want speed, stop creating pointless marshalling steps just to make things “easy”

pesterhazy13:08:32

However we did not remove the js->clj step although that is a performance bottleneck. The reason we kept it was that working with mutable data structures is more painful

dnolen13:08:44

@pesterhazy fwiw, you could probably use Transit verbose JSON reading

pesterhazy13:08:47

To do that you'd have to use gobj/get instead of get, and you can't assoc/update etc.

dnolen13:08:58

I suspect at least an order of magnitude faster to marshal than js->clj

pesterhazy13:08:50

@dnolen, interesting. We'd need to update the Golang api for that

alex-dixon14:08:09

Hadn’t considered the key encoding issue really. Thanks for pointing that out

pesterhazy14:08:56

Oh wait, reading the blog post... does Transit's verbose mode work with any JSON? That is, the produce doesn't have to be transit-aware?

dnolen14:08:45

modulo collision, i.e. some JSON value starts with “~CHAR…”

pesterhazy14:08:51

that's fantastic... and not a very widely known fact

dnolen14:08:03

well I did mention it 3 years ago 🙂

pesterhazy14:08:02

I'm going to give this a try and report back

alex-dixon14:08:36

@pesterhazy I’m not following “The produce(r?) doesn’t have to be transit-aware”

pesterhazy14:08:11

You can just consume any kind of JSON using the transit reader - it doesn't have to be JSON-encoded transit.

pesterhazy14:08:54

(Unless you have weird keys starting with a tilde character, which you most likely do not)

alex-dixon14:08:15

At that point is it just leveraging MessagePack or something?

alex-dixon14:08:54

:thinking_face:

alex-dixon14:08:12

But…point being faster reads from any valid JSON minus tildeized keys with transit reader

pesterhazy14:08:24

not MessagePack, no

pesterhazy14:08:40

not sure why the transit reader is so much faster than JSON.parse+js->clj

pesterhazy14:08:04

Is it because it produces less garbage? Shouldn't JSON.parse be pretty much optimal?

dnolen14:08:03

JSON.parse is fast, js->clj is not

alex-dixon14:08:47

Frustrating that CLJ/CLJS doesn’t rule the world sometimes

sfalcon14:08:18

so much yes

dnolen14:08:19

js->clj could be made faster of course, but since Transit solves a more general problem - it’s not really worth the effort

pesterhazy14:08:53

(->> raw JSON.parse js->clj count time), 1000 runs, 5445 msecs
(->> raw (cognitect.transit/read rdr) count time), 1000 runs, 2683 msecs

pesterhazy14:08:09

transit/read is significantly faster

jeremys15:08:08

Hey guys, using the new npm integration I started integrating the new google material components https://github.com/material-components/material-components-web to react using clojurescript. It is still a prototype but who knows, someone might be interested in playing with what I got right now and give me some feedback. You can find the code here https://github.com/JeremS/material-cljs cheers

alpox16:08:36

Hi all! I just started with clojure/clojurescript and run into the issue of: >WARNING: Use of undeclared Var om-tutorial.core/dosync at line 117 /home/elias/Testing/om-tutorial/src/cljs/om-tutorial/core.cljs When trying to use dosync. I cannot find any reference on how i should import that - it pretty much looks to me like it should be imported by default, so i wonder why i get this warning

alpox16:08:46

For reference, here is the code in which i try to use it:

(defmulti mutate om/dispatch)
(defmethod mutate 'board/evolve
  [{:keys [state] :as env} _ _]
  {:action
   (let [temp-board (:temp-board state)
         new-board (evolve (:board state) temp-board)]
     (dosync
      (swap! state assoc-in [:board] new-board)
      (swap! state assoc-in [:temp-board] (generate-temp-board new-board))))})

dnolen16:08:26

@alpox dosync doesn’t exist in ClojureScript

alpox16:08:53

@dnolen Ahh, thanks, that explains a lot 😄 does one just use do instead?

dnolen16:08:21

JavaScript is just single threaded, there’s no need for dosync

dnolen16:08:53

dosync ref if they existed would only be for portability - if somebody wants to provide a patch for that, would be welcome

alpox16:08:35

@dnolen i was thinking about that but then again i don't know how clojure/clojurescript works below and what exactly these functions do in the end. Many thanks for the clarification 🙂

dnolen16:08:27

@alpox if you have om specific questions you might want to ask in the #om channel

alpox16:08:56

@dnolen :thumbsup: thanks again

jeremys16:08:23

@alpox If I may you might also want to update your state in a single swap! if you want the update to be atomic. I won’t really matter in clojurescript since javascript is single threaded but it might in clojure. You might do it like this

(swap! state #(-> % 
                    (assoc-in [:board] new-board)
                    (assoc-in [:temp-board] (generate-temp-board new-board)))))

alpox16:08:34

@jeremys you may! I'm always interested in the best and better way to do things 🙂 after all, i just arrived and am learning 😄

alpox16:08:50

Thanks for the suggestion, i will gladly use this

reefersleep17:08:00

@alpox @jeremys I think for the purposes of assoc‘ing several values into a structure, you can just use assoc - that is, if your path is only one level deep.

(swap! state assoc :board new-board
                   :temp-board (generate-temp-board new-board))

alpox17:08:42

@reefersleep I didn't see that i can use multiple associations 😄 thanks for that

reefersleep17:08:07

Enlightenment about the threading macros is essential, though, so I find @jeremys example and mine complementary 🙂

fabrao17:08:08

Hello all, any suggestion for web app functional testing tool? I need to validate some states of external website and I want to do it automated with clojure. Do you think is it a good choice using clj-webdriver and PhantomJS?

lwhorton18:08:54

funny you should mention - i’m working on a tool that does exactly that which should be done in a few weeks. if you can wait lmk and I’ll ping you when it’s available. otherwise - depends on your needs. do you need a real browser to hit the external site? if that’s the case selenium is pretty much the only answer.

fabrao18:08:30

hello, I don´t need a browser, I only need to verify the result of an opertation

lwhorton18:08:06

what kind of operation?

lwhorton18:08:48

phantomjs/casper/(a few others) simulate the browser api for functional tests

fabrao18:08:08

well, I´ll log into the system, click some menus and verify the result into web element

fabrao18:08:33

phantomjs is pretty, but I used it with clj-webdriver, that is UNMAINTAINED now

fabrao18:08:03

so, is that the best option for that?

fabrao18:08:26

are you building something like selenium?

lwhorton18:08:58

if you take a closer look at clj-webdriver you can see that it’s just wrapping Java apis (selenium). PhantomJS is different - it’s all in-memory, headless. I’m not so sure you can use it to interact with an external site, such as logging in.

lwhorton18:08:12

Webdriver is the selenium (java) package that interacts directly with various browser APIs. It’s pretty hairy. There are lots of simplified apis that wrap driver in a different language, or try to simplify the driver’s api. http://webdriver.io/ for example.

lwhorton18:08:37

You can simply use the native java api to interact with a wd, though, from clojure — but it’s not simple

peterschwarz20:08:28

☝️ worth a try 🙂

fabrao21:08:02

thanks guys

metametadata14:08:15

Also take a look at etaoin. It works with PhantomJS and headless Chrome among others

jeremys19:08:05

@alpox @reefersleep of course assoc is way better there!

lilactown21:08:33

i'm trying to import the blocking pipeline to my clojurescript REPL

lilactown21:08:05

(require '[cljs.core.async :refer [<!!]])
----  Could not Analyze  <cljs form>   line:1  column:1  ----

  Invalid :refer, var cljs.core.async/<!! does not exist at line 1 <cljs repl>

darwin21:08:14

@lilactown you cannot possibly have blocking functionality available in javascript

lilactown21:08:27

ah, gotcha 😕

darwin21:08:36

this is probably well documented somewhere 🙂

lilactown21:08:01

i honestly am struggling to find documentation for cljs.core.async

lilactown21:08:34

yeah, I saw that but wasn't sure if things had changed since 2014

darwin21:08:05

javascript has only a single thread, you cannot block it, this is not going to change anytime soon 🙂

lilactown21:08:38

mm. sure, I can imagine now that it would be incredibly awkward to emit code that replicated that behavior.

lilactown21:08:13

I just wish there was a way that I could do psuedo-blocking stuff in the REPL

lilactown21:08:58

nbd. thanks for the response 🙂

shzhng22:08:51

what is the correct way to include scoped packages with :npm-deps?

lvh22:08:24

How do I call a method definition on a prototype? I’ve tried

(goog.date.Date.prototype.toUTCIsoString (new DateTime))
(apply goog.date.Date.prototype.toUTCIsoString [(new DateTime)])
… but neither works correctly:
TypeError: this.getUTCFullYear is not a function
    at goog.date.Date.toUTCIsoString (/.cljs_node_repl/goog/date/date.js:1234:10)
.. I know about this-as but I don’t think that’s what I want here

noisesmith22:08:29

@lvh shouldn’t the . before toUTCIsoString be a / ?

lvh22:08:14

goog.date.Date.prototype isn’t a namespace so I don’t think so

noisesmith22:08:33

I’m thinking static method syntax

lvh22:08:38

also goog.date.Date.prototype.toUTCIsoString evals to a fn as you’d expect

noisesmith22:08:41

maybe those things don’t work like static methods though

lvh22:08:03

@noisesmith FWIW I just tried it and it broke saying that’s not a ns

noisesmith22:08:20

so these things work

(cmd)dev:cljs.user=> (.-length (.-prototype js/String))
0
(ins)dev:cljs.user=> (.-length "foo")
3

noisesmith22:08:52

and

(ins)dev:cljs.user=> (.charAt "foo" 1)
"o"
(ins)dev:cljs.user=> (.charAt (.-prototype js/String) 1)
""

noisesmith22:08:17

I think you just access the item on the thing and ignore the prototype? I could be misunderstanding your issue

sundarj22:08:55

you need to set the this via .call .apply or .bind

sundarj22:08:46

cljs.user=> (js/Date.prototype.toISOString.apply (js/Date.))
"2017-08-08T22:59:17.973Z"

lvh23:08:04

ah; I did apply instead of .apply. Derp. Thanks sundarj 🙂

scaturr23:08:04

cross post from emacs: does anyone here use emacs and have a preferred html/css mode?

scaturr23:08:22

figured its worth asking here since i only find myself in html when working on cljs things

qqq23:08:02

I tend to use garden for css, and hiccup for html, then everything stays in clojure mode. 🙂 I do have an extra index.html that is hand written, but I almost never change it.

scaturr23:08:09

fair enough!

scaturr23:08:17

i did just stumble upon web-mode

scaturr23:08:31

but i suspect i won’t touch html that often either