Fork me on GitHub
#clojurescript
<
2019-01-03
>
restenb13:01:15

anybody that can tell me what the correct interop would be for something like this $('.ui.sidebar').sidebar('show');

thheller13:01:11

(-> (js/$ ".ui.sidebar")
    (.sidebar "show"))

👍 10
restenb13:01:43

many thanks

Dante T. M.19:01:58

@restenb you have jQuery added to externs (or from cljsjs) already?

borkdude20:01:05

What’s the best way for writing a predicate to check if something implements the ILookup protocol?

cljs.user=> (satisfies? ILookup {:a 1})
true
cljs.user=> (implements? ILookup {:a 1})
true

borkdude20:01:57

probably satisfies?

mfikes20:01:03

Yeah, @borkdude implements? is really an internal thing

lilactown22:01:15

so I’m trying to write an app that interacts with some other bits outside of it’s code base. This seems to work when I’m testing it in a development build, but when I try and do a release build and put it on a page, it breaks:

(defn ^:export start! [node]
  (a/go-loop []
    (let [ev (a/<! (gobj/get js/window "PUNK_IN_STREAM"))]
      (println ev)
      (dispatch ev)
      (recur))))

lilactown22:01:50

lost the error, reproducing so I can paste it… it gives a fairly indecipherable error out the take on the channel

lilactown22:01:09

punk.js:10623 Uncaught TypeError: Cannot read property 'pop' of undefined
    at punk.js:10623
    at $JSCompiler_StaticMethods_cljs$core$async$impl$protocols$ReadPort$take_BANG_$arity$2$$ (punk.js:10632)

lilactown22:01:50

on the page I have another app that has this in it:

(gobj/set js/window "PUNK_IN_STREAM" (a/chan))

dnolen22:01:07

looks like a race condition to me

dnolen22:01:23

in your code

dnolen22:01:33

the fact that it works in dev is just getting lucky

lilactown22:01:41

hmm. I can’t imagine it yet.

dnolen22:01:49

the error is telling you there is no channel

lilactown22:01:52

I changed it to take the in-stream chan as an argument

lilactown22:01:07

(defn ^:export start! [node in-stream]
  (a/go-loop []
    (let [ev (a/<! in-stream)]
      (println ev)
      (dispatch ev)
      (recur))))

dnolen22:01:15

I would change the code to check in-stream before reading

lilactown22:01:11

(defonce in-stream (a/chan))

(def start-punk! (gobj/getValueByKeys js/window "punk" "ui" "core" "start_BANG_"))

(start-punk! container in-stream)

dnolen22:01:56

it does seem strange to me that you have to communicate via window var

dnolen22:01:04

instead of sharing a proper reference

lilactown22:01:18

yeah, I had other ideas but I changed it to passing a reference. same error

dnolen22:01:14

and you put a println in there to confirm you have a thing to debug this?

lilactown22:01:15

well, first I put a pre assert. I just added a println…

(defn ^:export start! [node in-stream]
  {:pre [(not (nil? in-stream))]}
  (println in-stream)
  (a/go-loop []
    (let [ev (a/<! in-stream)]
      (println ev)
      (dispatch ev)
      (recur))))

lilactown22:01:26

the println prints:

#object[Object [object Object]]

lilactown22:01:46

but this is in release, so maybe it’s not pretty-printing correct because of that?

lilactown22:01:02

could there be conflicts because I have two CLJS apps on the same page, one passing a channel to another?

lilactown22:01:48

in my second app, which is trying to use this release-built one, I have this:

(defonce in-stream (a/chan))

(println in-stream)

(def start-punk! (gobj/getValueByKeys js/window "punk" "ui" "core" "start_BANG_"))

(start-punk! container in-stream)

lilactown22:01:46

#object[cljs.core.async.impl.channels.ManyToManyChannel]       core.cljs:192
#object[Object [object Object]]                                punk.js:756

dnolen22:01:02

@lilactown you can't have two apps on the same page

dnolen22:01:05

nothing will work

😞 5
dnolen22:01:44

there can only be one build in the same JS context, period

lilactown22:01:22

so I have one app that has been built and released. I’m trying to use it on a page with another app, which I am developing

lilactown22:01:34

that’s a no-go?

dnolen22:01:55

that isn't completely true

dnolen22:01:05

but you have to really really know what you're doing

dnolen22:01:16

but ClojureScript isn't going to help you

lilactown22:01:29

I only have a single module

lilactown22:01:15

my built and released application otherwise appears to work, except that it can’t seem to accept this channel created by the second app

lilactown22:01:24

it’s kind of important that this first application be built separately from the second, since it’s meant to be a 3rd party application that in the future will utilize self-hosted CLJS. I don’t want to impart the burden of configuring that on the consumer

lilactown23:01:04

interestingly, passing in a map from the second (dev time) app to the first (released) app results in different printing behavior:

#object[Object {:foo "bar"}] ;; foreign map
{:baz asdf}                  ;; map created in the same build

lilactown23:01:19

and trying to do (:foo foreign-map) results in nil

lilactown23:01:38

I wonder if the way CLJS protocols operate is somehow scoped to the build they are produced in. so a CLJS data type created in one build does not seem to interop in another build

lilactown23:01:04

if so that pretty much destroys my application 😕

lilactown23:01:48

@dnolen what do you think?

lilactown23:01:48

this wasn’t really helpful at all @U11BV7MTK. I’m asking a specific question.

dpsutton23:01:07

i'm sorry. i wish i could help.

john03:01:29

I don't think self host does advanced build, right? So things might not get munged.

john03:01:00

But I wouldn't expect much to work between two different advanced compiled apps, unless you're passing thing via edn/transit

todo23:01:16

Has anyone managed to successfully mix Rust/Wasm32 + CLJS for web development? I'm looking for a model where the high performance / "foundational" code is written in statically typed Rust, with some API layer of structs / traits exposed -- then being able to interactively develop CLJS on top of this (via figwheel or the like).

lilactown23:01:41

haven’t done it, but I see a few libraries that might be interesting