Fork me on GitHub
#clojurescript
<
2016-12-27
>
iku00088803:12:30

What are good alternatives for hiccupdata->dom node, if I am migrating from an old dommy?

qqq03:12:03

in cljs, how much can I .increment a number before it stops incrementing? (due to everything being a double in js)

mfikes04:12:32

@qqq I believe it is 2^53. Reference: See https://en.wikipedia.org/wiki/Double-precision_floating-point_format , in particular the sentence indicating that in the range from 2^52 and 2^53 you can represent integers, and then 2^53 to 2^54 being even integers. In short

(= (inc 9007199254740992) 9007199254740992)

mfikes04:12:34

Or, FWIW (inc cljs.spec/MAX_INT)

metametadata12:12:29

Would it be correct to say that Google Closure compiler won't even try to eliminate dead code from the libraries included via :foreign-libs+:externs?

martinklepsch12:12:00

@metametadata that would be correct, yes.

martinklepsch12:12:09

@metametadata that's kind of what the "foreign" bit is about. Usually foreign libs are written in a different module system or none at all and thus can't be understood/disected by the compiler

martinklepsch12:12:17

If you have something that's in Closure's module format you can use :libs and get all the benefits (DCE, renaming etc.)

thheller12:12:59

@metametadata FWIW Closure won't even see :foreign-libs, only their externs

fossifoo14:12:12

i'm trying to test a function that accesses a global JS variable and i'm looking for a way to set/mock that in the test. is there a way to write to global variables or change the access to them?

henriklundahl15:12:51

@fossifoo, e.g. (set! (.-xyz js/window) "xyz")

pesterhazy15:12:49

because js is single-threaded, you can just store the value, run the test, and restore its old value πŸ™‚

fossifoo15:12:54

thanks. that's what i tried. i got a parenthesis wrong πŸ˜‰

henriklundahl15:12:43

This also works and is shorter: (set! js/xyz "xyz").

fossifoo15:12:45

too much plain js, not enough lisp in the last few days πŸ˜‰

fossifoo15:12:11

yeah, that's actually what i use now πŸ˜‰

fossifoo15:12:26

have to defeat the urge to write a with-global-variable πŸ˜‰

fossifoo15:12:53

my main it's going to be the only point i'll take these in, no point, but....

fossifoo15:12:43

but there is no "unset", so "delete", right?

fossifoo15:12:16

oh, well, set!ing to js/undefined should be fine

potetm15:12:13

@fossifoo I think the preferred way is to use goog.object/remove

potetm15:12:13

There is also js-delete, but gobj/remove will tell you if the key was actually deleted.

fossifoo15:12:37

but for "global" i don't have any object

potetm15:12:22

Well I was thinking js/window, but deleting from window is apparently illegal in js itself.

potetm15:12:39

disregard. carry on πŸ™‚

fossifoo15:12:48

actual: #object[ReferenceError ReferenceError: Can't find variable: global

fossifoo15:12:00

seems like phantomjs doesn't like js/global

fossifoo15:12:07

it provides window though

pesterhazy15:12:48

it's js/global in node, js/window in browsers I think

potetm15:12:14

Hmm, it actually worked in my repl, but not in my console:

potetm15:12:21

js/window
=> #object[Window [object Window]]
(set! js/window.a "foo")
=> "foo"
js/window.a
=> "foo"
(js-delete js/window "a")
=> true
js/window.a
=> nil

potetm15:12:41

(in chrome) ^

fossifoo16:12:43

hmmm. also still seems to be set in phantomjs after the delete

fossifoo16:12:03

i guess i just go for overwriting it with undefined

fossifoo16:12:25

should work everywhere in case i want to switch test environments πŸ™‚

fossifoo16:12:23

works good enough. thanks

gfredericks21:12:06

I think I am going to make an SPA, for the first time in a while.

gfredericks21:12:39

but it is not a business app and does not have a backend or a complex app state thing. so I'm afraid of using a full SPA framework

gfredericks21:12:07

I feel like I mostly just need a good library for handling events and updating the dom

gfredericks21:12:25

and do everything else the quick & dirty old fashioned way

gfredericks21:12:49

am I wrong? what libraries are good for the events and dom stuff?

geoffs21:12:19

@gfredericks for updating the dom my preference has been reagent for a while

geoffs21:12:49

reactive atoms were you need them for ad-hoc state as necessary

gfredericks21:12:05

okay so I can use that without having to like have an implementation of datomic in the browser and use datalog or anything like that

geoffs21:12:34

yup totally.

gfredericks21:12:39

I imagine it has event handling as well

geoffs21:12:11

haven't looked into that as much. Most event stuff I've done with it I just hook directly into whatever js event I need

gfredericks21:12:25

should I be figuring out how react works if I'm going to do that or can I pretend react is not there

geoffs21:12:04

I don't 100% understand how react works myself. or even like 80%. I mostly pretend it's not there

geoffs21:12:57

:thumbsup:

esanmiguelc22:12:21

@gfredericks I’d recommend reading a little bit on react if you have not tried it ever, I think reagent docs assume that you know react in the first place. It’s very intuitive after that, though. Recommended

potetm22:12:04

Is :serve-static really an option for the browser repl?

potetm22:12:21

It's in the doc string, and it's defaulted to true in the opts. But that key doesn't appear to be read anywhere. It just reads :static-dir when setting up the server.

potetm22:12:17

Furthermore, given the way the xpc connection is set up, I think you must serve static files to one extent or another.