Fork me on GitHub
#clojurescript
<
2017-11-22
>
blackawa02:11:49

Hi guys. Anyone knows how can I export module for npm from clojurescript? I am writing npm module with cljs but got stucked…

blackawa02:11:00

@jiyinyiyong Thank you for information! 😭 I had no idea to search for build tools.(I was trying with lein-cljsbuild) After searching, I found same functionality in lein-figwheel. I will use it because I am more familier to it than shadow-cljs. FYI: https://github.com/bhauman/lein-figwheel/wiki/Node.js-development-with-figwheel#nodejs-module-development-with-figwheel

Jon02:11:34

not bad. if you want to find more on shadow-cljs's side, try #shadow-cljs

sova-soars-the-sora03:11:20

Is there a modern consensus on how to handle logins and sessions with clojure/script?

sova-soars-the-sora03:11:57

Specifically, how can I make sure a login persists between browsers being connected and not ? I want to make things as uninterruptive (new words yay) as possible for someone revisiting.

sova-soars-the-sora03:11:58

Some ideas I had revolve around keeping a local hashed value and then transmitting it over the wire on new connect and de-hashing it, and verifying logins that way. Is that reasonably secure, or is there a better way?

gklijs04:11:16

@sova between browsers seems impossible, as there is no way to data at a location multiple browsers can access as far as I know. Of course you could retrieve a session after a login, so the only thing they have to do on another browser is to log in again. If all your state is in the back end, you can then just go on as before. I started my current project from https://github.com/nginx-clojure/nginx-clojure/tree/master/example-projects/clojure-web-example they use a shared map to store information in the session, but have hints to use redis so you could scale. And you need not to hook the old session to the new session when the same user logs in again. There might me better/easier solutions.

giorzio09:11:22

Hi everyone, I'm trying to configure a var at compile-time with "goog-define" but I receive the following warning:

WARNING: Use of undeclared Var job_name.core/goog-define at line 4 src/cljs/job_name/core.cljs
I also specified the var in the :compiler options:
:closure-defines {job_name.core/foo "value"} 
Anyone could help?

thheller09:11:45

@giorgio.porzio goog-define is a macro and can only be called statically

thheller09:11:10

(goog-define foo "default value")

thheller09:11:22

how are you calling it?

giorzio09:11:35

sorry I forgot to write it, I'm calling it in the same way as you did

thheller09:11:37

which CLJS version are you on? might just be an old verison?

giorzio09:11:33

ok, it was a version problem. Thank you!

foobar11:11:29

How do I call getAttributeNames on a dom node? This method cannot be found with advanced compilation

thheller11:11:26

add exterms then

thheller11:11:44

I think its not part of the standard yet do doesn’t have externs by default

thheller11:11:39

or upgrade 😉

Bravi12:11:16

is is ok to use cljs.core.async instead of re-frame for a small application?

octahedrion12:11:51

@bravilogy I've successfully used core.async with Om

octahedrion12:11:28

(Om previous)

octahedrion12:11:31

-- I had various channels in my app-state, and responded to messages with transact! Using core.async's pub-sub worked well for me

Bravi12:11:07

thanks, just what I wanted to know 🙂

octahedrion12:11:34

what it did mean was that I passed all messaging channels through to views so they could construct UI event-handlers that dispatched messages, which lead to changes in app-state (no direct coupling - all event handlers send messages like {:click :my-button} - no direct state-mutation in handlers)

octahedrion12:11:19

- that way you can associate other events with the same responses, like messages from the server, so you can drive the UI from server messages too

joshkh12:11:42

does anyone here use cljs-oops? if so, how do you work with javascript date objects? when i try (ocall (js/Date.) :getTime) i get Uncaught Oops, Unexpected object value (date-like)

darwin13:11:10

@joshkh use normal cljs interop in case of dates, it is covered by default externs, more details https://github.com/binaryage/cljs-oops/issues/13#issuecomment-332560027

darwin13:11:29

strings, dates and other standard javascript objects are guaranteed to have externs covering them (those externs are bundled with closure compiler)

joshkh13:11:31

thanks @darwin . i didn't realise there were default externs bundled with the closure compiler 🙂

joshkh13:11:23

thanks for the links/info

Matt Butler14:11:13

Hi, Is there a way to ensure/see if my externs file is being found by the closure compiler? It doesn't appear to be but I get no errors/info.

darwin14:11:46

@mbutler maybe try to introduce a syntax error into your extern file? I believe closure compiler should spit some warning at least

darwin14:11:29

this is one thing I don't like about externs btw. see what I wrote in point 4 here https://github.com/binaryage/cljs-oops#externs-from-hell

Matt Butler14:11:36

@darwin It would appear that my externs files is indeed not being read in/found 😞

Matt Butler14:11:24

Are there some good checks/obvious pitfalls?

darwin14:11:25

I don't know, once I had to modify ClojureScript compiler with some verbose logging of what is being passed into closure compiler API as parameters, my problem was that a library I was dependent on had bundled externs but it didn't seem to work

Matt Butler14:11:41

Also sorry @darwin I lied, I threw in the syntax error in dev mode casually forgetting to turn advanced compilation on... At least i can now be confident that my file is being read and the problem is my inability to write externs 😄

Matt Butler14:11:19

However, it was working, all i did was move a few files around, I dont know if that is more scary 🙂

sooheon15:11:53

I’m getting an error compiling cljs: “No reader function for tag Inf” with the newest versions of cljs, what could be causing this? I looked in the file and it’s just to do with defining infinite number literals for js

bronsa15:11:24

make sure you're on the last version of cljs and tools.reader

bronsa15:11:31

it might be that you're using an incompatible version

sooheon15:11:34

“1.9.946” is the cljs version

sooheon15:11:53

is it expected to explicitly declare tools.reader dep?

bronsa15:11:01

i believe so

bronsa15:11:10

clojurescript itself, i mean

bronsa15:11:39

do a lein deps :tree | grep tools.reader and make sure you're getting version >=1.1.0

sooheon15:11:04

Thanks, making sure that was up to date fixed the issue.

joshkh18:11:31

could someone help me understand what i'm doing wrong with the recent code splitting / :modules compiler options updates? i set up a dummy project with the following advanced compilation configuration: https://github.com/joshkh/modules/blob/master/project.clj#L45 when i compile with lein cljsbuild once min i get the following error:

------ Figwheel Configuration Error ------

Missing required key :entries at path (:cljsbuild :builds 1 :compiler :modules :cljs-base)

  {:cljsbuild
   {:builds
    [{:compiler
      {:modules
       {:cljs-base
        {:output-to "resources/public/js/compiled/app.js"
         :entries ...
         ^---- The required key :entries is missing
         }}}}]}}

------------------------------------------
But the documentation at https://clojurescript.org/reference/compiler-options#modules states that you can override the cljs_base.js file name by providing only an :output-to key

rauh18:11:26

@joshkh Figwheel version?

joshkh18:11:48

i don't think so, i'm running the very latest figwheel / clojure / clojurescript versions

joshkh18:11:30

providing the :cljs-base map with an :entries [] key/value doesn't appear to work either as suggested here: https://clojurescript.org/news/2017-07-10-code-splitting

sova-soars-the-sora18:11:32

you do not need a { before cljsbuild

joshkh18:11:55

i don't in the actual project.clj in the link. i think that's just how figwheel does its reporting 🙂

sova-soars-the-sora18:11:32

oh i did not notice you linked to the actual file 🙂

sova-soars-the-sora18:11:32

I believe you need an output-to file.js

joshkh18:11:16

good idea, let me give that a shot

thheller18:11:48

it just looks like figwheel maybe has the wrong validation for this?

thheller18:11:16

thats not a CLJS error, its figwheel

sova-soars-the-sora18:11:21

you have one in :outside {} but one needs to live inside :compiler {} according to a recent project.clj here locally

joshkh18:11:31

i think i might have been barking up the wrong tree. figwheel shouldn't have anything to do with this. it's advanced compilation.

joshkh18:11:49

sorry, red herring

thheller18:11:50

figwheel still validates the config.

sova-soars-the-sora18:11:10

yeah figwheel won't run until it's satisfied

sova-soars-the-sora18:11:22

that everything is "valid"

sova-soars-the-sora18:11:28

(is my understanding)

joshkh18:11:55

hmmm, okay, update: https://github.com/joshkh/modules/blob/master/project.clj#L45 weirdly enough my public/js/compiled directory has a bunch of files that look more like no optimisations: app.js cljs cljs_base.js cljsjs clojure goog outside outside.js process reagent re_frame work

thheller18:11:56

thats why it won’t accept [] (which CLJS is totally fine with, I think)

joshkh18:11:39

good catch thheller

joshkh18:11:22

i'll raise an issue if i confirm that i'm doing this correctly

sova-soars-the-sora18:11:45

so uh, can you just put nil there or :none ?

thheller18:11:06

the base module is kinda special, so usually it should not be allowed to be empty

thheller18:11:29

but empty entries are still fine since they “catch” common dependencies in the graph

sova-soars-the-sora18:11:42

what's the :entries line for exactly? i know nothing about advanced compilation in cljs land

joshkh18:11:33

i think maybe i'm missing something fundamental here. if i include no module descriptions and run lein cljsbuild once min i still get loads of files in js/compiled. that doesn't sound right at all for advanced optimisation.

sova-soars-the-sora18:11:30

isn't that ok though? i figured it was only the end product .js that got all the optimizations

sova-soars-the-sora18:11:58

compilers are a magical black box 😄

joshkh18:11:48

i don't think so? my other cljs projects produce a single some-app.js when i use advanced comp. what's going on here! maybe it's time for a walk. 😉

joshkh18:11:13

(or maybe those files get produced anyway but they're never loaded)

joshkh18:11:23

(maybe for source maps?)

sova-soars-the-sora18:11:34

Yeah, what role the files in the output-dir play is still a mystery to me

joshkh18:11:36

the end goal of this madness is to compile cljs based web workers into their own files

sova-soars-the-sora18:11:47

you want each webworker to have its own .js ? sounds attainable ... modules seems to be the best way to go about that so far? it's a new puzzle to me

joshkh18:11:14

if i remove the :cljs-base entirely and keep the :outside module entry then i get an app.js of 0 bytes, cljs_base.js of 234 kb, and outside.js with 160kb. anyway that's a start... thanks for the input guys. i'll keep playing around with it.

rauh18:11:36

@joshkh One workaround would be to switch off figwheels config validation. See validate-config

joshkh18:11:59

that sounds handy

joshkh18:11:31

i wish the newest module changes had a bit more documentation with practical examples. they seem to be fantastic changes and cover a lot of ground that previously separated cljsbuild from something like webpack

sova-soars-the-sora18:11:26

i think you want to give each webworker two things: base namespace that they all share in common, unique namespace that each webworker has its own code specific to it, and then specify :entries #{"namespace.unique"} and :depends-on #{"namespace.shared"}

joshkh18:11:16

i'll make a note of that for now and apply it i get a simple module example working. thanks again!

sova-soars-the-sora18:11:21

compiler comprehension is a team effort 😃

thheller18:11:28

you could try shadow-cljs where modules actually work and I have been using them since 2013 😉

joshkh19:11:34

you're not the first person to suggest that

dnolen19:11:58

@joshkh looking at the backlog I’m not really I understand what your issues is

dnolen19:11:22

the guide takes you through a complete setup https://clojurescript.org/guides/code-splitting

dnolen19:11:40

what you were referring to was the announcement which doesn’t really show you how to use it

dnolen19:11:05

still, it may be that shadow-cljs is more convenient for the WebWorker use case, but I wouldn’t know about that

thheller19:11:11

@joshkh see https://github.com/thheller/shadow-cljs/wiki/ClojureScript-for-the-browser#web-workers, just set :web-worker true for the module and the rest will be taken care of

joshkh20:11:41

@dnolen i'm very sure it's just a problem on my end - sometimes i need a little practice for things to click. i haven't spent much time playing with the compiler itself. @thheller thanks for the link. i'll play with shadow-cljs if it solves my use case, then dig more into :modules when i have some time.

johnj23:11:54

In terms on lines of code, from when would you consider using Cljs instead of JS?

vemv23:11:36

@lockdown- I'd go for cljs if it's a SPA. for the more typical "sprinkled bits of js in a server-rendered app", cljs might be overkill if you're not very familiar with it