Fork me on GitHub
#clojurescript
<
2017-01-20
>
dnolen00:01:46

@samcf you mean it’s an fn local to some other fn? if it’s really something you need to test why not just lift it out?

dnolen00:01:18

if you just don’t want it to appear as part of your public API, ^:private metadata is a thing, defn- is the shorthand

dnolen00:01:07

@ezmiller77 just my 2 cents, but testing preconditions seems odd to me

onetom08:01:20

If I want to work with arbitrary precision numbers in CLJS, would it make sense to 1. define cljs.compiler/emit-constant[1] for the 1.2M notation 2. to emit js/BigNumber[2] types, which in turn are 3. converted with cognitect.transit/bigdec for serialization with Transit and 4. deserialized as java.math.BigDecimal, so I can 5. persist them as :db.type/bigdec into Datomic ? [1] https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L229 [2] https://github.com/MikeMcl/bignumber.js

onetom08:01:32

Is there any example how to setup all this?

thheller08:01:59

@onetom I would recommend a different route ... transit allows you to set custom handlers for types

dominicm08:01:21

I may be remembering incorrectly, but I'm of the belief that Google Closure contains a bigdecimal equivalent type @onetom

thheller08:01:45

so you can control that java.math.BigDecimal gets converted to js/BigNumber and the reverse

thheller08:01:38

not too sure about datomic but should be the same

onetom08:01:17

@thheller transit converts java.math.BigDecimal to cognitect.transit.types/BigDecimal or something like that

thheller08:01:30

yes by default, but you can override it

onetom08:01:31

that's the least of the problems

onetom08:01:57

the problem is the inconvenience of creating numeric literals

onetom09:01:31

it kinda works, btw, im just not sure whats the best way to hook it into the boot-cljs boot task: i made this bigdec.clj:

(ns bigdec
   (:require cljs.compiler))

(defmethod cljs.compiler/emit-constant BigDecimal [x]
  (cljs.compiler/emits (str "(new BigNumber('" (.doubleValue ^BigDecimal x) "'))")))

thheller09:01:58

well you are going to need a custom namespace anyways

thheller09:01:13

since things like + or - are not bigdec aware in cljs

onetom09:01:15

and in my index.cljs i have this:

(ns ^{:hoplon/page "index.html"} page.index
  (:require-macros
    [bigdec])
  (:require
    [cljsjs.bignumber]
...

onetom09:01:50

yeah, i know, that's enough pain alone, that's why i thought i could at least make the bigdec literals more convenient to enter

thheller09:01:11

just use a custom namespace/type for everything

thheller09:01:22

and make sure to use bigdec/+ instead of cljs.core/+

thheller09:01:49

I don't think hacking the compiler is a good way to go

onetom09:01:25

this seems to do the magic, but for example the Dirac REPL doesn't understand the 1.2M notation and still returns js/Number, so i should install this whole magic somehow earlier in the build pipeline

thheller09:01:51

that is what I mean

thheller09:01:07

you are hacking the compiler ... so you need to hack it for every tool you want to use

thheller09:01:19

use plain cljs and skip the hacks

thheller09:01:23

much less pain involved

onetom09:01:31

ok, thanks

thheller09:01:36

only thing you lose is the 1.2M notation

onetom09:01:00

which works on the server side...

onetom09:01:36

it's just a bit annoying not to be able to move data literals back and forth easily, thats all

thheller09:01:05

FWIW I have been doing that for a long while now as I describe

thheller09:01:10

no issues whatsoever

thheller09:01:55

yes a bit annoying

thheller09:01:03

but really not that bad

onetom09:01:56

we are just using dirac quite a lot too, so it would be veeery convenient to have this...

thheller09:01:14

never used dirac but this approach should not be an issue?

onetom09:01:40

i can probably use the :js-preload the same way dirac is inserting itself...

deas10:01:06

Short question ...

deas10:01:22

{:foreign-libs [{:file     "resources/public/jslib/depends-on-react.js"
                 :provides ["sample.foreign-dep-on-react"]
                 :requires ["cljsjs.react"]}]}

deas10:01:15

(ns foobar
  (:require ["sample.foreign-dep-on-react"]))

deas10:01:15

I was expecting that this ensures cljsjs.react is always loaded before depends-on-react.js is. Seems I am wrong. Any suggestions how to achieve this dependant on the cljs-build?

thheller10:01:11

@deas I'm not entirely sure but shouldn't :provides and :requires be symbols?

thheller10:01:23

:requires [cljsjs.react]

deas10:01:03

@thheller The former is meant to be a map fragment of project.clj.

thheller10:01:29

symbols are perfectly valid there

thheller10:01:20

but I know nothing about cljsbuild anymore so I might be wrong

thheller10:01:29

but the setup looks OK, so it should work

deas10:01:57

@thheller It does not work for some reason. And no, :requires must be an array of strings.

thheller10:01:29

sounds like a bug then

deas10:01:56

@thheller load order looks fine. Maybe my assumptions about react.inc.js exposing window.ReactDOM were wrong. Anyways, thanks for your time.

thheller10:01:30

ReactDOM is in cljsjs.react-dom

deas10:01:33

@theller cljsjs.react.dom did the trick. Thanks.

practicalli-johnny12:01:45

Any recommended step by step tutorials on reagent & reframe for relative novices? I'm running a hackday and would like to build a reactive app step by step in Clojurescript and we got stuck with Om last time. One of the ideas is to build a live voting app for presenters, so the audience can give feedback as they are speaking. It would be great if any tutorials also used Dev cards.

qqq13:01:48

@jr0cket : there's also a #re-frame channel here, the authros of re-frame are there, and they might have helpful insights

placeboza14:01:53

So strange, can't find a single example anywhere of using the web cam of phone/device .. e.g. just grabbing the device and streaming out the video, something

placeboza14:01:59

using clojurescript I mean

placeboza14:01:23

Maybe I'm just such a noob that it's too obvious to find an example for 😛

kauko15:01:29

@placeboza do you know how javascript interop works? You can just use the functions used in that example from clojurescript using interop

placeboza15:01:18

no, but that gives me a direction, thanks 🙂

placeboza15:01:09

ah I see.. yes

kauko15:01:04

It may be smart to keep all of the js interop in one namespace, like a wrapper, and have the actual functionality in another namespace.

placeboza15:01:19

makes sense, Id want to separate it out anyway

placeboza15:01:54

I think I should properly finish learning clojure though, Im too noobish. And not sure if ClojureScript is gonna handle what I want to do

placeboza15:01:22

May have to just use straight Clojure and lein-droid for mobile

placeboza15:01:29

making a game that uses the camera

placeboza15:01:22

would be easier if I just used the language Im good at, but I love the elegance and concept behind clojure

placeboza15:01:29

and live coding

emccue16:01:31

"Using the camera" is a very broad topic that I think goes beyond just basic Access

emccue16:01:21

I think you should be able to get camera access working fairly easily, but the real question is what you want to do with that

emccue16:01:38

Client side object detection? There are js/android libraries for it. Server side something detection? I'm sure you can figure out some data scheme that isn't too taxing

devth16:01:02

what's the latest thinking on making clojurescript compiles faster during dev? i assume optimizations: none and using cljsbuild and figwheel all help, but still my repl takes 30 seconds to start, then when i run my app from the repl and startup figwheel it's another 120 seconds of compiling. can we precompile libs?

dnolen17:01:59

120 seconds of compiling seems odd unless you have a lot of code or you’re blowing away your build each time

dnolen17:01:19

if really you want the REPL to start faster then you probably need to avoid Lein

dnolen17:01:38

Figwheel Sidecar load time could be decreased if there was an AOT’ed artifact - I’m sure @bhauman has bigger issues on his plate than investigating that

dnolen17:01:30

@devth precompiling libs means potentially being locked to a particular version of the compiler - so we haven’t really pursued that idea

devth17:01:43

must be our libs. om.next, grommet, and a moderate amount of client code.

devth17:01:04

(i think we are blowing away our build)

dnolen17:01:16

you can turn on :compiler-stats to see where the time is going

dnolen17:01:26

blowing away the build is pretty gratuitous these days

dnolen17:01:39

most of the reasons to do that under dev have gone away

devth17:01:14

cool, thanks. i'll try both of those out.

isak17:01:31

is there a good way to check for inconsistent variable access in closure? having some minification errors due things like js/window.top vs (aget js/window "top"). Also some errors that are not visible with pseudo-names on.

dnolen17:01:14

There is not

dnolen17:01:37

If window.top isn't a standard thing don't use it

dnolen17:01:45

Or provide an extern if you must

dnolen17:01:44

I don't know what you mean by your last sentence. Needs clarification

isak17:01:15

ok. for the last sentence, i mean that some of the minification errors we've gotten have gone away with pseudo-names turned on, which makes them harder to track down

dnolen17:01:29

seems unlikely - I’ve never encountered that before - but yes that may be possible

dnolen17:01:38

no recommendations for that case sorry

isak17:01:24

it is something that started happening after we introduced module splitting. np, trying to take out the foreign libs now.

dnolen17:01:02

@isak there’s a known dependency order problem with module splitting now fixed in master

dnolen17:01:13

so that’s what you probably seeing

dnolen17:01:24

but hard to say for sure unless you try master yourself

dnolen17:01:36

which is something worth getting familiar with

isak17:01:52

@dnolen ah yes, that sounds right, we'll give that a try, thank you.

shicholas18:01:25

hello, I'm trying to convert some clojure code to clojurescript and currently use the jdbc/postgresql drivers. what is a good clojurescript alt? thanks!

richiardiandrea18:01:46

@shicholas do you mean querying using Clojurescript?

shicholas18:01:12

like I use the Yesql library with my clojure code

richiardiandrea18:01:35

uhm, you might need to look at some Javascript lib, I haven't heard of anything like that in cljs

shicholas18:01:58

okay, will look around, thanks

shicholas18:01:13

I guess like use the node-postgres library or something

richiardiandrea18:01:26

yes I would actually look into that

richiardiandrea18:01:59

@shicholas lol I didn't do anything 😄 if you can report back your experience, I am interested 😉

shicholas18:01:43

ha for sure, I'm still a clojure n00b and didn't want to try and reinvent the wheel