Fork me on GitHub
#clojurescript
<
2016-03-15
>
mfikes00:03:10

@george.w.singer: I’d try :refer-macros as in [cljs.core.async :refer-macros [put! chan <! >!]]

george.w.singer00:03:58

@mfikes: thanks for the suggestion, but unfortunately it didn't work.

mfikes00:03:13

@george.w.singer: I also wrote about it here, but I don’t think it adds anything to what you have already tried, honestly: http://blog.fikesfarm.com/posts/2015-12-02-clojurescript-repl-auto-require.html

george.w.singer00:03:54

Wow -- I came across that before asking on Slack from Googling

george.w.singer00:03:19

Crazy coincidence lol

mfikes00:03:35

@george.w.singer: Oh, wait. The macros for core.async are in a different ns right?

george.w.singer00:03:51

cljs.core.async.macros

mfikes00:03:13

Dang. Well, that’s why it doesn’t work. Seems like you might need a :repl-require-macros option added. Hmm.

george.w.singer00:03:54

I just tried :repl-require-macros '[[cljs.core.async.macros :refer-macros [go]]] and that also didn't work

puppybits01:03:26

Is there a way to get the previous item(s) in a seq when iterating over it?

cky01:03:32

No. If so, lists (which are singly-linked) would not be usable as a seq.

richiardiandrea01:03:21

@puppybits: that would be a reduce, where you collect what you need for the "next" step I guess

jasongilman01:03:01

You can iterate over the list and the list offset by 1

jasongilman01:03:21

(def items '(1 2 3 4 5))

jasongilman01:03:25

(map #(vector %1 %2) (cons nil items) items)

jasongilman01:03:08

=> ([nil 1] [1 2] [2 3] [3 4] [4 5])

bpicolo03:03:56

Anybody pretty familiar with re-frame that could give me some assistance? I've been stuck for a while on this: I have a reaction that I expect to resolve to a vector, but it resolves to cljs.core.ValSeq which has been super troublesome and difficult to debug

bpicolo03:03:07

cljs.core.ValSeq doesn't function inside of a for loop I believe

bpicolo03:03:09

Let me giiist...

bpicolo03:03:00

My actual code unfortunately appears nowhere in the stack trace

bpicolo03:03:27

ahh, well actually it does in the for loop

oli03:03:36

what does your subscription look like?

bpicolo03:03:53

@oli that's in the gist

bpicolo03:03:16

also added what @tags looks like at that point

bpicolo03:03:07

I've been stuck on this bug for quite a long time, not really sure how to debug what's going on because I don't really know what to expect either

bpicolo03:03:15

(Very new to cljs)

oli03:03:46

i mean the register-sub decl.

oli03:03:13

(rf/register-sub :company (fn [db] (reaction (-> @db :company))))

bpicolo03:03:19

I do not have one

bpicolo03:03:25

Maybe that's what I missed

oli03:03:40

yeah - your handler updates the db

oli03:03:52

your subscription listens for changes

bpicolo03:03:20

oh I do have that uhh

bpicolo03:03:35

but let me see if it makes sense

oli03:03:54

that's good... otherwise i'd have no idea where you're getting values from simple_smile

bpicolo03:03:08

@oli added that too : )

oli03:03:53

try getting rid of vals...

bpicolo03:03:32

@oli that worked perfectly

bpicolo03:03:45

I was just copying the todomvc ;_;

bpicolo03:03:11

I get it now

bpicolo03:03:27

It's because they are k:v

bpicolo03:03:32

@oli you are the best ❤️

bpicolo03:03:54

pity that that function works at all on a vector

oli03:03:51

no prob. meanwhile I have this joy...

oli03:03:08

_ is not ISeqable

bpicolo03:03:00

Isn't transpiling great

cky03:03:29

@bpicolo: Looking at your Gist:

cky03:03:17

Handlers have parameters of the format [db [event-name & args]]. So unless you use the trim-v middleware, your parameters needs to add the event name.

cky03:03:41

i.e., [db [event-name text]] or [db [_ text]] in the case of your add-tag handler.

cky03:03:03

Or, you could just use the trim-v middleware.

bpicolo03:03:35

@cky: I was just hitting that issue 😄

bpicolo03:03:56

does that mean this is using middleware?

cky03:03:27

Most of the handlers there is using todo-middleware, which includes trim-v.

bpicolo03:03:03

cky do you recommend trim-v or explicit

bpicolo03:03:17

I'll make it explicit for now I suppose

cky03:03:29

Sure, whatever works for you. simple_smile

bpicolo04:03:58

now to figure out how to get event.target.value

bpicolo04:03:17

@cky where should I handle cleanup for events?

bpicolo04:03:30

actually, in this case it's trivial

bpicolo04:03:47

all works now, marvelous

johanatan06:03:31

is it possible to partially apply a javascript object method with its this?

johanatan06:03:02

e.g., from bunyan lib. want to do: (partial (.-info log) log)

johanatan06:03:06

[or something like it]

johanatan06:03:21

[also if I'm able to do that first step, can apply then operate on it? [bunyan logging methods want the args expanded inline but I will have a vector of them]

cjmurphy06:03:15

Does anyone know if Onyx works on Clojurescript? I saw some archived posts where that was mentioned as a possibility.

bwstearns07:03:46

Quick couple of questions: I want to use https://github.com/google/closure-compiler/blob/master/contrib/externs/maps/google_maps_api_v3.js in a luminous project. I've dropped it into `/target/cljsbuild/public/js/. Is that the right place for it and how do I properly import that into my core.cljs file to use it?

smw07:03:18

@bwstearns: You’re usually better off getting the dependency from clojars if you can...

smw07:03:11

Sorry, the second is what you wanted… not a wrapper, just the javascript in the right place with the ‘externs'

bwstearns07:03:04

@smw You're the best! thanks. New to clojure/cljs. I saw cljsjs earlier but I misunderstood what it was.

smw07:03:27

simple_smile I’m still pretty new too, hope it helps.

lucasbradstreet07:03:03

@cjmurphy: it doesn't work on clojurescript. There's nothing technically stopping it, but it would require a pretty big refactoring.

bwstearns08:03:06

has anyone run into something like: Uncaught TypeError: Cannot read property 'mount_components' of undefined? I think it's saying that myapp.core.mount_components is undefined, but it wasn't a while ago.

bwstearns08:03:23

does "extern only" mean that you don't explicitly import google maps cljsjs in the .cljs file where you're using it?

casperc08:03:17

Any hints on how to define how a type made with deftype prints with pr-str? In Clojure I am implementing a method on the print-method multimethod, but it seems to be different in Clojurescript unfortunately.

dialelo09:03:58

if you want to customize printing for your type

casperc09:03:51

@dialelo: Nice thanks alot. Cool book too, didn’t know about that one.

dialelo09:03:35

you're welcome! thanks for the kind words, we have to update some stuff and finish the project but we did it all in our spare time

casperc09:03:42

Wierd that it isn’t aligned between Clojure and Clojurescript though

dialelo09:03:00

yep, is one of the differences between Clojure and ClojureScript

casperc09:03:11

Ah, you’re one of the writers too? simple_smile

dialelo09:03:17

yes, me and @niwinz started the project and lots of people have contributed

martinklepsch09:03:20

@bwstearns: Google naps api files have to be loaded from their js server and because of that the cljsjs package can only provide the externs

martinklepsch09:03:01

I think you still need to require cljsjs/Google-maps though to ensure the externs are loaded for compilation

martinklepsch09:03:05

@dialelo: @niwinz wondering if you have investigated goog.Promise as underlying promise library for promesa... Would be curious to hear why you went with bluebird

niwinz09:03:32

is not about goog.Promise but the reasons are pretty the same

dialelo09:03:24

however, it shouldn't be too difficult to adapt goog.Promise for using it with promesa's API https://github.com/funcool/promesa/blob/master/src/promesa/protocols.cljc

daan09:03:13

question about Promesa for Clojure. When would I use that instead of Clojure's own promise, when developing in Clojure (not Clojurescript)?

niwinz09:03:32

@daan them ara pretty different and has different purposes. But the main difference is that the clojure promise and future has blocking api

niwinz09:03:21

promesa in CLJ uses CompletableFuture, that is highly composable and has proper async api.

dialelo09:03:33

it also gives you more control on how they run; you can provide your own j.u.c.Executor for running callbacks

dm309:03:09

is promesa compatible with manifold by any chance? I recall manifold extended CompletableFutures

niwinz09:03:43

Is not directly compatible, but is easy to make the promesa api work in the same way with manifold deferreds

daan09:03:26

@niwinz: when you say "composable", do you mean you can chain them in a way? Monad-like? That is what I sometimes miss in Clojure coming from Scala. To be able to map over promises and apply functions over the results without actually having to wait for the result.

niwinz09:03:21

you can chain them, apply function without waiting the result.

niwinz09:03:39

in fact, CompletableFuture has monadic api.

martinklepsch09:03:56

@dialelo: @niwinz thanks for the pointers will give it a try when I'll use promesia

dialelo09:03:27

you're welcome, happy to hear any feedback

nha11:03:08

Has anyone played with core.match and ClojureScript ? I would like to know if it increases the size of the output JS files. My understanding after reading the wiki it that it will generate efficient conditions code via a macro and not embed some kind of engine (therefore a reasonable size increase). Is that correct ?

achesnais13:03:59

I wonder, I'm using cljsjs/chartist, and the extern file only lists the most used functions. Would there be a specific reason the whole Chartist api isn't included, or is it just likely that whoever wrote it only included what they personally needed?

thheller13:03:12

@nha should be fine but be careful when using it inside core.async go blocks, that might lead to an explosion in size

thheller13:03:23

besides that yes it is all done in a macro, no engine

nha13:03:28

@thheller: Thanks simple_smile do you have a link as to why with core async it changes ? (just curious)

thheller13:03:37

not really related to core.match just a general thing with core.async in cljs

thheller13:03:02

since core.match might generate a bunch of nested if and such

thheller13:03:12

core.async doesn't deal well with that

nha13:03:43

Oh ok - so match should be fine for me simple_smile I am worrying about core async though now 😕

thheller13:03:47

no link, just a general obversation I made over the years 😉

nha13:03:56

Ok thanks for sharing simple_smile

thheller13:03:04

just keep your go blocks small

thheller13:03:12

move as much code into functions as you can

thheller13:03:22

keep only the concurrency related stuff in the go

nha13:03:35

ok thanks for the tip simple_smile

nha13:03:04

there is very little information about the size of libraries in cljs (I realise the closure compiler complicates things of course)

thheller13:03:16

don't worry about it for most cases 😛

nha13:03:29

Do you happen to have a workflow that allows to monitor the size ?

thheller13:03:43

size doesn't really matter too much due to the closure compiler

nha13:03:46

In my case I do care since part of it will be distributed as a js lib

thheller13:03:51

things that aren't used get removed

thheller13:03:17

not like normal js world 😉

nha13:03:19

right I get that - I just think that JS devs are more sensitive to size than we are generally

nha13:03:37

aha right well that's the thing for me ^^

thheller13:03:40

believe me I'm a size nazi

thheller13:03:01

I optimize more than I probably should

thheller13:03:11

but cljs + closure is just hard to beat

thheller13:03:17

it is close to perfect

nha13:03:38

Really good to know simple_smile (I heard about rollup.js as a new contender for size by the way)

thheller13:03:56

nah still won't come close

thheller13:03:19

they have to deal with too much undefined crap in the js world

thheller13:03:40

and nobody writes the strict style the closure compiler requires by hand

thheller13:03:54

cljs does that for us 😉

nha13:03:15

Perfect simple_smile even if it wasn't the case cljs brings other amawing things to the table

nha13:03:23

Thanks again !

thheller13:03:37

yeah it is pretty perfect simple_smile

darwin13:03:02

> and nobody writes the strict style the closure compiler requires by hand well, some google devs do, for example the chrome/webkit devtools team does

thheller14:03:13

well yes the closure lib is huge as well

thheller14:03:52

but still .. even most of the new stuff coming from google isn't written in closure style

slotkenov14:03:34

Is there something like https://github.com/technomancy/slamhound for ClojureScript?

daan14:03:07

Hi folks! I have a (maybe somewhat dumb) question about Figwheel. When I run lein figwheel in my terminal, it knows it has to pickup the dev build. How does it know that? And what happens when I add another build that uses Figwheel?

darwin14:03:21

you can specify builds via command-line: lein figwheel build1 build2 … (this works the same as lein cljsbuild), other option is to configure it via figwheel’s config in project.clj

daan15:03:05

I understand that, but I'm wondering how Figwheel understand to pick up my dev profile when I don't specify a profile on the command line at all

cjmurphy15:03:22

Is dev the first in your lein project file?

thheller15:03:24

my hguess would be that it picks all?

jannis15:03:26

Is there a recommended / idiomatic way of cancelling timeouts?

exupero16:03:11

@jannis If you’re using js/setTimeout, pass the returned value to js/clearTimeout.

jannis16:03:09

@exupero: Good point, why not just use the JS timeout instead of core.async's.

exupero16:03:41

Ah, didn’t realize you were talking about core.async. As far as I know you just use alts to circumvent a timeout and let it run out without effect.

cjmurphy16:03:14

With core.async you could use a little component system, might be overkill thou.

cjmurphy16:03:15

.. wish I knew how to make it take up less space 😞

exupero16:03:43

@cjmurphy: If you create it as a snippet, it’ll hide all but the first bit. You can edit the above post.

jannis16:03:50

Yeah, a component is definitely too much overhead 😉

jannis16:03:04

Background: this is a function that takes a time in ms and a callback and returns a function that collects callback arguments so the callback is only called once every X ms with all arguments provided in the current time window.

thheller16:03:39

@jannis sounds like you want to core.async alt! over one timeout and one channel that collects the arguments

thheller16:03:51

@cjmurphy: (async/close! poison-ch) instead of the put! would be more idiomatic

cjmurphy16:03:28

@thheller: Great thanks - I thought I might luck in and get some good feedback...

thheller16:03:37

(go-loop [count 0]
  (alt!
    (timeout 1000)
    ([_]
       (println "In timer at " count)
       (recur (inc count)))
    poison-ch
    ([v]
       (println "[printer-component] stopping"))))

thheller16:03:45

personally I like alt! in this case

jannis16:03:58

@thheller: That creates a loop that keeps running. What I am trying to go for is a one-shot-reschedulable argument-collecting timeout. If you don't call the collecting function at all, it never runs. If you call it once, it schedules the timeout once. If you call it twice with <X ms in between, it reschedules the timeout with the second call. If you call it twice with >=X ms in between, it schedules the timeout once for the first call and then a second time for the second call. Does that make sense?

cjmurphy17:03:30

That loop was just improving the code snippet a bit.

thheller17:03:58

you could use a transducer if you want to get really fancy 😉

jannis17:03:17

I sure do want to get fancy 😉

thheller17:03:44

but it would require using core.async and channels all the way

thheller17:03:50

doesn't sound like you want to do that

thheller17:03:15

ie. instead of calling a function you put something on a channel

jannis17:03:34

I'd be ok with it if it doesn't involve a permanent loop (unless it sits and waits most of the time) and if timeouts can be pushed back / rescheduled.

thheller17:03:10

oh wait you can't use a transducer

thheller17:03:26

well it'd be hacky as hell if you did

thheller17:03:29

so better not

pandeiro17:03:30

@darwin Any idea if chromex can be used with a figwheel/boot-reload-like live updating dev workflow?

richiardiandrea17:03:33

I have a question for integration testing with Phantom, in particular I would like to test reading (async Ajax fetching) served files

richiardiandrea17:03:51

Now I am using lein-doo but I saw that Phantom can act as webserver

richiardiandrea17:03:18

what is a good way to achieve this?

pandeiro17:03:25

@richiardiandrea I'd say that's not really the user case for phantom's built in server

pandeiro17:03:50

I'd use existing Clojure HTTP tooling

richiardiandrea17:03:13

@pandeiro: thanks for answering, so you would boot up a stand alone server for that right?

pandeiro17:03:14

Yeah definitely

darwin18:03:20

@pandeiro: chromex works with figwheel, except for content scripts

darwin18:03:52

See project.clj in chromex-sample

johanatan19:03:55

is it possible to partially apply a javascript object method with its this? e.g., from bunyan lib. want to do: (partial (.-info log) log) [or something like it] [also if I'm able to do that first step, can apply then operate on it? [bunyan logging methods want the args expanded inline but I will have a vector of them]

darwin19:03:25

@jonathan: you can use javascript’s .call or .apply to pass this

darwin19:03:56

(.call (.-info log) log …) or (.apply (.-info log) log (to-array extra-args))

johanatan20:03:43

so, the short answer is: ClojureScript's partial and apply only operate with ClojureScript functions?

cky20:03:26

@johanatan: You can also use it with JS functions that don’t care about the value of this. 😉

johanatan21:03:04

@darwin: @cky: here's the final version (pretty handy tool for anyone using bunyan): https://gist.github.com/johanatan/2e6540e9e3e198bac875

anmonteiro22:03:18

in Javascript, 46245 << 16 = -1264254976

anmonteiro22:03:47

in Clojure, (bit-shift-left 46245 16) = 3030712320

anmonteiro22:03:16

Is this related to JavaScript number precision being only 53 bits?

anmonteiro22:03:44

anyone know how I can get the same result in Clojure?

anmonteiro23:03:48

FWIW, the solution is: (unchecked-int (bit-shift-left 46245 16))