Fork me on GitHub
#clojurescript
<
2019-04-25
>
misha08:04:14

(ns foo ;;cljs
  (:require ["esrever" :as esrever]))

(let [s "Lorem ipsum 𝌆 dolor sit ameͨ͆t."
      a (clojure.string/reverse s)
      b (esrever/reverse s)]
  (js/console.log s)
  (js/console.log a)
  (js/console.log b)
  (js/console.log (= a b)))
https://github.com/mathiasbynens/esrever

metehan10:04:18

Use of undeclared Var threedays.core/format

  1  (format "%5d" 3)
      ^---
clojure fortmat doesn't work in clojurescript right? i want to make 5 to 0005 how can i do this ?

dominicm10:04:39

@m373h4n there is a format in Google closure, but you need to import it

misha11:04:42

(goog.string.format "%04d" 5)  ;;=> "0005"

metehan11:04:45

misha, dominicm, thank you very much

metehan14:04:06

Warning: React does not recognize the componentDidMount prop on a DOM element.

metehan14:04:43

(defn card
  [item]
  [:div.holder {:component-did-mount (resetMsnryLayout)}
   [:div.card
    [:div.card-image
...

hkjels14:04:59

have a look at`reagent/create-class`

metehan14:04:57

Thank you. I searched on github and I found some sample codes. I'll try to implement now.

metehan14:04:14

where i should put this :component-did-mount

David Pham14:04:04

I have a memory leak in my app, and I wanted to know if anyone has some advice on how to tackle the problem? The leak only appears on Windows

dnolen14:04:32

@neo2551 need a lot more information to be helpful - did you confirm via Chrome/Firefox dev tools that you're not leaking there? what version of IE are you talking about? And is the observed behavior in IE a crash?

David Pham14:04:57

It happens on Firefox on Windows

David Pham14:04:07

But kit Firefox Linux

David Pham14:04:38

@dnolen thanks a lot for helping. I will try to do more thorough test with multiple browser first.

David Pham14:04:11

What are the common cause of memory leak in cljs? (With reagent/re-frame)

dnolen14:04:58

I don't think you can point to a common case

dnolen14:04:14

if this is Firefox then you're in luck - it has descent memory profiling tools

dnolen14:04:31

if it has a heap snapshot feature that can be very helpful

dnolen14:04:01

(er, well actually re: common case, lazy sequences)

dnolen14:04:14

that's the first thing to check for - if it's not that then you have to go hunting

lilactown14:04:13

<memory leak in IE 10> = “Just go buy more RAM, thanks”

dnolen14:04:26

@neo2551 usual issue is to do some kind of operation that involves an infinite lazy sequence and then realize it - which of course will just eat up memory

dnolen14:04:40

but that would affect every browser

David Pham14:04:23

But if this is the case, it would consume the memory super fast?

dnolen14:04:47

@neo2551 yes it would explode almost immediately, locking up the browser

dnolen14:04:07

I would use the above to find the leak

David Pham14:04:14

Thanks. I have an app that loops events.

David Pham14:04:23

Thanks I will search!

David Pham14:04:36

And also thanks a lot for your talks! They are really inspiring

David Pham14:04:56

I wish we had the slides for the one when you talk about simpler tools.

heefoo14:04:43

@lilactown I constantly get Use of undeclared Var hx.hooks/useEffect When i try to utilize your library

lilactown14:04:31

what version are you using?

heefoo14:04:41

latest, i think

heefoo14:04:43

let me see

heefoo14:04:13

lilactown/hx {:mvn/version "LATEST"}

lilactown14:04:20

seems weird. does it point to a specific line?

lilactown14:04:08

FYI I’ve never seen that way of referring to maven versions

lilactown14:04:35

I think what’s happening is that it’s not pulling the SNAPSHOT version

lilactown14:04:57

so you’re using 0.4.0, which doesn’t have the useAbcXyz named fns

heefoo14:04:00

sure, but i have already had it tested iwith what you refer at your site

lilactown14:04:23

try "0.5.0-SNAPSHOT"

lilactown14:04:49

I haven’t done a proper release of what the docs reflect. sorry about that

heefoo14:04:48

no worries

lilactown15:04:41

hold please 🙂 fixing

lilactown15:04:55

strange that this doesn’t show up for me. are you using shadow-cljs or figwheel?

heefoo15:04:06

pure shadow-cljs

heefoo15:04:35

From the message it seems that hx.uitls is a macro namespace correct ?

lilactown15:04:53

I mean it’s not that the error is wrong just curious why it’s not occurring for me 😛

lilactown15:04:16

yeah, and it’s barfing because I also have some CLJS-specific code that’s not in a reader conditional

heefoo15:04:08

I am reading the file

heefoo15:04:06

(comment (props->clj #js {:class "foo"}) )

heefoo15:04:12

this is the only js tag appearing

lilactown15:04:27

there’s also map->camel+js which I think is the actual problem

heefoo15:04:54

goog.object/create

heefoo15:04:03

that is essentialy the js tag litteral

lilactown15:04:46

I’m just gonna split the ns into .cljs and .clj

heefoo15:04:12

that would work too 🙂

lilactown15:04:25

OK, I just pushed a new snapshot

lilactown15:04:38

lilactown/hx/0.5.0-SNAPSHOT/hx-0.5.0-20190425.151107-2.pom

heefoo15:04:05

a long snapshot name

lilactown15:04:19

yeah you don’t need to use the whole thing (I think)

lilactown15:04:24

my maven-foo is very weak

heefoo15:04:37

still better than mine

lilactown15:04:40

but just ensure that you’re pulling that one when shadow-cljs downloads the dependencies

lilactown15:04:14

i think it does some caching and I’m not sure how to invalidate it for snapshots (if it’s required)

heefoo15:04:29

probably have to reach in .m2

heefoo15:04:42

Downloading: lilactown/hx/0.5.0-SNAPSHOT/hx-0.5.0-20190425.151107-2.jar from https://repo.clojars.org/

heefoo15:04:47

i think is downloading

lilactown15:04:10

😄 all fixed. thanks for the report! happy to help!

lilactown15:04:10

😄 all fixed. thanks for the report! happy to help!

ghadi15:04:03

Is it possible to extract ClojureScript compiler warnings as data?

ghadi15:04:20

Or turn warnings into errors

idiomancy17:04:59

anyone know of a good way or workaround to do with-out-str on console.log? Presumably the console entries are stored somewhere, is there some way to access them?

idiomancy17:04:01

Alternatively, does anyone know what the console uses to display object properties? like some kind of format function I can call on MouseEvent that would return me the string that is displayed in the console with console.log

darwin17:04:35

you can redefine console methods with your own functions and capture all calls

idiomancy17:04:16

yeah, but thats the inverse of what I need. I want the value that is generated from the inputs, not the inputs to the function

darwin17:04:02

console displays rich html, I don’t understand the question

darwin17:04:37

or do you really want html console would render?

idiomancy17:04:01

well, I would be okay with that. at least I could parse it. the issue I have is that attempting to serialize an event with JSON.stringify doesn't work. circular references etc prevents it from formatting. console.log deals with that though, and I wanted to capture its output. but I mean ideally id really just like a way to serialize a dom event

darwin17:04:34

well, using output from console.log for this would be a brittle idea (browser vendors can change that output anytime), instead remove circular references or stuff which is causing troubles prior calling stringify on it

idiomancy17:04:07

I don't disagree with any of that

darwin17:04:02

btw. console strings you print are not stored anywhere accessible, at least in chrome, they are sent over into browser engine, they are not kept in js environment

idiomancy17:04:31

yeah, so I've discovered lol

idiomancy18:04:39

I ended up just doing this:

(defn capture-event [e]
  (let [keys (js->clj (js-keys e))]
    (zipmap (map keyword keys)
            ((apply juxt (map (partial partial #(aget %2 %1)) keys)) e))))

idiomancy18:04:25

i think aget is fine there because Im looking up the keys post compilation, right?

lread17:04:58

@ghadi you can hook into warnings via :warning-handlers. I am experimenting with this using https://github.com/emezeske/lein-cljsbuild. Here’s a link to my playground warning-handler: https://github.com/lread/rewrite-cljs-playground/blob/cljc-spike-2/test/rewrite_clj/warning_handler.clj which is specified here: https://github.com/lread/rewrite-cljs-playground/blob/cljc-spike-2/project.clj#L36

ghadi17:04:40

oh, useful, thanks!

ghadi17:04:08

@lee is that a lein-cljsbuild thing or a clojurescript thing?

dpsutton17:04:32

## 1.8.40

### Fixes
* CLJS-1603: Only warn for misspelled comp/REPL opts
* :warning-handlers missing for known compiler options
* CLJS-1592: Self-host: Robustness for core tests
* 

lread17:04:34

lein-cljsbuild made it easy to specify a warning-handler, so I took that route for now.

ghadi17:04:47

nice! does :warning-handlers resolve a symbol into a function? or do you need to supply a function from code?

ghadi17:04:57

(I can try it)

ghadi17:04:18

using something like requiring-resolve would be nice for build tooling

lread17:04:28

no, that was what I found a bit awkward with it and why I started my experiment with lein-cljsbuild which does resolve for you.

lread17:04:43

FWIW, here’s where lein-cljsbuild helps out with the setup of warning-handlers: https://github.com/emezeske/lein-cljsbuild/blob/master/plugin/src/leiningen/cljsbuild.clj#L126

ghadi18:04:37

I wonder if :watch-fn :watch-error-fn and :warning-handlers could use requiring-resolve

lread20:04:48

Oh, I did not notice :watch-fn, that could further my little experiment! Thanks.

ghadi20:04:44

that appears to already take a symbol

ghadi20:04:56

it's only :warning-handlers that doesn't

lread20:04:06

oh, cool! will try it!

ghadi18:04:41

I don't know how that interacts with self-hosting... but it would be nice for build automation

ghadi18:04:53

just point to a var already on the classpath

dnolen18:04:13

@ghadi I don't see any issue for self-hosting - and even if there were that would be considered separately

dnolen18:04:01

patch welcome for this and I completely agree - would be simple - I think the only consideration here would be making sure this doesn't tie us 1.10 or something like that

ghadi18:04:26

are there other callbacks exposed?

ghadi18:04:01

I only grepped the docs quickly

dnolen18:04:28

@ghadi that's probably all that's there at the moment

mv19:04:33

Is there a guide or tutorial to resolving js promises in cljs? I know that the promise will never reject

mccraigmccraig19:04:21

@mv i've been successfully using funcool/promesa with js promises for quite a while http://funcool.github.io/promesa/latest/

mv19:04:52

Yes I saw that, was just curious if there was a stdlib or core way of doing it

mv19:04:56

If not, thanks!

mccraigmccraig19:04:13

no stdlib way afaik, other than using the completion callbacks to put the resolution onto a core.async channel

lilactown19:04:43

(-> (returns-a-promise-of-a-thing)
    (.then (fn [thing] (do-something-with-thing thing)))
?

martinklepsch19:04:08

on the topic of promises — anyone had to implement something to run multiple promises sequentially?

mccraigmccraig19:04:14

well, sure, if you only want to resolve a single promise - when you want to compose chains of them with sensible error handling you might want a lib

lilactown19:04:05

FWIW I use promesa heavily, but don't find it generally better than just interop

lilactown19:04:34

@martinklepsch not sure I totally understand. do you mean, given a collection of promises, that you run each one after the other, feeding result of one into the next?

mccraigmccraig19:04:52

we use the promesa impl of the funcool/cats promise monad context a lot - i really like it - the monadic bind syntax makes for very comprehensible code

martinklepsch19:04:08

more like this

a().then(b).then(c).then(function(result) {
   // all are done here
});

martinklepsch19:04:35

I don't actually care about the result of the previous run but yeah, first promise should resolve before second is "started"

mccraigmccraig19:04:52

@martinklepsch (cats.core/mlet promesa-ctx [a (thing) b (other-thing) c (ya-thing)] (return (x a b c)))

lilactown19:04:03

it's hard to know what exactly you want to happen different than writing out that promise chain exactly

martinklepsch19:04:57

oh right, sorry — I want to do this in a map like interface over a sequence of items.

martinklepsch19:04:20

which makes it hard to do it with syntax constructs like mlet etc

lilactown19:04:07

fundamentally it's a reduce, right?

lilactown19:04:51

so you could do

(defn chainp "Chains a promise-returning function to a promise"
  [p1 f]
  (.then p1 f))

(.then (reduce chainp (js/Promise.resolve) [a b c])
   (fn [result]
     ;; all are done here
    ))

martinklepsch19:04:46

you're right, it's really that simple I guess. 🙂

jaide20:04:17

Argh, how do I set element 0 of a js array again? (set! (nth (.-data obj) 0) "something-else") doesn’t work

jaide20:04:18

Nevermind, it’s aset

ghadi20:04:50

Filed https://dev.clojure.org/jira/browse/CLJS-3074 I might not have the time to look at this, so it's up for grabs by any motivated party! @dnolen

lread21:04:38

I suppose I could take a crack at it. Seems like an easy first issue?

lread22:04:07

Wait.. wrong room to ask, I’ll head over to #cljs-dev