Fork me on GitHub

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


that seems like it should work


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


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


@qqq, there are several libraries that try to detect the device based off the user agent like, but it’s usually preferable to do feature detection


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)


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


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


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)))


@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.


Is rum support hiccup style on ReactiveNative? -


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?


@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


@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


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


@hlolli lots of differences


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


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?


@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.


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?


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.


(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.)


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


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?


@plins why would you use figwheel instead of cljsbuild ?


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)


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


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


@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


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


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


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


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?


@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


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


the cljs does the websocket stuff


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


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


well, the websocket can be https if nothing else


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


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


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


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)


yeah looking at that now


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


never mind, I was reading that wrong


Between "dev" and "devcards"


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)


just a theory


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


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.


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.


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.


@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


Perhaps some downstream tools automatically load namespaces like that?


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


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


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


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.


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)


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


but I’d need to test that assumption


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


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


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


(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.)


that’s great to know about


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?


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


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


You can run tests directly in that REPL.


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


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


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


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


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


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


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


awesome, I do in fact have clj


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


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


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


By the way, the reason you can start the Node REPL this way is via (no magic)


cljs.repl.nashorn also works


Yes, I have ClojureScript in deps.edn:

  {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"}}}


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


nice - thanks a lot


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


yes, that is truly my dream


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
     // component generation logic)

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