Fork me on GitHub
#clojurescript
<
2016-12-19
>
nikki06:12:57

hey all -- quick q if i say (let [[x val]] ...) and val is like a compile-time constant would it optimize out the construction of the obj to once (when func defined) rather than many (each time it's called)?

chrisoakman06:12:07

@nikki You can always check the JS output to see what is produced. I suspect that the GClosure Compiler would decide whether or not to make that optimization if a value were a compile-time constant. Advanced Mode compilations are pretty smart and crazy efficient.

nikki07:12:55

@chrisoakman: interesting -- i was wondering if there are more optimizations available when you are equipped with clojure's semantics since you know some stuff is "immutable" or such

cmal07:12:26

Hi, are there any articles about this in reagent? I am using d3 in reagent, and want to convert the Javascript d3.select(this) to ClojureScript. How can I do this? Thanks! I am doing the cljs version of line 84 of this: http://codepen.io/zyzy5730/pen/JKkWQO?editors=0110 .

chrisoakman07:12:04

@cmal I believe this-as is the preferred way to access JS this in CLJS: http://cljs.github.io/api/cljs.core/this-as

cmal07:12:16

Ah, Thank you very much @chrisoakman

Jon08:12:28

We created a WeChat group for ClojureScript. if you are interested, check out in #clojure-china 🙂

cmal08:12:34

@mikethompson Hi, I've read those articles and not found they talked about d3.select(this). I've tried this, reagent/current-component, (reagent/argv this) and (this-as this ...) . None of them seems to work. I am still trying to find out how this can be done

curlyfry08:12:56

@cmal In the article, you can see that for example :component-did-mount is associated with a function with comp as its argument. I think that might be the this you are looking for.

curlyfry08:12:25

Or perhaps (reagent/dom-node comp)

borkdude09:12:27

@chrisoakman it’s a nice namespace to read through btw, goog.functions

cmal09:12:40

@curlyfry yeah, those assumes that this is an reagent component or an argument passed to (fn...), but in d3 when use .on("mouseover", function(){ d3.select(this)...}, this refers to an svg node which triggers an event, maybe a rect or a group or something else.

borkdude09:12:48

Has anyone here had a good experience with chromex (developing chrome extensions in clojurescript)? Is it possible to use the REPL/hot code reloading for testing the plugin? That would be a benefit to me over plain JS

danielstockton10:12:08

Are there any resources for seeing how to localize a cljs app using google closure's i18n tools?

curlyfry11:12:28

@cmal: Sorry, I'm not very familiar with d3 so I don't think I can help you further

cmal11:12:30

@curlyfry ok, thanks. I think I must open a stackoverflow question for this.

thheller11:12:14

@cmal the this d3 expects is a DOM/SVG node, those are naturally "hidden" by React/reagent

thheller11:12:32

best way to access it is probably via a :ref

thheller11:12:41

I do not know how refs are handled in reagent though

cmal12:12:46

@thheller Thank you for your help.

martinklepsch12:12:44

Is there a performance difference between defrecord and deftype for function invocations?

gfredericks12:12:25

though I didn't realize this was the clojurescript room when I answered, so I'm a bit less confident now

thheller13:12:45

@martinklepsch no, defrecord is basically deftype with some added sugar

tankthinks13:12:56

has anyone done om/reagent with web components, e.g. https://x-tag.github.io/?

tankthinks13:12:38

I asked this question a few days ago but didn’t stick around to see if anyone answered … sorry for the repeat

darwin13:12:13

@borkdude Dirac could be an example of a non-trivial chrome extension built with chromex, figwheel works[1] for me as expected, with one exception: hot reloading does not work for content scripts, but that is a chrome security limitation, not a problem of chromex or figwheel. Also chromex-sample project is already setup to work with figwheel[2]. For me the most important feature of chromex is core.async. Almost all extension apis are asynchronous, so writing plain javascript leads to the callback hell, unless you use promises or similar mechanism in modern javascript. [1] https://github.com/binaryage/dirac/blob/40e21166c741eae9d550a74ea95b2670c76bddf9/project.clj#L473 [2] https://github.com/binaryage/chromex-sample/blob/207cd1a1b5103a614d225c2eb620764a58deec89/project.clj#L30

borkdude14:12:33

@darwin thanks 🙂

bcbradley14:12:56

hey guys i'm currently experimenting with clojure and clojurescript, I've got a really basic server with ring jetty and compojure. Currently every endpoint serves basic html files. I'd rather have a root route "/" that serves html over http (that refers to javascript and css), and every other route actually serves text over http (data stored in edn format). The goal is to have a single page application served on the browser, where buttons and clickables invoke the server as if it were a RESTful API (since it actually is). I'd rather not have to write all the client javascript html and css manually and would much rather write it in clojure. So I'm looking over clojurescript. Can you give me some pointers on how to set up the most basic clojurescript project with lein? I don't need a lot of fancy features or third party library integration right now, I just want to get the minimal possible project up and going so I can recompile my clojurescript into javascript. I'll worry about CSS later, and at some point I will probably want to incorporate figwheel to tighten the development feedback loop. I don't want to take on too much at once though, I know what these tools do but right now I don't know much about the "nuts and bolts" of putting up the scaffolding that a clojurescript development process would require.

bcbradley14:12:48

The example on the clojurescript website is a little too basic, it doesn't leverage lein and I have to manually invoke java. Thats alright, but I'd prefer to elevate myself just a tad. Not as far as having the whole project layout and choice of libraries done for me, but just a tad higher.

tankthinks14:12:32

the output of lein new luminus myapp +cljs will give you a project structure I think you’re looking for

bcbradley14:12:46

thankyou i'll look it over

bcbradley14:12:04

before i delve deep into it, do you know whether it would be a pain to substitute my own choice of libraries?

bcbradley14:12:14

is it an opinionated framework?

tankthinks14:12:30

not a pain … it just helps set stuff up

tankthinks14:12:12

here are the libraries it will "set up” (add to project.clj and create example code) for you, but you can mix or match as you see fit

bcbradley14:12:58

it looks pretty flexible

bcbradley14:12:15

i just don't want to end up having things happen beneath me that I won't have a chance to understand

bcbradley14:12:25

its good to put yourself through doing things manually at least once

bcbradley14:12:16

although i guess if thats what i want to do i should just go through the official tutorial and work with the java command

bcbradley14:12:25

i guess my problem is lein

bcbradley14:12:32

it feels like magic and i never understood it

borkdude14:12:00

@bcbradley maybe have a look at http://boot-clj.com as well

borkdude14:12:39

don’t know if there is boot support for luminus though

borkdude14:12:54

I refer to luminus mainly as documentation, not working with the template myself

limist14:12:00

Hi all, any suggestions please, for how to detect a user's (imminent) BACK button navigation, in a cross-device way? e.g. for desktop browsers (no touch screen), tracking y-position to detect the (typical/common) mouse leaving the js/window would work. But not for mobile, etc. Thanks in advance for any help.

metametadata14:12:12

@limist back navigation is usually detected via History API

martinklepsch14:12:26

@metametadata I think he wants to "predict" if the user is going to do it.

martinklepsch14:12:45

@limist why do you want to do that though 😮

martinklepsch14:12:24

I don't think there's a cross browser way of predicting the future 🙂

limist14:12:34

@metametadata @martinklepsch Yes, trying to show users some, ahem, advice before they leave us...

limist14:12:19

@martinklepsch It's a very limited-in-time-and-space prediction, of course. 🙂

metametadata15:12:16

never seen anything like that 🙂 maybe you could show it in the standard dialog box on user leaving the page (using beforeunload event)

limist15:12:35

@metametadata Thought of that, but it seems there's no customizing of the message for security/privacy reasons, e.g. in Chrome https://www.chromestatus.com/feature/5349061406228480

metametadata15:12:44

@limist cool, didn't know about that

limist15:12:11

@metametadata Yes, me neither until recently; explains why even mighty Facebook can only show you a generic alert when you close the fb tab (and when you have something written but un-posted, somewhere on page).

borkdude15:12:07

lol: (number? NaN) ;;=> true

bostonaholic16:12:08

@borkdude that’s to be consistent with JS typeof NaN -> “number”

borkdude16:12:17

That will be my koan for the rest of today.

ricardo16:12:39

@bcbradley If you don’t mind rather new approaches, you could also have a look at #macchiato

ricardo16:12:38

Pretty early stage. Very much open for input at this point. I’m sure we wouldn’t mind having an extra set of eyes, or someone asking “how am I supposed to do X?"

Aron16:12:19

https://gist.github.com/ashnur/3f00f7629d6cff24b4f72f08fc1679cc is this something expected, and if it is, what am i doing wrong?

jondejung18:12:05

@yogthos Hey Dmitri are You available for a quick question?

bcbradley19:12:36

has anyone else taken a look at this? It looks like a pretty good resource for beginners: https://github.com/magomimmo/modern-cljs

borkdude19:12:52

I read it about 3 years ago just before Om/Reagent, etc. became popular. Nice to see they updated it.