Fork me on GitHub
#clojurescript
<
2016-05-12
>
cjmurphy00:05:30

Here's a straightforward Reagent / reframe SO question: http://stackoverflow.com/questions/37164091/how-do-i-loop-through-a-subscribed-collection-in-re-frame-and-display-the-data-a/37168749#37168749. I've heard people say here that map is prefered to for with Reagent. Can someone tell me what it is and I'll add it in (or put your own answer obviously)? I think people know that map is better than for, but most of us glance over the technical reason for this...

fasiha00:05:04

@cjmurphy: I use map instead of for because I can never remember the syntax for the latter 😕

fasiha00:05:29

@abdullahibra: what you're asking for is a Distributed System. Which are hard. https://github.com/aphyr/distsys-class and also https://www.somethingsimilar.com/2013/01/14/notes-on-distributed-systems-for-young-bloods/ were helpful for me when getting started thinking about this kind of thing. Even now, cljs libraries like Om Next and posh are just figuring out how to do client⇔server⇔other clients transfer reliably and efficiently. You can hand-roll something simple, for sure, but in general, the problem is hard, so things like Firebase, Parse, Meteor, etc. exist and are popular (though some of those complect other concerns too).

fasiha01:05:01

@darwin: gun looks awesome

vikeri07:05:07

What is best practice in serializing js-objects to edn? I have a (goog.date.Date.) that I would like to serialize and store. With pr-str I just get "#object[Object 20160512]” which naturally fails to be parsed by cljs.reader/read-string. Seems like tagged literals is not fully supported in cljs still?

danielwoelfel07:05:18

You probably want cljs.reader/register-tag-parser!, example here: https://git.io/vrt8Q

darwin08:05:12

@vikeri: I believe one of transit’s design goals was to robustly serialize objects/data-types into EDN: https://github.com/cognitect/transit-clj

vikeri08:05:43

@danielwoelfel: Great, I’ll check it out!

vikeri08:05:46

@darwin: Spoke with @bensu and he said that transit should not be used for storage since the format/api might change.

vikeri08:05:33

@danielwoelfel: Where do I add the tag and transform the object when writing it? I don't have to traverse the data structure first and replace all occurrences of goog.date.Date right? My initial hypothesis was that pr-str would have an optional argument with serializing functions.

plexus08:05:01

@vikeri: pr uses print-method under the hood, which is a multimethod, so you can add implementations for new types

plexus08:05:33

at least that's true in Clojure, haven't tried it in Clojurescript

plexus08:05:58

seems it isn't true in Clojurescript... I can trace it down to pr-writer-impl, but it doesn't seem like there's an easy way to extend it

plexus08:05:54

or maybe there is, it seems IPrintWithWriter is a protocol you can implement

vikeri08:05:31

@plexus: Thanks! Seems the last blog post is what I want.

vikeri09:05:31

Got it working, these things ought to be better documented...

urbanslug09:05:25

@dnolen I noticed you said you don’t use loops which is all Clojure seems to offer. How do you do recursion in Clojure because it’s not very Clojure to use recursion as far as I have seen?

annarcana10:05:19

urbanslug: Recursion is done with the loop/recur form, because the compiler doesn’t otherwise do any tail call optimizations. It’s dogma not to use it in end-user code, though a lot of core functions are implemented with it.

mccraigmccraig11:05:45

anyone know how i can see output to *out* or *err* during cljs macroexpansion... it's being suppressed in my setup

risto11:05:37

@dnolen: Isn't it possible for ClojureScript to implement true TCO? From my understanding, true TCO wasn't implemented for Clojure because of the current limitations of the JVM security model. But Javascript doesn't have that kind of limitation.

urbanslug11:05:58

@jarcane: Not to use what in end user code?

fasiha11:05:13

@risto: I thought TCO was new in JS, based on things like http://www.2ality.com/2015/06/tail-call-optimization.html ?

annarcana11:05:31

The ES6 standard does call for TCO.

annarcana11:05:42

The vendors are complaining about actually implementing it though.

risto11:05:36

@fasiha: Yeah, ES6 is still pretty new and not fully implemented in browsers. Everyone is still targeting ES3 or ES5. I think ClojureScript could implement true TCO similar to how Babel has done it, and it would work for older browsers too.

annarcana12:05:36

I would love to see it happen, one way or another.

annarcana12:05:23

I know Fable, the new F#->JS compiler, does it by just compiling to ES6 and feeding that to Babel, but CLJS isn’t likely to go down that route.

lewix12:05:15

@risto what's the difference between the current TCO and the true TCO you're referring to?

fasiha12:05:14

I could feel myself getting more and more educated the more of it I read @mikethompson !

fasiha12:05:12

Fixing five criminal uses of map-indexed in views.cljs 😕

annarcana12:05:29

@lewix: Partly, I suspect he means that in most languages TCO is done for the whole program. Clojure’s is limited to the loop/recur form which IIRC just uses some local optimisation tricks to turn itself into a loop. It definitely can’t do clever stuff like mutual recursion (though I don’t think ES6 can do that either)

risto12:05:39

And yeah, it's only done using loop-recur rather than for the whole program by default

annarcana12:05:26

Kawa Scheme apparently does have full TCO but it has performance and interop consequences when enabled. http://www.gnu.org/software/kawa/Options.html#Options-for-compiling-and-optimizing

dnolen12:05:33

@risto JS does have that limitation

dnolen12:05:56

anything that isn’t uniformly implemented is never going to be under consideration

risto12:05:18

The security model? how so?

dnolen12:05:37

JS doesn’t have that

dnolen12:05:07

and no we’re not going to implement on our own, the perf hit is huge

dnolen12:05:19

and tooling integration nightmare

risto12:05:12

Couldn't the perf hit be mitigated by the closure compiler?

risto12:05:34

Well, in any case, would something in a tail call position be transpiled like that via closure?

risto12:05:56

In other words, once browsers implement TCO for JS (because of ES6), then clojurescript would get that for free

risto12:05:41

But only if the transpiled code is still in tail recursive form

dnolen12:05:52

perf hits can be mitigated with requisite amounts of free time

dnolen13:05:17

usually there are more impactful things to work on

dnolen13:05:22

TCO just isn’t that important

risto13:05:24

Yeah, that's probably true. But it does make a lot of algorithms more elegant

dnolen13:05:05

sure typical Scheme textbook algorithms, after a lot of time with Clojure, I just don’t think it really matters much other than “that’s pretty"

risto13:05:20

Yeah, Clojure can probably get away with making most non-recursive algos still completely readable. But in a lot of languages the recursive form definitely is easier to read.

tel14:05:38

is there any example of an :externs shimmed standalone library I can copy? there’s a security flaw in a current cljsjs lib and while I’ve got a PR to update it I need to move more quickly than they are

tel14:05:17

ah ah, sorry, I’m looking for how to do it with leiningen

juhoteperi14:05:26

google-maps, google-platform-js and stripe are currently packaged like that

juhoteperi14:05:54

You can also just set up deps.cljs on your app project and include extern in the project

tel14:05:43

that’s true, hm, and probably the simplest

tel14:05:50

I liked the notion of keeping deps all in one place

tel14:05:24

we’re using jitpack internally, so I can easily throw up a vendored version of the auth0 lib

tel14:05:31

but it only supports lein

xcthulhu15:05:47

@tel: I have a couple

tel15:05:16

cljsjs updated in the mean time, but I’ll keep these bookmarked

xcthulhu15:05:04

Both of these libraries required messing around with their respective upstream build pipelines, which is a no-no for the CLJSJS team. But if you're trying to rope something in and the authors didn't like using --standalone for browserify you're sort of screwed...

xcthulhu15:05:45

JavaScript fatigue at its finest.

juhoteperi15:05:30

@xcthulhu: What do you mean with "messing around with build pipelines"? I think some cljsjs packages modify some build configuration or something like that

juhoteperi15:05:32

Anyway, packaging JS libs separate from Cljsjs is fine. Makes my life easier when I don't have to maintain them.

xcthulhu15:05:31

@juhoteperi: In the case of bitauth, I have to go in to their gulp file and monkey around with their browserify command (or skip their build system all together and run browserify out of band).

xcthulhu15:05:07

In the case of SJCL, I have to pull down the clojure compiler and compile with simple optimizations, set pretty-printing to true, and wipe their comments and run their unit tests over the result to get a functional "unminified" version of their library. I wish it wasn't so but SJCL both needs the closure compiler's optimizations to be functional and also fails to write their javadoc comments in a way that doesn't make the closure compiler throw a fit.

juhoteperi15:05:06

Heh. Some JavaScript libraries are quite inconvenient to use.

xcthulhu15:05:19

In the case of bitauth, I'm ready to retire that library. An upstream dependency (elliptic.js) doesn't support advanced compilation and it's too much yak-shaving to fix.

xcthulhu15:05:15

@juhoteperi: Sadly, SJCL's bignum library is actually more functional than the google closure library's goog.math.Integer 😞

xcthulhu15:05:23

At this point I've sunk like 100 hours into this little hall of mirrors that is JS crypto libraries.

xcthulhu15:05:44

@all: What are people's thoughts on js/window.crypto.subtle ? Would a clojurescript wrapper + polyfill for legacy browsers be welcome?

xcthulhu15:05:55

I'm like 50% of the way there...

xcthulhu15:05:26

(I had one buddy say he didn't trust window.crypto.subtle...)

pataprogramming17:05:15

So I finally got my CIDER + Boot + browser-REPL setup sorted out...now have no problems getting two REPLs established, one for CLJ, one for CLJS. Thanks to everyone who offered suggestions and pointers to tutorials. I've got Reagent on the front end, and a whole lot of data on the backend I want to turn into dynamic visualizations. Any recommendations for where to look next for a good way to set up the flow?

edannenberg17:05:40

@pataprogramming: for reagent https://github.com/Day8/re-frame is probably the hot sauce currenty, i also like https://github.com/krisajenkins/petrol (watch the linked talk)

pataprogramming17:05:24

Scanning the (extensive!) re-frame README, the bit that's currently missing for me is how the data gets from the backend into the app-db ratom.

pataprogramming17:05:44

Say I've got some metrics that take a fair number of CPU cycles to crunch coming in on the backend. What are the architecture options for pushing that stream out to the CLJS side of things on the browser?

edannenberg17:05:35

whatever floats your boat really, rest, websockets.. https://github.com/ptaoussanis/sente is pretty awesome

pataprogramming17:05:57

Cool. I poked around with sente + Om a year ago, but only to get a toy scenario set up. If that's still state of the art, I'll dive back in. Thanks!

edannenberg17:05:07

if you haven't checked it out yet: https://github.com/danielsz/system makes things a breeze, atleast for the backend part

pataprogramming17:05:22

I've worked with component in the past, but not system. I think I've heard it plays nicely with Boot?

pataprogramming18:05:11

This is the first project I've converted to Boot, and I'm really liking it. Faster and lighter, and it's been really easy to stick my fingers into the pie when I needed to make some tweaks.

pataprogramming18:05:01

Any thoughts on http-kit vs Immutant? I used http-kit the last time I was playing around with sente.

xcthulhu18:05:11

@patapizza: These benchmarks are kind of old, but immutant has better performance: https://github.com/ptaoussanis/clojure-web-server-benchmarks

edannenberg18:05:54

@pataprogramming: Yea it does play very nice with boot indeed, coming from gradle boot was a no brainer as soon as i saw it. 😛 Can't comment on http-kit vs immutant, but shouldn't really matter as you can switch at any time with sente.

martinklepsch18:05:47

Does a predicate like regular-expression? exist in CLJS?

niquola18:05:50

Hi all, stupid question - is it possible to make cljsbuild faster (cache, multi-threading, etc)? It's becoming slowest part in our Continuous Delivery Pipeline 😞

borkdude18:05:16

@nicola cljs supports parallel builds

niquola18:05:33

But not - parallel build ?! We have just a couple of builds - should we split them somehow?

niquola18:05:22

thx! - let me check it

pataprogramming18:05:41

@martinklepsch:

cljs.user> (regexp? #"")
true

martinklepsch18:05:14

@pataprogramming: thanks! how did I not find this haah

fenton19:05:38

does anyone debug clojurescript apps on mobile devices? if so any suggestions?

fenton19:05:06

i.e. no console available.

dnolen19:05:14

@fenton: if it’s a web app in a mobile browser on iOS you can debug, also thought this was true for Android

dnolen19:05:46

for native, I suppose you’ll have to be OK with logging if your platform doesn’t have better JS debugging integration

dnolen19:05:30

on iOS at least with JSC logging works same as NSLog far as I know

fenton19:05:48

@dnolen what I was trying to do is serve it up with boot and the various cljs-repl, reload, etc..., then i should have all the power of a repl, cider, etc... however am having trouble using this arrangement when all devices are not the localhost.

dnolen19:05:52

@fenton: I would get this working with the simplest thing first if you’re just interested in debugging

fenton19:05:53

for example, some mobile phones dont work...for some reason, but I don't have access to the phone, but if they connect to the site....then with the above setup, theoretically, I'd be golden with a repl in their browser.

dnolen19:05:06

then add bells and whistles later

dnolen19:05:31

as far as making this work with every possible mobile phone - probably not gonna happen

fenton19:05:49

true for sure, but this development setup would be powerful... i think everything is basically there for this setup too... raised an issue with boot-cljs-repl...

dnolen19:05:54

well in my mind at least actual debugging means source mapping and stepping, you need access to the phone for that

dnolen19:05:27

spending a lot of effort to just get a REPL to some random phone doesn’t sound like it would help that much with serious debugging at least to me

fenton19:05:24

repl is usually my first stop...but perhaps you are right.

fenton19:05:15

but i dont think this needs to be setup for each different phone...it should be a generic setup for any browser connected device.

dnolen19:05:11

well also being to connect to someone else device via browser through a REPL is also a probably a pretty bad security hole so I don’t know 🙂

dnolen19:05:44

(but maybe misunderstood here)

fenton19:05:51

yes i wouldn't run in production like that!

fenton19:05:29

i'd just serve the static files...but when they aren't working i can wind up this jetty served site with all the repl connection trappings...

dnolen19:05:42

@fenton: well if this is for debug builds then I don’t see why it couldn’t be made to work

dnolen19:05:48

I don’t see why localhost would be an issue

fenton19:05:10

@dnolen. basically my setup is I'm running the site on a remote server. In the simplest case, I open up a local browser (just as a test) that is pointed to this remote server (being served by boot cljs-repl reload serve, etc...). At this point everything is fine. Then I open up a repl (either cider connected or a terminal right on the server), but (start-repl) but weasel complains, hangs... The bug i raised for it is: https://github.com/adzerk-oss/boot-cljs-repl/issues/41

fenton19:05:36

I'm pretty noob'ish on the build tools...so perhaps i'm doing something wrong...or maybe there is a bug... a bit surprised others haven't run into this tho... would make mobile development a lot easier IMO

dnolen19:05:55

@fenton: I haven’t been following the cider integration, and definitely not weasel or piggieback, I suspect you may have more luck with Figwheel

fenton19:05:20

@dnolen okay maybe I'll give that a try...

dnolen19:05:24

(I could be wrong about all of this, I only use Figwheel + Cursive myself)

juhoteperi19:05:18

@fenton: People developing for mobile platforms are small section of people writing Cljs (or using Boot) and people using browser-repl are another small section, those who use both are even smaller section

fenton19:05:32

@juhoteperi: but i think developing for mobile should be peoples first thoughts when using cljs, no? Mobile is the future right?

fenton19:05:25

@juhoteperi: but what you say is true...

dnolen19:05:08

@fenton now that I understand what you are trying to accomplish, I’ve had stuff like this working before BTW

dnolen19:05:01

I think like 3 years ago I played around with browser REPL interacting with many connected clients - desktop browser, iPad, and iPhone, and Android device browsers

dnolen19:05:32

but my advice would be stick with the simplest thing

dnolen19:05:42

forget about Cider, Weasel, etc. for now

dnolen19:05:55

just try to get Figwheel to do what you want at a terminal and go from there

fenton19:05:45

@dnolen yes, i'll give that a try, not sure conceptually if it makes sense as I haven't used figwheel for sometime now...but i guess it should?

dnolen19:05:13

@fenton: how is it any different than what you described?

dnolen19:05:27

Figwheel does other things, but it’s also a REPL

fenton19:05:57

@dnolen yes you are right... just haven't used figwheel for a while...sorry my statement was not helpful 🙂

dnolen19:05:58

I’m only suggesting it because it’s really popular and thus probably less issues, more help

fenton20:05:32

@dnolen i'll report back! thanks again! 🙂

martinklepsch21:05:59

People who have rich text editors in their app, how did you do it? 🙂 I recently stumbled upon https://github.com/bustlelabs/mobiledoc-kit and the more I'm playing with it the more I'm liking it. Draft is an alternative but mobiledoc seems much simpler

vinnyataide22:05:13

hello! What is better? react-native with a clojurescript wrapper or lein-droid package?

richiardiandrea22:05:47

@fenton At the last Clojure/West the Untangled team had a nice feature for bug reporting...a classic log of all the events up to the bug, which is not step through but very neat 🙂

fenton22:05:44

@richiardiandrea: OK I'll chat with you offline soon... Just at sailing center waiting for sailing partner! ;)