Fork me on GitHub
#clojurescript
<
2015-06-23
>
coyotespike01:06:52

@edbond @sveri @rauh @andrewmcveigh - many thanks for generously helping me sort through CSRF - I understand the mechanism much better now!

coyotespike01:06:51

I'm now working on implementation. Here's a gist with the method "put the token in the page template, then grab and POST on client side." https://gist.github.com/anonymous/99f176f41aff7b9977b7

coyotespike01:06:30

And here's my attempted implementation of the method "GET and then POST the CSRF token": https://gist.github.com/anonymous/27302db67a819eb36292

coyotespike01:06:11

Any comments/suggestions greatly appreciated

aengelberg06:06:12

I'm getting a compile error when trying to compile the following code:

(defn number->hex-padded [n]
  (if (<= n 0xFFF)
    (.substr (str "0000" (.toString n 16)) -4)
    (.toString n 16)))

aengelberg06:06:42

Caused by: clojure.lang.ExceptionInfo: Unknown dot form of (. nil toString nil) with classification
[:cljs.analyzer/error :cljs.analyzer/symbol ()] at line 522 src\cljs\instaparse\gll.cljs {:file "src
\\cljs\\instaparse\\gll.cljs", :line 522, :column 3, :tag :cljs/analysis-error}

aengelberg06:06:36

In the REPL that code works just fine.

aengelberg06:06:49

Nvm, false alarm.

rui.yang10:06:55

what's the relation between om and om next? will om next make om deprecate?

martinklepsch10:06:57

@rui.yang: No. Om will continue to exist and I think David said he wants to provide a migration path from one to the other.

Petrus Theron11:06:01

@arohner: make sure your table content is inside [:tbody] in your [:table]

escherize11:06:18

@arohner: I have an example of a hiccup table with tbody (and thead) over at http://hiccup.space

meow16:06:06

Is there a reason why

do
isn't included on http://cljs.info/cheatsheet/?

bocaj16:06:59

What is involved to get clojurescript running within PostgreSQL using PL/v8 ?

nullptr16:06:11

pkobrien: can't answer that question but IMO would be worth adding

nullptr16:06:46

it's something i use pretty often in practice, more than a lot of stuff in the existing cheat sheet

dnolen16:06:21

bocaj: sounds like more trouble than it's worth since you have to parse/eval the entire standard library to do anything

meow16:06:20

@nullptr: yeah, I was kind of surprised it wasn't there

meow17:06:49

I'm having a hard time remembering swap! versus reset! Is that just a familiarity thing or are those terms commonly used elsewhere? (I guess that's more of a newbie question.)

akiva17:06:32

Familiarity, I suspect. I just look at the verb in this case: one for another vs. start from scratch.

coyotespike17:06:23

@rauh: thanks, that's a very clear explanation!

meow17:06:45

If one were creating a very thin wrapper over some functions in a js library, like Google Closure, what are the tradeoffs between these two forms?

(defn get-document []
  (dom/getDocument))

(def get-document-b dom/getDocument)

roberto17:06:29

the first one is executing dom/getDocument

roberto17:06:39

the second one is creating an alias for dom/getDocument

meow17:06:06

from the caller's point of view the same result is returned

roberto17:06:26

i don’t think so

roberto17:06:07

remember, when you enclose a fn with (), then it is executing it

roberto17:06:18

for example, translating this to JS:

roberto17:06:53

the first one is equivalent to this:

function getDocument() { 
    return getDocument()
}

roberto17:06:12

the first one is equivalent to this:

var getDocumentB = getDocument;

roberto17:06:02

you probably wanted the first one to be:

function getDocument() {
    return getDocumuent;
}

teslanick17:06:55

This is more confusing since you're using camelcased names in your JS transliteration, which causes a naming collision.

roberto17:06:18

yeah, was just trying to explain what happens when you enclose a fn in ()

roberto17:06:26

wasn’t meant as a literal translation

meow17:06:25

@roberto: unless I've lost my mind, the code I posted works - its powering an app running in my browser right now

meow17:06:30

I was just wondering about the difference between wrapping a js function inside a cljs function vs aliasing the same function when you don't need to modify any of the input arguments or output values.

mfikes17:06:41

Is @meow's 2nd form referred to as “point-free” in the Clojure community?

roberto17:06:10

also, the 2nd form could be ‘more performant’, because you are doing one less function call.

meow17:06:38

And the alias has the naming convention of cljs

roberto17:06:53

i prefer the 2nd form, because it communicates its meaning a little clearer.

akiva17:06:09

I prefer the 2nd as well. I’d go with the first only if I had to do some pre-processing first.

meow17:06:32

Then the question is how far one can take this when the js function has multiple optional arguments and so forth

andrea.crotti17:06:25

is there a way to get auto completion in the "lein figwheel" repl?

roberto17:06:25

it shouldn’t need any extra code, unless you want to do some pre-processing.

akiva17:06:33

I don’t think the alias cares.

nullptr17:06:35

gcc advanced compilation would probably inline that, negating the performance argument

meow17:06:37

@mfikes: I haven't come across that term yet.

mfikes17:06:07

@meow: I encountered it in Haskell. Just wandering what people call it in the Clojure community. Perhaps the same…

meow17:06:42

Most of these functions benefit from argument mangling so they need to be wrapped. I'm just trying to keep things to a bare minimum. I'm trying to wrap the parts of Google Closure that I'm using in my app and that I've seen others use. But I want to keep this simple and only wrap the most common and most basic stuff.

meow17:06:36

Anything more than that would be a rabbit hole with no bottom...

dnolen17:06:48

@meow: the second form loses out on ClojureScript fn validation if your intention is to provide an idiomatic interface.

dnolen17:06:56

that said I think both are kinda useless

dnolen17:06:16

just use the Closure thing directly. Wrapping stuff is not idiomatic in Clojure(Script) unless you are adding significant value.

meow17:06:18

If this were python I could load up that namespace and then change all the names on the fly, but it isn't...

dnolen17:06:00

the only time I ever feel any need to wrap Closure is when dealing with core.async since you have to lift callbacks into channel ops

meow17:06:55

@dnolen: I hear what you are saying. Some of my examples have come from your code as well. Some isn't Closure but just simple things like (defn now [] (js/Date.))

meow17:06:40

I'm just gathering up the basics to keep things DRY in my code.

meow17:06:29

I have no intention of wrapping any large part of Closure.

dnolen17:06:44

right little helpers, I tend to write these as I go. Even then I would prefer the first over the second and I would probably write out the signature so I get some compile time validation.

dnolen17:06:04

multi-arity fns don't inline as well, but it's kinda of a moot point given the inlining done at the VM level.

meow17:06:49

Yeah, most of what I have are little helpers like

(defn get-viewport-width []
  (.-width (dom/getViewportSize)))

dnolen17:06:58

right I would prefer this style in nearly every case

dnolen17:06:16

one day we might get JS usage validation, but it's a ways off yet

meow17:06:06

I was toying with supporting synonyms since there aren't always canonical names for some stuff because people have been exposed to various frameworks, so I have some code like

(def by-id get-element)

(def find-by-id get-element)

(def get-element-by-id get-element)
I assume that's okay, though debatable as to whether or not there should be support for synonyms like this or just a single name.

dnolen17:06:37

I still wouldn't do that

dnolen17:06:49

aliasing like that can mess with dead code elimination

dnolen17:06:59

you would have to double check, but I know the other way works

dnolen17:06:14

if all you're trying to do is save some keystrokes one word ...

dnolen17:06:20

M-A-C-R-O-S

meow17:06:49

@dnolen: You've given me more to consider. Thanks. simple_smile

arohner18:06:14

In Om, are there any requirements that app-state be e.g. serializable? Can I stick a fn in appstate?

sander18:06:20

arohner: you could even put om components in app-state

arohner18:06:34

I was hoping to do just that

noprompt19:06:06

whenever i do something like (def my-alias-to some-other-function) i make sure to add the arglists meta data too it as part of my practice.

(def ^{:arglists '([n])} double (comp inc inc))

noprompt19:06:06

for people using emacs or something which can display that information it's very helpful.

noprompt19:06:31

it's worthwhile to do that for multifns too.

shriphani19:06:43

hi. how do I check if a method exists in clojurescript ?

shriphani19:06:07

method of an object actually.

shriphani19:06:21

In js I can do obj.method and it is usually undefined.

noprompt20:06:36

(and (not (nil? obj)) (ifn? (.-method obj)))

noprompt20:06:11

something like that perhaps.

shriphani20:06:57

yeah that works….

shriphani20:06:07

damn, js is cray

meow20:06:00

@noprompt: ty for the arglists tip

meow20:06:47

@noprompt: I made a list of projects that I want to look into for use on my cljs apps and 4 out of 6 of them were yours: ankha, clairvoyant, phalanges, and shodan (and I already use garden, of course) simple_smile

noprompt20:06:47

@meow: thanks! hope they're helpful. let me know if you have problems.

bmay22:06:46

any recommendations for a real-time graph on a web application? i'm thinking clojure -> clojurescript (via aleph) -> javascript (d3.js)

owyn23:06:15

@bmay for real time graphing, you can check out http://riemann.io/dashboard.html