Fork me on GitHub
#clojurescript
<
2017-12-06
>
sova-soars-the-sora01:12:09

Hello everyone, is there a reason (log .js/console "message") wouldn't work in cljs?

phronmophobic02:12:04

that seems like it should work

phronmophobic02:12:20

I always put (enable-console-print!) somewhere so I don’t have to worry about it

qqq06:12:39

what's a good way to detect if device is tablet / what type of tablet it is

phronmophobic06:12:10

@qqq, there are several libraries that try to detect the device based off the user agent like http://hgoebl.github.io/mobile-detect.js/, but it’s usually preferable to do feature detection

phronmophobic06:12:57

ie. if you want to do something for touch devices, then try to detect if it’s a touch device (some laptops and desktops have touch screens)

phronmophobic06:12:15

if you want to do something based off screen size, then check the screen size

Niclas09:12:31

Does anybody have experience in testing if a mocked out function was called with certain arguments in ClojureScript?

noisesmith18:12:30

with clojure / clojurescript stubbing tends to work out better than mocking. That said, a simple reliable test is to make an atom - so a rough pseudo-code:

(deftest foo-test
  (let [invocations (atom [])
       foo-fn (fn [& args] (swap! invocations conj args) (do-real-foo args))]
    (invoke-foo foo-fn)))

peeb09:12:49

@sova if you have (enable-console-print!) set in your cljs source somewhere, then you can just use (prn message) to print to the console, also.

netpyoung10:12:34

Is rum support hiccup style on ReactiveNative? - https://github.com/tonsky/rum/issues/155

hlolli12:12:08

I may have asked this question long ago, is there effectively any difference from clojure.core/format and goog.string/format, that must be the reason why format isn't available in the cljs core api?

peeb12:12:30

@hlolli not sure, I tend to use cuerdas to avoid the confusion. I'd suspect the Google Closure format has a different API to the Clojure core one, though

hlolli12:12:00

@peeb I think that's true, but still surprising since google closure is a java library, that they wouldn't try to follow java standard. Maybe it has to do with more types being in java

fbielejec14:12:13

Can I use goog.fs.FileWriter on the brower side?

dnolen14:12:55

@hlolli lots of differences

dnolen14:12:26

but that aside, goog.string/format defeats DCE, and its use is discouraged by Google Closure Library devs themselves

hlolli14:12:48

yeh requireing it is painful enough... Is it theoretically possible to make make format function that does the same in cljs as clj and ship it in future cljs releases?

hlolli14:12:16

@fbielejec yes, I believe I used it some time ago when downloading musical samples that I played in the browser. The fs is just the browser sources instead of os file system. You can prompt the user to save it I guess.

jacekschae14:12:44

is anyone aware of cljs service-workers (not web-workers) library? If not can anybody point me to any resource how to write a cljs library?

jcr17:12:16

I'm using figwheel+cider, and for some reason everything cljs-related in emacs works very slowly. E.g. if I reindent the whole buffer, it takes about a second or two. agressive-indent-mode is not usable too due to the lag. What could be the cause? I remember I didn't have that behavior in older versions of cider\figwheel\something else.

jcr17:12:55

(Also, slightly off-topic: I'm working around this by using emacs' excellent narrowing features; but is there a way to show an outline of the buffer while I'm narrowed in? I've tried "minimap", but it minimaps the narrowed content, not the whole buffer.)

bru18:12:56

yay, managed to pull in a custom prism syntax highlighting from clojurescript. sorry for the noise, had to celebrate

plins19:12:33

hello everyone, im trying to write a ssh file which generates and deploys a fat jar.. but lein figwheel min waits for someone to connect to the figwheel server, is there a way to prevent this?

noisesmith19:12:36

@plins why would you use figwheel instead of cljsbuild ?

plins19:12:40

should I use cljsbuild for production an figwheel is dev only? my first front end project (also my first cljs project sorry for the stupid question)

noisesmith19:12:48

@plins that’s my understanding, figwheel uses the cljsbuild config - it may even use cljsbuild itself

noisesmith19:12:20

in my experience figwheel gets all confused if I do any optimizations too

noisesmith19:12:46

@plins still not certain if figwheel just uses cljsbuild vs. knowing how to use its config, but the project.clj for the figwheel template definitely mentions you should use cljsbuild for deployment https://github.com/bhauman/figwheel-template/blob/master/src/leiningen/new/figwheel/project.clj#L56

plins20:12:59

found it linked on the issues 🙂 thank you! guess i should read the docs more carefully

sova-soars-the-sora20:12:29

realtime web communications question: does it make sense to do logins over web sockets?

sova-soars-the-sora20:12:44

are there some glaring security holes i am not savvy to ?

grzm21:12:27

When switching between builds in figwheel, in one case my dev/cljs/user.cljs file is getting loaded, and in another, it's not. :source-paths includes the file in both. Any ideas why?

noisesmith21:12:35

@sova I use normal login, then redirect to my app on success - that way I can avoid sending any cljs to the client if they have not authed

noisesmith21:12:07

which - I guess that’s a small thing but it adds peace of mind that even if the compiled cljs reveals stuff only logged in people see it

noisesmith21:12:33

the cljs does the websocket stuff

noisesmith21:12:29

@grzm intuitively I wouldn’t expect my dev/cljs/user.cljs to be loaded in an optimized build

sova-soars-the-sora21:12:31

Ah, that makes sense, part of my application is meant to be public/world-facing without login, but part is meant to be log-in-to-participate, i think it can all be done over sockets, but i don't want to send any sensitive data unencrypted over the wire if possible

noisesmith21:12:53

well, the websocket can be https if nothing else

grzm21:12:09

Makes sense. However, in this case, both have :optimizations :none

sova-soars-the-sora21:12:36

yeah, https (wws://) probably just as good then... thanks man

noisesmith21:12:41

@grzm - oh that’s weird, maybe a caching bug - do they have different files with the same namespace name?

grzm21:12:40

Interesting thought. The cljs/user.cljs file is the same file in both builds (`src/dev/cljs/user.cljs`) (By the way, the project.clj file is included in that gist I shared above)

noisesmith21:12:57

yeah looking at that now

noisesmith21:12:46

@grzm so is this a difference between :dev and :test ?

noisesmith21:12:25

never mind, I was reading that wrong

grzm21:12:27

Between "dev" and "devcards"

noisesmith21:12:44

so what if “dev” loads cljs.user because that is the main ns, and “devcards” doesn’t because there’s nothing that actually pulls that code in (which maybe does something implicit without being explicitly called)

noisesmith21:12:46

just a theory

noisesmith21:12:43

I’m vaguely aware that cljs.user should be auto-loaded if found but I’ve never been able to make that happen myself

grzm21:12:59

Thought of that, too. But trying again: I've now added a no-op function and included it in the :on-jsload. Still same behavior. Unless that's getting optimized away somehow, which it shouldn't, I'd think, given the optimization setting.

grzm21:12:48

And yeah, there's some kind of magic going on there, with respect to getting cljs.user to load. It's not obvious to me what it is.

grzm21:12:19

Interesting. That ticket makes me think it shouldn't be loading it at all. Yet it clearly is in the "dev" build. The ticket doesn't have a whole lot of additional info in it.

noisesmith21:12:35

@mfikes oh wow for some reason I expected that to be happening and figured I was doing something wrong - glad to get confirmation it was an issue on the tool side

mfikes21:12:01

Perhaps some downstream tools automatically load namespaces like that?

grzm21:12:34

Then again, in my case it's being explicitly loaded in :source-paths

mfikes21:12:21

Perhaps CLJS-2298 is about loading a user namespace (as opposed to cljs.user), but maybe that's a typo.

grzm21:12:10

I wouldn't be surprised if it's figwheel. There's been issues relating to figwheel special-casing certain namespaces in the past, IIRC.

grzm21:12:46

btw, what tools do people use for searching source code? github's search is just awful for anything that's not a contiguous alphanumeric string. I end up cloning a lot of repos just so I can ack it locally.

grzm21:12:25

Well, there is a difference with the namespace being on the classpath and it actually being loaded into the repl, right? Or, maybe that's not the case in ClojureScript: the files need to be compiled to be available, and once they're compiled, they're part of the overall JavaScript object representing the repl environment, right? (Corrections welcome, particularly with respect to terminology)

noisesmith21:12:45

I think cljs (at least under figwheel) is happy to compile files on demand as you require them

noisesmith21:12:52

but I’d need to test that assumption

noisesmith21:12:14

I just created a brand new ns and it loaded via require (but not automatically just by existing)

noisesmith21:12:09

nope, figwheel definitely loaded that ns just because it was on the classpath

noisesmith21:12:20

tested via putting (set! (.-foo js/window) "bar") at the top level of my ns

mfikes22:12:48

(I found this out because if you, say, (require '[clojure.spec.test.alpha :as st]) (so you can instrument, etc.), then if you save a change to the file you are in-ns'd inside of, it will blow away the st alias, and :autoload false lets you get back to conventional REPL dev—useful for defining "lib"ish part of your codebase that heavily use Spec.)

noisesmith22:12:23

that’s great to know about

noisesmith22:12:04

also, since I have you here, what’s your recommended way to work on a cljs lib - I’ve been running lein install then restarting my app that uses the lib but there must be something more elegant that doesn’t require making a dumb little app inside my lib right?

noisesmith22:12:47

with clojure I can just fire up a repl or use lein test but I don’t know how to do things that simply in cljs

mfikes22:12:07

Yeah, I would consider running a Node REPL and just interacting with your lib in that REPL

mfikes22:12:24

You can run tests directly in that REPL.

noisesmith22:12:27

cool - is there a resource that shows a simple example of doing that?

mfikes22:12:34

I suppose if you want, you could use doo or something more complciated

noisesmith22:12:55

I’d go for node and use that repl by preference

mfikes22:12:32

Yeah, lets say your project is in src and you have cljs.jar locally, then you can java -cp src:cljs.jar -m cljs.repl.node and then you will be in a node REPL

mfikes22:12:04

Otherwise, the trick will be "where is the ClojureScript compiler JAR", depending on your setup

noisesmith22:12:06

ahh - I keep cljs.jar in my ~/bin and I can totally do that (as long as my lib doesn’t have other deps…)

mfikes22:12:39

In fact, if you have the new clj tool installed, clj -m cljs.repl.node is as simple as it gets 🙂

noisesmith22:12:58

awesome, I do in fact have clj

mfikes22:12:22

I suspect you can mess with a project-local deps.edn to put your source on the classpath. :thinking_face:

noisesmith22:12:20

ahh looks like in order to do that with clj I also need to explicitly add cljs to my config (either global or local)

noisesmith22:12:31

makes sense to put cljs in my global config, I use it enough

mfikes22:12:59

By the way, the reason you can start the Node REPL this way is via https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/repl/node.clj#L233-L234 (no magic)

mfikes22:12:23

cljs.repl.nashorn also works

mfikes22:12:27

Yes, I have ClojureScript in deps.edn:

{:deps
  {org.clojure/clojure {:mvn/version "1.9.0-RC2"}
   org.clojure/clojurescript {:mvn/version "1.9.946"}
   ,,,
   org.clojure/test.check {:mvn/version "0.9.0"}}}

mfikes22:12:59

I keep that in ~/.clojure/deps.edn

noisesmith22:12:43

nice - thanks a lot

mfikes22:12:17

No problem. With this setup, developing a ClojureScript lib can easily be done using "old school" REPL techniques 🙂

noisesmith22:12:33

yes, that is truly my dream

athomasoriginal23:12:08

Lets say I have a function that returns a component - think reagent or anything like that. What is the preference in CLJS about the parameters for said function. For example, lets say my component creates a list-item. This list-item always requires title , date and description which one of the following would you opt for?

(defn list-item
     [title date description]
     // component generation logic)

(defn list-item
     [item]
     // component generation logic)

;; item  is a a map like this: { :title x :date x :description x  }