Fork me on GitHub
#clojurescript
<
2017-02-19
>
sova-soars-the-sora02:02:15

Can I ask about some best practices in login and authentication for SPA?

sova-soars-the-sora02:02:49

I think I have a pretty good design, but I'm not sure where to take it from here.

sova-soars-the-sora02:02:23

Users login -> sends ajax request to server -> user gets back a token, on subsequent requests for special actions (send posts to the server) it uses the token to make sure it's the right user on the serverside... So that's grand and dandy... but what's a good way to persist state on the client side, cookie style?

sova-soars-the-sora02:02:05

Someone mentioned LocalStorage as a valid option, the data i'm working with is not all that sensitive and localStorage may prove to be very convenient for this.

martinklepsch06:02:24

How do I get the current namespace during macro expansion again?

anmonteiro06:02:19

@martinklepsch (-> &env :ns :name symbol)

Aron07:02:22

do you have an easy way to convert ~400MB xml (wiikiquote dump) into json? ๐Ÿ™‚ or something even better?

andrea.crotti08:02:35

Better in what sense @ashnur ?

andrea.crotti08:02:00

And it's probably easy once you define exactly what data you want

Aron08:02:22

i would like to have quotes by authors and only the quotes, nothing else

Aron08:02:53

i said better to not sound like that json is somehow necessary ๐Ÿ™‚

Aron08:02:18

because i started with js, but i realized maybe clojure people have better solutions

andrea.crotti08:02:20

Well it depends on what you are doing with the data after

andrea.crotti08:02:05

But that's the way part the parsing and getting the data as Clojure data structures is the only hard part imho

qqq08:02:36

does cljs offer weak references ?

qqq08:02:58

In particular, I'd like a cljs map where the keys are weak references, (and if they get collected, the values can vanish -- I'm fine with that)

qqq08:02:18

if not that, a cljs set with weak references would be fine too -- when gc-ed, the items just vanish from the set

thheller08:02:02

@qqq no, JS does not yet have them

qqq09:02:09

@thheller: thanks for the info

andrea.crotti09:02:29

suppose I can write some functions that make sense in both clojurescript and clojure

andrea.crotti09:02:57

is it always better to just put them in cljc files so we that I can run tests more easily with cider & co?

andrea.crotti09:02:20

would they get executed also when running clojurescript tests?

Aron09:02:16

js does have WeakMap

qqq09:02:04

@andrea.crotti: in theory yes, in practice, I found myself constantly wasting time battling #?(+clj / +cljs), dealing with different :requires and other stupid things that just slowed me down

andrea.crotti09:02:34

ah right good point

qqq09:02:15

the one advantage of *.cljc files was that it REALLY forced me to separate pure functions from DOM manipulating functions, which made things cleaner, but it the other parts were a constant battle

qqq09:02:41

support there looks pretty good, if I'm reading it correctly

andrea.crotti09:02:01

also did someone else has this sort of error running javascript tests? actual: #object[TypeError TypeError: undefined is not an object (evaluating 'frontend_cljs.core.get_final_score.call'

andrea.crotti09:02:26

it's requiring as (:require [frontend-cljs.core :as core]

thheller09:02:31

oh interesting .. last time i checked weak reference didn't work at all. guess I was wrong then

andrea.crotti09:02:33

and the functions are definitively there and working

thheller09:02:17

@andrea.crotti how do you run your tests?

andrea.crotti09:02:41

lein doo phantom test @thheller

andrea.crotti09:02:45

which did work correctly for a while

qqq09:02:55

do you have a browser-repl of some sort where you can use (in-ns ...) and explore around?

andrea.crotti09:02:56

even calling code from that module

andrea.crotti09:02:03

not sure how I messed it up

thheller09:02:21

maybe an exception while loading the file?

andrea.crotti09:02:57

uu right `frontend-cljs.core-test> (in-ns frontend-cljs.core) java.lang.UnsupportedOperationException: nth not supported on this type: Symbol `

thheller09:02:59

don't know too much about doo phantom

andrea.crotti09:02:00

ok that's why probably

thheller09:02:17

(in-ns 'frontend-cljs.core)

andrea.crotti09:02:36

ah ok yes that works

andrea.crotti09:02:50

but still thinks they are undeclared

andrea.crotti09:02:16

frontend-cljs.core> (frontend-cljs.core/count-wins 0 []) 0

andrea.crotti09:02:21

but if I call them with the full path they wokr

qqq09:02:48

@thheller: OT, how do you do the inline-pre, I only know how to use the three backticks, which causes a entire pre-div @andrea.crotti: I realize this is useless, but with cljs, especailly incremental compilation, sometimes, if I just nuke all the cached stuff it and it rebuilds everything, it just works

thheller09:02:04

just one backtick

qqq09:02:27

(+ 1 2) should output 3

qqq09:02:29

neat, thanks!

andrea.crotti09:02:21

mm wtf I commented out some stuff, then it gave the actual right error, which was a simply arity mismatch

andrea.crotti09:02:37

then I uncommented the rest of the code and it all works now

thheller09:02:28

no compiler warnings?

andrea.crotti09:02:41

not anymore, odd

thheller09:02:28

dunno if this is still true for CLJS but sometimes a cached file will not be recompiled, so warnings won't show

thheller09:02:40

try a clean build and see if there are any warnings (just in case)

wagjo10:02:51

Can we please revisit CLJS-536? Clojure added more support for namespaced keywords into reader macros, specs use them heavily, so this lossy behavior of clj->js is very surprising

pesterhazy11:02:35

Don't think we can change the default behavior, it would break existing code

pesterhazy11:02:31

(I'm not speaking for the authors of cljs of course)

thheller11:02:25

@wagjo as David mentioned in the comments. you can achieve this behavior with IEncodeJS

thheller11:02:40

(extend-type Keyword IEncodeJS (-clj->js [kw] (-> kw str (subs 1))))

pesterhazy11:02:37

that seems dangerous though as it changes the behavior of library code @thheller

pesterhazy11:02:46

not just your own

thheller11:02:12

yes, but so would changing the way it is now ๐Ÿ˜‰

pesterhazy11:02:05

the patch allows to pass {:preserve-namespace true} on a per-call basis

pesterhazy11:02:27

that seems to me the safest option

pesterhazy11:02:57

it's also in the spirit of js->clj's :keywordize-keys true

thheller11:02:36

yeah seems fair, curious though when you'd ever do clj->js->clj seems a very lossy process overall? not just for keywords

thheller11:02:14

ie. you can't tell a symbol from a keyword afterwards

thheller11:02:18

> general question to the node.js folks: did you use a template (lein/boot)? if yes, which one?

pesterhazy11:02:24

yes it's never guaranteed to be a safe round trip

wagjo12:02:35

symbols preserve their namespace when transformed with clj->js, I think we should consider the lossy keyword behavior a bug, and not as a feature which should be left supported for existing libraries.

pesterhazy12:02:56

I don't know about that. Often losing the ns is exactly what I want

wagjo12:02:08

then you would get it only for half of the identifiers, symbols would be left with their namespace. I don't see how this should be an intended behavior

pesterhazy12:02:01

symbols are used much less frequently than keywords, I'm not sure if the comparison is fair

pesterhazy12:02:25

when talking to javascript apis at least

pesterhazy12:02:35

generating JSON etc.

wagjo12:02:20

so were namespaced keywords, before spec. Current popularity of some type should be relevant.

pesterhazy12:02:45

I agree it's unfortunate that symbols and keywords behave differently btw

wagjo12:02:07

Let me give you and alternative view. clj->js is very similar to producing json object from a clojure's one. Most of json generators do keep keyword namespace, e.g. chesire https://github.com/dakrone/cheshire/blob/master/src/cheshire/generate.clj#L140 . This makes clojurescript behavior differ from a clojure, as in clojurescript world (correct me if I'm wrong), the idiomatic way to generate json is with clj->js

pesterhazy12:02:05

I don't think cheshire is representative of clojure.core

pesterhazy12:02:37

the thing is, existing code calls name and (name kw) strips the ns part

pesterhazy12:02:53

so all existing (pre-namespace) code will default to stripping namespaces

wagjo12:02:33

You were the one that used third party libraries as arguemnt against the change ๐Ÿ™‚

wagjo12:02:01

and now cheshire cannot be used as an argument for the change

pesterhazy12:02:39

my point is that you shouldn't, without a pressing need, resort to breaking existing code

pesterhazy12:02:12

but I'm in no position of authority anyway, so my opinion hardly matters

vlaaad16:02:23

Hi there! Looks like I found a bug in cljs.spec, not sure where to report it. Is it appropriate place for bug reporting?

pesterhazy16:02:07

yes I think so, and ultimately there's alsoa jira, http://dev.clojure.org/jira/browse/CLJS

fenton19:02:00

If I want to make a clojurescript library with logging that can be turned on and off easily by users of the library... Any suggestions?

darwin19:02:09

@fenton really depends on many factors, I guess, 1) you can roll your own logging subsystem as part of the library 2) try to use goog.log if you are ok with string-only logging 3) bring in some dependency, maybe timbre[1]? [1] https://github.com/ptaoussanis/timbre

fenton19:02:41

Ok, just was curious if there was some industry standard evolving. Any experience with Klang versus timbre?

darwin19:02:09

no experience, I will be rolling my own solution (not finished ATM): https://github.com/binaryage/clearcut

darwin19:02:58

the main goal is to design something with cljs-devtools in mind and also something which will allow exactly same code for clj and cljs

darwin19:02:01

I will also consider eliding logs based on some identifier (e.g. logger name) in addition to log-level filtering

richiardiandrea19:02:23

^ shaping very nicely, sorry did not have time to contribute, atm quite busy, but I am following...

darwin19:02:27

not very nicely... got sidetracked with some other tasks and havenโ€™t done any progress in more than 3 months ๐Ÿ˜ž

darwin19:02:56

but still pretty high on my TODO list ๐Ÿ™‚

michaelstalker23:02:33

Preamble: I'm sorry if this question comes up frequently. I did a little searching, but nothing came up ๐Ÿ™‚

michaelstalker23:02:52

I'd like to use JavaScript's fetch() from my ClojureScript.

michaelstalker23:02:09

This is for asynchronous HTTP requests.

michaelstalker23:02:13

Only some browsers support it, though.

michaelstalker23:02:24

Is there something like Babel for ClojureScript?

michaelstalker23:02:37

Or...am I thinking about this wrong?

michaelstalker23:02:07

I know the Google Closure library has XhrIo. Should I just be content with what Google Closure offers me?

michaelstalker23:02:27

I suppose I could just wrap some XhrIo functionality with my own fetch function.

michaelstalker23:02:51

My first thought was that it would be nice to use ES6/7 features from my ClojureScript code, and have things "just work" in all browsers via some code manipulation in the compilation process.

thheller23:02:19

FWIW XhrIo works pretty much in every browser, why use something that may not be supported

thheller23:02:28

if you really want to use fetch just use a polyfill