This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-08
Channels
- # aleph (4)
- # beginners (5)
- # cljs-dev (21)
- # clojure (155)
- # clojure-dev (3)
- # clojure-italy (10)
- # clojure-losangeles (3)
- # clojure-nl (2)
- # clojure-russia (5)
- # clojure-spec (42)
- # clojure-uk (11)
- # clojurescript (170)
- # code-art (1)
- # component (3)
- # core-async (28)
- # cursive (70)
- # data-science (3)
- # datascript (1)
- # datomic (28)
- # emacs (6)
- # gorilla (1)
- # graphql (2)
- # jobs (1)
- # lein-figwheel (4)
- # lumo (7)
- # off-topic (13)
- # om (63)
- # parinfer (66)
- # planck (1)
- # re-frame (22)
- # reagent (2)
- # ring-swagger (53)
- # rum (3)
- # sql (13)
- # test-check (2)
- # unrepl (48)
- # vim (8)
- # yada (33)
but actually, for something like a NodeList, there's likely a utility somewhere that already does this...
yeah, I was thinking there would be a utility.
Any suggestions on anything that I could read further to understand this process a little better?
@tkjone did you see this? https://github.com/lynaghk/c2/issues/43
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
I see what they are doing
(extend-type js/NodeList
ISeqable
(-seq [array] (array-seq array 0))
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)
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
@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
you’ll have to convert cljs collections of child nodes into JS arrays before passing them to Preact
@symfrog I cannot reproduce the problem with the first repo from yesterday - React loads fine, no errors
@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
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
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
@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 ?
fwiw, other people have tried this feature with foreign-libs React and nothing has been reported
@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
@symfrog found the issue, https://dev.clojure.org/jira/browse/CLJS-2310 thanks
Still looking for a custom JSON serialization method that doesn’t require a consumer to know transit. Is there such a thing?
@alex-dixon what are your requirements?
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.
@alex-dixon as long you don’t use the more complex features, I don’t see the problem with Transit
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?
@alex-dixon I think that would be the only issue, but to me if you want JSON why bother keywords anyway
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
What helped was to give up on kebabization and to use string keys rather than keywords
It's not too painful because you can use {:strs [abc]}
and just replace keyword calls with get
good rule of thumb, if you want speed, stop creating pointless marshalling steps just to make things “easy”
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
@pesterhazy fwiw, you could probably use Transit verbose JSON reading
To do that you'd have to use gobj/get
instead of get
, and you can't assoc/update etc.
@dnolen, interesting. We'd need to update the Golang api for that
Hadn’t considered the key encoding issue really. Thanks for pointing that out
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?
that's fantastic... and not a very widely known fact
fair point
I'm going to give this a try and report back
@pesterhazy I’m not following “The produce(r?) doesn’t have to be transit-aware”
You can just consume any kind of JSON using the transit reader - it doesn't have to be JSON-encoded transit.
(Unless you have weird keys starting with a tilde character, which you most likely do not)
At that point is it just leveraging MessagePack or something?
:thinking_face:
But…point being faster reads from any valid JSON minus tildeized keys with transit reader
not MessagePack, no
not sure why the transit reader is so much faster than JSON.parse+js->clj
Is it because it produces less garbage? Shouldn't JSON.parse be pretty much optimal?
Frustrating that CLJ/CLJS doesn’t rule the world sometimes
js->clj could be made faster of course, but since Transit solves a more general problem - it’s not really worth the effort
(->> raw JSON.parse js->clj count time), 1000 runs, 5445 msecs
(->> raw (cognitect.transit/read rdr) count time), 1000 runs, 2683 msecs
transit/read
is significantly faster
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
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
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))))})
dosync
ref
if they existed would only be for portability - if somebody wants to provide a patch for that, would be welcome
@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 🙂
@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)))))
@jeremys you may! I'm always interested in the best and better way to do things 🙂 after all, i just arrived and am learning 😄
@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))
@reefersleep I didn't see that i can use multiple associations 😄 thanks for that
Enlightenment about the threading macros is essential, though, so I find @jeremys example and mine complementary 🙂
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
?
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.
well, I´ll log into the system, click some menus and verify the result into web element
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.
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.
You can simply use the native java api to interact with a wd, though, from clojure — but it’s not simple
☝️ worth a try 🙂
Also take a look at etaoin
. It works with PhantomJS and headless Chrome among others
@alpox @reefersleep of course assoc is way better there!
(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>
@lilactown you cannot possibly have blocking functionality available in javascript
this is a solid answer: https://stackoverflow.com/questions/21400464/cant-seem-to-require-or-in-clojurescript
javascript has only a single thread, you cannot block it, this is not going to change anytime soon 🙂
mm. sure, I can imagine now that it would be incredibly awkward to emit code that replicated that behavior.
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@lvh shouldn’t the . before toUTCIsoString be a / ?
I’m thinking static method syntax
maybe those things don’t work like static methods though
@noisesmith FWIW I just tried it and it broke saying that’s not a ns
so these things work
(cmd)dev:cljs.user=> (.-length (.-prototype js/String))
0
(ins)dev:cljs.user=> (.-length "foo")
3
and
(ins)dev:cljs.user=> (.charAt "foo" 1)
"o"
(ins)dev:cljs.user=> (.charAt (.-prototype js/String) 1)
""
I think you just access the item on the thing and ignore the prototype? I could be misunderstanding your issue
cljs.user=> (js/Date.prototype.toISOString.apply (js/Date.))
"2017-08-08T22:59:17.973Z"
cross post from emacs: does anyone here use emacs and have a preferred html/css mode?
figured its worth asking here since i only find myself in html when working on cljs things