Fork me on GitHub
#clojurescript
<
2018-07-20
>
justinlee00:07:27

I was wondering if it was nested scrolls. It is not uncommon to have an external holder that fits the viewport so that the sidebar is fixed and the main content scrolls. Perhaps that’s it? I am not familiar with how that event bubbles.

jjttjj03:07:04

has anyone had to format/compact numbers in cljs such that 43,000,000,000 becomes 43B? I know goog.i18n.NumberFormat is capable of this but I'm having trouble working out how exactly to make it work. Is this functionality in cljs.pprint/cl-format?

jjttjj03:07:09

nvm got it

(:import (goog.i18n NumberFormat)
           (goog.i18n.NumberFormat Format))
...
(def formatter (NumberFormat. Format/COMPACT_SHORT))
(.format formatter 43000000000)
;;=> 43B

jjttjj04:07:44

anyone know if cl-format supports this?

kennytilton06:07:55

It does a lot (I hear it is Turing complete) but not that. You can roll your own, tho:

(defn pic9A [n]
  (let [scale (Math/floor (/ (Math/log10 n) 3))]
    (clojure.pprint/cl-format
      nil "~d~v[~;K~;M~;B~;T~;G~]"
      (/ n (Math/pow 10 (* scale 3)))
      scale)))

👍 4
jjttjj15:07:58

cool, thanks!

kennytilton06:07:42

Lightly tested, and be careful, that is a capital A in the name as a hat-tip to Cobol.

javi09:07:13

Hi, i am working on adding inline doc search in my self-hosted clojurescript environment. using (meta (var map)) or (meta #'map) works great and gives me

{:ns cljs.core,
 :name map,
 :file "cljs/core.cljs",
 :end-column 10,
 :top-fn
 {:variadic true,
  :max-fixed-arity 4,
  :method-params ([f] [f coll] [f c1 c2] [f c1 c2 c3]),
  :arglists ([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]),
  :arglists-meta (nil nil nil nil nil)},
 :column 1,
 :line 4654,
 :end-line 4654,
 :arglists ([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]),
 :doc
 "Returns a lazy sequence consisting of the result of applying f to\n  the set of first items of each coll, followed by applying f to the\n  set of second items in each coll, until any one of the colls is\n  exhausted.  Any remaining items in other colls are ignored. Function\n  f should accept number-of-colls arguments. Returns a transducer when\n  no collection is provided.",
 :test nil}
however i want to pass the var name as a string, and doing (meta (var (symbol "cljs.core" "map"))) and is not working. What piece am i missing/getting wrong?

iperdomo09:07:10

(meta (resolve (symbol "clojure.core" "map"))) ?

👍 4
thheller09:07:43

@fj.abanses in CLJS this data is only available via the analyzer API. see cljs.analyzer.api

👍 4
thheller09:07:35

if you are in self-hosted you should have access to the compiler env. there you could (get-in @compiler-env [:cljs.analyzer/namespaces 'cljs.core :defs 'map :meta])

javi09:07:12

thanks! @thheller giving it a try.

javi09:07:09

thanks @iperdomo, trying this also.

javi09:07:22

got it working. thanks for the help!! (get-in @cljs.env/*compiler* [:cljs.analyzer/namespaces 'cljs.core :defs (symbol "map") :meta])

shidima12:07:28

I'm having some problems converting js to cljs code. I know I could use something like (def ig-obj (js/ig.module.requires.defines)) to get to a nested scope, but I have problems adding the options:

ig.module( 
	'game.main' 
)
.requires(
	'impact.game',
	'impact.font'
)
.defines(function(){
MyGame = ig.Game.extend({
	font: new ig.Font( 'media/04b03.font.png' ),
	
	init: function() {
	},
	
	update: function() {
		this.parent();
	},
	
	draw: function() {
		this.parent();
		var x = ig.system.width/2,
			y = ig.system.height/2;
		
		this.font.draw( 'It Works!', x, y, ig.Font.ALIGN.CENTER );
	}
});

shidima12:07:04

How would I go about adding the parameters to the nested scope?

milomord14:07:54

You will actually probably want to use a threading macro here

milomord14:07:15

Something like:

(-> js/ig
      (.module "game.main")
      (.requires "impact.game" "impact.font")
      (.defines my-defines-function))

milomord14:07:14

As for 'nested scope' def (if I understand what you mean correctly) doesn't nest

milomord14:07:41

You'll want to look at using let to define local variables

athomasoriginal20:07:45

Hey all, does anyone have an example project of a pure clojurescript ui library, or just a library, which uses deps + clj cli tool? I am particularly interested in seeing how they run the production build...but in general, would just love to see some examples. Thanks!

eriktjacobsen22:07:48

Asking for Debug help: We have a pretty basic reagent app. It works for everyone else, but on my machine with a fresh git clone and using same DB as everyone, it fails. Fails both with figwheel and cljsbuild/run. No problems with java clojure, other cljs apps work fine. Same version of java, and I was previously a version behind them with lein but I get same behavior after upgrading to 2.8.1. I get a The map literal starting with :AWS contains 3 form(s). Map literals must contain an even number of forms. uncaught exception in cljs. (:AWS is a key loaded from a DB, not in source) Outside of throwing the laptop in the dumpster, I'm past my cljs knowledge on next steps to debug this, as no one else can repro this, and seems independent of the code itself.

Mario C.22:07:11

Ive gotten one of those before when I misplace my {}

eriktjacobsen22:07:10

It's a fresh git clone with same code as 5 others who don't see any errors. Also I think the error is coming from a reader attached to a core.async channel, as that literal does not actually appear in the code but rather as a response coming from the backend

justinlee23:07:31

If you are using the reader to parse the backend (bad idea imo) that would explain how it is different for you: somehow your login info is causing a different response from the server. You need to find where that’s happening, and put a try catch around that piece of the code so that you can dump the response from the server.

eriktjacobsen23:07:05

Thanks. There is no login info, the steps are literally:

git clone
lein figwheel
load page
get error
the same on each computer, only mine fails. Same network, connecting to same DB(verified as working), etc. I posted the stack trace elsewhere, but it's extremely opaque as they are all core fns.

eriktjacobsen23:07:02

I can go the route of adding in a ton of debug code every few calls, my focus thus far has been why would it work on 5 other machines and not mine, despite having nearly identical environments.

justinlee23:07:28

This is why I don’t like core async :)

lwhorton00:07:57

i haven’t needed core async for anything since using reframe

lwhorton00:07:25

side effects and async flows are handled so nicely that i don’t bother with the (mental) overhead of core.async

justinlee02:07:41

@U0W0JDY4C that’s interesting. that’s possibly the strongest argument for re-frame i’ve heard. though i worry that it turns everything into state machine programming

lwhorton21:07:58

it does… but is that so bad? especially when dealing with UIs, nearly everything non-trivial could be improved with a fsm. also, i know @U051MTYAB is hammocking about ways to improve reframes FSM-like characteristics

justinlee23:07:18

I mean, all things being equal, it is nice to have the flow of data and networks calls laid out in a linear fashion, rather than trying to trace a sequence of events

justinlee23:07:46

i understand that the tooling helps and there are big gains from simplifying the steps

justinlee23:07:58

maybe it is a net improvement

lwhorton16:07:05

maybe it’s just preferred flavors. i find that tracing discrete possibilities into completely isolated fns that are “somewhere else” is easier than trying to look at a big ol’ nested if block and/or some sort of loop/recur channel with branching conditionals

quoll22:07:17

It’s complaining of a map literal rather than a map. Is source code for the map being generated as a clojurescript fragment (or edn) and then loaded?

eriktjacobsen23:07:25

The frontend does load some end from the backend. but it's all in the same project, connected to same db as others, and only breaks on my machine. The stack trace is very unhelpful:

"Error: The map literal starting with :AWS contains 3 form(s). Map literals must contain an even number of forms.
    at new cljs$core$ExceptionInfo ()
    at Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 ()
    at Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2 ()
    at cljs$core$ex_info ()
    at Function.cljs.tools.reader.impl.errors.throw_ex.cljs$core$IFn$_invoke$arity$variadic ()
    at cljs$tools$reader$impl$errors$throw_ex ()
    at Function.cljs.tools.reader.impl.errors.reader_error.cljs$core$IFn$_invoke$arity$variadic ()
    at cljs$tools$reader$impl$errors$reader_error ()
    at cljs$tools$reader$impl$errors$throw_odd_map ()
    at cljs$tools$reader$edn$read_map ()"

quoll23:07:02

That actually answered one of my questions. Some EDN was generated, only the EDN was faulty and it can’t be parsed. So the trick is to find where it was created. Is it create dynamically and read in as a string? Is a file generated, and the file is read in? To start with, you’ll want to track down how the DB is read to get this info? What happens with that info once it’s read? Where does it go? Where is the code that reads the reader? Is it calling cljs.tools.reader.edn.read-string, or cljs.tools.reader.edn.read?

quoll23:07:27

finding where it’s read may give you hints as to where it was generated

eriktjacobsen23:07:23

Oh check the main forum, I found it was a deprecated cookie that we aren't reading in user code, but gets read by reagent

eriktjacobsen23:07:09

Somehow I got a corrupted cookie on my browser only. clearing it fixed. Oddly we aren't using cookies in our code anymore so didn't even think to clear cookies

quoll18:07:57

Well done tracking it down!

quoll22:07:10

my first thought (with extremely limited knowledge of what you have) is that the code doing that reading is not handling some condition that it’s running into

quoll22:07:35

and only generates 3 elements, instead of the 4 it expected

bhauman23:07:43

@eriktjacobsen print the string before it is read

eriktjacobsen23:07:52

whups my bad everyone, false alarm. We had a deprecated reagent cookie that somehow got set with bad data on my browser. Clearing cookies was a critical step I failed to check, since we are no longer even using the cookies in our code. Apparently they are read at a lower level and caused a edn / reader failure outside of our user code. Thanks for the help everyone. (good reminder: always clear cookies)