Fork me on GitHub
#clojurescript
<
2020-02-05
>
coby05:02:51

is there an idiomatic way to limit precision when generating doubles from a spec? I have the following but I really just want to generate dollar amounts

(spec/def ::amount (spec/double-in :Nan? false :infinite? false))

andy.fingerhut06:02:18

You could generate integers, then use a function to divide them by 100.

andy.fingerhut06:02:20

Where by 'use a function' I think I mean using gen/fmap as described here: https://clojure.org/guides/spec

coby16:02:32

ok, I'll try that. Thanks

MC08:02:32

Hello: apologies if this has been asked before, but is there a goto template for react-native development?

Michaël Salihi08:02:24

• Re-natal : Figwheel + RN https://github.com/drapanjanas/re-natal • If you want run http://Expo.io with Shadow-CLJS : https://github.com/PEZ/rn-rf-shadow Note that you have the channel #cljsrn for all the CLJS and React Native stuff

MC08:02:21

Thanks for the info!

Michaël Salihi08:02:24

• Re-natal : Figwheel + RN https://github.com/drapanjanas/re-natal • If you want run http://Expo.io with Shadow-CLJS : https://github.com/PEZ/rn-rf-shadow Note that you have the channel #cljsrn for all the CLJS and React Native stuff

jeroenvandijk16:02:15

Did anyone try to decode binary transit data in js / cljs?

p-himik16:02:58

You probably mean "encode"? If so, Transit already supports binary data. And it uses base64 for it.

jeroenvandijk21:02:57

@U2FRKM4TW transit-js and transit-cljs only support the :json format, right? And I only need decoding

p-himik22:02:23

I am still not sure what you mean. You pass the data to a Transit writer on one end, you get it out of a Transit reader on the other end. Why do you need to explicitly do something with base64?

p-himik22:02:41

(require '[cognitect.transit :as t])

(let [out (ByteArrayOutputStream.)
      writer (t/writer out :json)] 
  (t/write writer (.getBytes "Clojure" "UTF-8"))
  (let [in (ByteArrayInputStream. (.toByteArray out))
        reader (t/reader in :json)]
    (String. (t/read reader))))
=> "Clojure"
And something similar should work in CLJS just as well - you'd get a Uint8Array instead of bytes[].

p-himik22:02:52

Here, if you scroll a bit, is a table with all data types supported by Transit: https://github.com/cognitect/transit-format#how-it-works bytes is in there.

jeroenvandijk07:02:14

Thank you. However I want the binary format because it is more compact than json. Not for a regular web app case. It will have to be like this: encoding clj data -> transit msgpack bytes -> base64 string. On the cljs side: decode base64 to binary integer array -> cljs data

p-himik08:02:50

I see. Just make sure you do actual measurements, because base64 eats away more than 30% of space. Just out of curiosity - why do you even need base64, why not just transfer binary data?

jeroenvandijk08:02:42

I need to put the dat in a cloudformation template

jeroenvandijk08:02:17

maybe it could be higher order base, but then I would also have to write that decoding code

p-himik08:02:43

My point is that it's very likely that JSON will end up being smaller than base64-encoded binary. :) I just tested it on a few samples, and that's indeed the case.

jeroenvandijk09:02:13

I've tested in on a few samples where it wasn't the case 🙂 But it depends on other things as well. I heavily use integers for instance

jeroenvandijk09:02:23

But i'm happy to have received your feedback and given the current state of transit libraries I'll try to get the maximum out of transit-cljs

p-himik09:02:51

Oh, nice! Can you give me such a sample?

jeroenvandijk09:02:18

It's not open source yet, but it will be when it's done. The basic idea is to replace repeated and known entities by integers. For my use case it is much more compact than Gzip for instance

p-himik10:02:07

Interesting, thanks!

Joe Corneli18:02:11

Hi, I am trying to find my way around inside of a CLJS REPL.

Joe Corneli18:02:19

cljs.user> (require 'cljs.analyzer.api)
nil
cljs.user> (cljs.analyzer.api/all-ns)
#object[Error Error: No protocol method IDeref.-deref defined for type null: ]
	 cljs.core/missing-protocol (target/public/cljs-out/admin/cljs/core.cljs:316:4)
	 cljs.core/-deref (target/public/cljs-out/admin/cljs/core.cljs:671:1)
	 cljs$core$deref (target/public/cljs-out/admin/cljs/core.cljs:1452:4)
	 (target/public/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:197:73)
	 (target/public/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:183:33)
	 (target/public/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:193:33)
	 (target/public/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:179:33)

Joe Corneli18:02:26

This is a bit confusing

Joe Corneli18:02:12

Is there a way to dig deeper and understand what this "null" is about?

Joe Corneli18:02:45

The CIDER message is as follows:

Joe Corneli18:02:57

1. Unhandled clojure.lang.ExceptionInfo
   #object[Error Error: No protocol method IDeref.-deref defined for
   type null: ]
   {:type :js-eval-exception,
    :error
    {:status :exception,
     :value
     "#object[Error Error: No protocol method IDeref.-deref defined for type null: ]",
     :ua-product :firefox,
     :stacktrace
     "cljs$core$missing_protocol@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:309:9\ncljs$core$_deref@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:2162:17\ncljs$core$deref@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:4927:18\ncljs.analyzer.api.all_ns.cljs$core$IFn$_invoke$arity$1@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:197:73\ncljs$analyzer$api$all_ns@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:183:33\ncljs.analyzer.api.all_ns.cljs$core$IFn$_invoke$arity$0@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:193:33\ncljs$analyzer$api$all_ns@http://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:179:33\n@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js line 751 > eval:1:94\n@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js line 751 > eval:9:3\nfigwheel$repl$eval_javascript_STAR__STAR_@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:751:24\n@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:799:56\nG__12816__2@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:35676:106\nG__12816@http://exchange-cljs.test/cljs-out/admin/cljs/core.js:35943:20\nfigwheel.repl.ws_connect.cljs$core$IFn$_invoke$arity$variadic/</<@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:1053:30\ngoog.events.EventTarget.prototype.fireListeners@http://exchange-cljs.test/cljs-out/admin/goog/events/eventtarget.js:284:23\ngoog.events.EventTarget.dispatchEventInternal_@http://exchange-cljs.test/cljs-out/admin/goog/events/eventtarget.js:381:26\ngoog.events.EventTarget.prototype.dispatchEvent@http://exchange-cljs.test/cljs-out/admin/goog/events/eventtarget.js:196:34\<http://ngoog.net|ngoog.net>.WebSocket.prototype.onMessage_@http://exchange-cljs.test/cljs-out/admin/goog/net/websocket.js:426:8\n"},
    :form (cljs.analyzer.api/all-ns),
    :js
    "try{cljs.core.pr_str.call(null,(function (){var ret__6754__auto__ = cljs.analyzer.api.all_ns.call(null);\n(cljs.core._STAR_3 = cljs.core._STAR_2);\n\n(cljs.core._STAR_2 = cljs.core._STAR_1);\n\n(cljs.core._STAR_1 = ret__6754__auto__);\n\nreturn ret__6754__auto__;\n})());\n}catch (e184785){var e__6755__auto___184786 = e184785;\n(cljs.core._STAR_e = e__6755__auto___184786);\n\nthrow e__6755__auto___184786;\n}"}
                 repl.cljc:  578  cljs.repl$evaluate_form/invokeStatic
                 repl.cljc:  499  cljs.repl$evaluate_form/invoke
       piggieback_impl.clj:  207  cider.piggieback/eval-cljs
       piggieback_impl.clj:  206  cider.piggieback/eval-cljs
       piggieback_impl.clj:  243  cider.piggieback/do-eval/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
       piggieback_impl.clj:  220  cider.piggieback/do-eval
       piggieback_impl.clj:  219  cider.piggieback/do-eval
       piggieback_impl.clj:  266  cider.piggieback/evaluate
       piggieback_impl.clj:  264  cider.piggieback/evaluate
                  Var.java:  384  clojure.lang.Var/invoke
       piggieback_impl.clj:  297  cider.piggieback/wrap-cljs-repl/fn/fn/fn
       piggieback_impl.clj:  190  cider.piggieback/enqueue/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  834  java.lang.Thread/run

thheller19:02:40

@holtzermann17 you are not in a self-hosted REPL so you can only access the analyzer from a clojure REPL

thheller19:02:27

the null is about the compiler env not being initialized, since that is initialized on the clojure side of things

Joe Corneli19:02:38

OK, that's interesting.

Joe Corneli19:02:56

I do have Clojure listed as a dependency in the project, but that's not enough?

thheller20:02:04

no you misunderstand how things work. you are in CLJS REPL so things you eval'd run in the JS engine after being compiled by the CLJ side

thheller20:02:10

you want to talk to that CLJ side directly instead

thheller20:02:45

but what exactly are you after? you might need to go self-hosted depending on what you are doing

Joe Corneli20:02:28

Yeah, just hoping to use all-ns at the moment. Ah. I could try for the [self-hosted](https://practicalli.github.io/clojurescript/quickstart/self-hosted-clojurescript.html) compilation...

Joe Corneli20:02:35

Sounds like a bit of heavy lifting for this limited purpose but it might be interesting.

thheller20:02:40

all-ns is intended to be used from CLJ (or from macros), so its not directly accessible in the REPL unless you are using self-hosted

Joe Corneli20:02:30

Maybe compiling a self-hosted version will be a good "learning project" for me for this weekend

Joe Corneli20:02:52

Thanks for the helpful guidance!

Ivan Koz23:02:28

Guys, i'm just getting into frontend, how do you approach css\layout side of things is there something specific for that?

bfabry23:02:25

just getting into frontend in general or just getting into it with clojure?

Ivan Koz23:02:42

in general, last time i did website was 10 years ago

Ivan Koz23:02:55

it was joomla php build

bfabry23:02:46

there's something to be said for just sticking with vanilla css, especially if it's newish to you. it'll be by far the easiest to google etc

bfabry23:02:16

it's what will be presented to you in developer tools too

Ivan Koz23:02:37

i have no problems with java or clojure, but it's a bit confusing how it all works together, atm the hardest part is css\layouts\rendering side of react components and how static\client rendering fits into a whole

bfabry23:02:53

and in my experience it's pretty rare to need to generate css. if you do, then https://github.com/noprompt/garden might make sense

bfabry23:02:45

but probably best to just define explicit css classes and assign the classes to your react components

Ivan Koz23:02:01

how do professionals approach css and layouts in their apps? Just to see if there is a direction to go to.

shaun-mahood23:02:48

That's a big question - I would look for general CSS and design resources specific to the kind of work you want to do. In general, I think the biggest changes in the past 10 years have been the rise of preprocessors and the way that React has brought styles into React components with JSX.

Ivan Koz23:02:40

yes i understand it's a big question, i just need a solid direction to where to go

Ivan Koz23:02:48

i think bootstrap and flexbox also right?

shaun-mahood00:02:21

Yes, though flexbox is a browser standard (so much nicer to use than what we had 10 years ago), where bootstrap is another framework

shaun-mahood00:02:48

A couple of component libraries specific to Reagent (if that's what you're using) https://re-com.day8.com.au/ https://github.com/gadfly361/soda-ash

Ivan Koz00:02:28

i plan to go with rum for now, but need to evaluate that decision

shaun-mahood00:02:04

Personally, I tend to throw all my CSS directly into my reagent components as I'm figuring things out (https://github.com/bhauman/devcards is amazing for this) and move it into classes later (using garden to generate my stylesheets)

shaun-mahood00:02:15

Good luck - there's a lot to learn, and I found it particularly challenging to translate from general resources to CLJS when I was getting started.

Ivan Koz00:02:43

i'm ok with java and fp in lisp, that's plays in my favor i guess

Ivan Koz00:02:57

need to learn javascript better tho

Ivan Koz00:02:09

thank you a lot Shaun

shaun-mahood00:02:46

No problem, hope things go well!

bfabry23:02:31

professionally I haven't worked with css for 7ish years. but that's how it was done then, with classes