Fork me on GitHub
#clojurescript
<
2016-02-13
>
raspasov01:02:26

hey guys - I got some strange behavior with the core.async promise-chan

raspasov01:02:50

only one (go ...) waiting on the promise-chan gets released at a time

raspasov01:02:56

in JVM Clojure the exact same code works correctly

isaac_cambron03:02:57

@raspasov: that’s the behavior i’d expect

isaac_cambron03:02:11

Why do you expect it to print two things?

raspasov03:02:36

@isaac_cambron: because I'm pretty sure those are the semantics of promise-chan

raspasov03:02:50

@isaac_cambron: also it behaves differently in Clojure vs ClojureScript

raspasov03:02:45

promise-chan function Usage: (promise-chan) (promise-chan xform) (promise-chan xform ex-handler) Creates a promise channel with an optional transducer, and an optional exception-handler. A promise channel can take exactly one value that consumers will receive. Once full, puts complete but val is dropped (no transfer). Consumers will block until either a value is placed in the channel or the channel is closed. See chan for the semantics of xform and ex-handler.

raspasov03:02:54

unless I'm totally blind and I'm missing something super obvious : )

isaac_cambron03:02:14

yeah, it’s possible that i’m the one misunderstanding promise channels, now that i look into it

raspasov03:02:24

I was trying to use it in React/Om to orchestrate some animations between components, basically have one promise-chan that gets passed to multiple components and they "wait" till one (and exactly one) value gets delivered to promise-chan by their parent

isaac_cambron03:02:03

Yeah, now that I’ve revised my understanding of promise channels, I agree with you and am thus no help 😞

niwinz09:02:08

I don't understand How I can use resolve or ns-resolve in macros for cljs. Them does not works in the same way as in clojure 😞

niwinz09:02:45

For the same usage in clj it returns a proper var and in the cljs it returns always nil (independently if I'm using resolve or ns-resolve.

kauko12:02:42

(defn get-from-both [symbol] [foo/symbol bar/symbol])

kauko12:02:53

Is something like this possible in clojurescript? Or clojure for that matter?

kauko12:02:23

resolveand ns-resolveseem like they'd have something to do with this

mfikes15:02:01

@niwinz: Well, in regular ClojureScript, the macro is executed in Clojure. If you are willing to opt into bootstrapped ClojureScript in order to gain this, then it can be done building atop cljs.js. Here is an example in Planck, FWIW:

cljs.user=> (ns foo.core)
nil
foo.core=> (def a 3)
#'foo.core/a
foo.core=> (in-ns 'cljs.user)
nil
cljs.user=> (require '[planck.core :refer [ns-resolve]])
nil
cljs.user=> (let [sym (ns-resolve 'foo.core 'a)]
       #_=>  (prn sym)
       #_=>  (prn @sym))
#'foo.core/a
3
nil

niwinz15:02:55

thanks @mfikes in my case is regular cljs

mfikes15:02:59

@kauko: If you are willing to bring in cljs.js, then you can build things that do that: https://gist.github.com/mfikes/7342d6321868d4fc4a3d

kauko15:02:23

wait, what do you mean by cljs.js? Isn't that the javacript libraries packaged for clojurescript -thingy?

mfikes15:02:20

No… (sorry, it is an overloaded set of 6 characters). I’m referring to the API namespace for accessing bootstrap ClojureScript capabilities.

mfikes15:02:33

@kauko: So, I’m essentially saying that if you are willing to bring on a decent amount of complexity and additional generated code size, give up on certain optimizations, it is possible. simple_smile

kauko15:02:00

Ah, right

mfikes15:02:04

(Depend on your use case, how much you need it, etc.)

kauko15:02:15

Well, I don't need it that much simple_smile

kauko15:02:30

I'll just have a function with the signature [thing thing] instead of just [thing]. No big deal.

rauh17:02:01

It seems like doing a core.async put! in the middle of a CLJS file (not in function but right in the global scope) prevents the code that follows the put! to be run. Has anybody had this problem?

alpheus17:02:34

Where should I report a bug in the tutorial at https://github.com/omcljs/om/wiki/Remote-Synchronization-Tutorial -- I've got a patch that fixes it.

alpheus17:02:19

The wiki says "don't edit"

echristopherson19:02:43

@mfikes What does that mean, exactly? It uses the JVM Clojure for macros? >in regular ClojureScript, the macro is executed in Clojure.

virmundi19:02:58

hello. I've got a rather odd case. In chrome extensions there are two environments that a javascript should file may find itself. This is mostly around which chrome specific apis are available at a time.

virmundi19:02:39

The background execution has access to an object named webRequest. The content script lacks such an object.

virmundi19:02:25

My problem is that the monolithic js file gets loaded into both. This causes the content script to fail loading.

virmundi19:02:43

How can I get around this?

potetm19:02:11

@echristopherson: cljs is (usually) AOT-compiled into js. This means that macros are expanded by cljsbuild (which runs on the JVM).

virmundi19:02:47

no, I'll try now.

virmundi19:02:29

perfect. So simple. Thanks

chrisoakman19:02:52

no problem, also check that gist again. There is exists? which might be more idiomatic for this use case.

virmundi19:02:59

I was afraid I'd have to get into externs and interops.

settinghead19:02:07

is there a way to use .css files from a CLJSJS package in a leiningen project?

settinghead19:02:04

can’t seem to find any documentation on that

richiardiandrea19:02:14

@settinghead: from my experience there is no (easy) way to do in in lein, but boot provides a sift task for moving around files (and it is actually what cljsjs uses for generating packages)

mfikes19:02:01

@echristopherson: Yeah, what @potetm said. But, getting more to the point, consider

(ns foo.macros)

(defmacro resolve-it [ns sym]
  (str (ns-resolve ns sym)))
You can evaluate (foo.macros/resolve-it clojure.core inc) which will expand to "#'clojure.core/inc”. So, ns-resolve works, but it is executing in Clojure. If you try to remove the wrapping str call, then you are going to get an error
No method in multimethod 'emit-constant' for dispatch value: class clojure.lang.Var
Which further reinforces the idea that the macro is expanding in Clojure to a JVM object, which is then passed to the ClojureScript compiler for JavaScript emission, which it can’t do. The bigger problem is that, since ns-resolve is running in Clojure, there is no way it can resolve symbols in your ClojureScript code.

virmundi19:02:23

should (js->clj o) create a clj map for a javascript object? I tried that but still can't use (:url as-map)

chrisoakman19:02:17

@virmundi: by default, (js->clj x) converts JavaScript Object keys to string, not keywords. You can pass (js->clj x :keywordize-keys true) to recursively convert the string keys to CLJS keywords

virmundi19:02:39

Chris comes through again!

chrisoakman20:02:07

or leave the keys as strings and use (get clj-x "url") (although keywords are easier to read / use)

echristopherson20:02:42

what does it do with ES6 symbols?

dnolen20:02:24

it doesn’t handle them, but there’s a protocol for handling more stuff

dnolen20:02:35

js->clj and clj->js are convenience helpers only useful for small amounts of data, if they can be avoided I would

juhoteperi21:02:43

@settinghead: You can serve the files from cljsjs using Ring or you could use a Lein plugin which can read files from classpath and compile Less or Sass files to CSS (my less4clj and sass4clj projects implement this)

settinghead21:02:47

@juhoteperi: thanks. i’ll take a look