Fork me on GitHub
#clojurescript
<
2018-05-13
>
jco09:05:27

I'm making a small Sokoban game in ClojureScript (using re-frame), and I want some way of "simulating" cursor key movement on a touchscreen. I.e. I want an event to trigger when the player presses the left part of the screen etc... Do I need to create some big overlapping divs, or are there other ways?

dominicm11:05:04

In traditional js ,this is done by having event bubbling/propagation, allowing the window handler to have an event on it. http://www.javascripter.net/faq/eventbubbling.htm might be useful.

Dormo09:05:00

@zalky That's how interop is done in Clojure/Clojurescript, no? I've only seen and used the first way. I've never seen nor used the second way.

Dormo09:05:59

I'm trying to use an existing React component with Reagent. Unfortunately, I'm having some trouble getting it loaded. In my page template:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ReactPlayer.js"></script>
    {% script "/js/app.js" %} 
(`app.js` being my transpiled clojurescipt, the tag above being the react component) As you'd expect, the React component depends on React, but React is not defined when it's loaded, so it errors.

Dormo09:05:16

What would a solution be?

Dormo09:05:22

Would making a cljsjs package solve this?

Pontus10:05:51

@vheuken I'd recommend shadow-cljs for using js libraries in clojurescript. Here's a good gist if you want to evaluate more options: https://gist.github.com/jmlsf/f41b46c43a31224f46a41b361356f04d

jumar10:05:51

Is Code Splitting something that is often used in larger ClojureScript applications? I got a question about it in a Clojure workshop but since I (mostly) don't do UI stuff I didn't have a good answer. My first reaction was that perhaps when we have advanced Google Closure compiler we mostly don't need it. Are there any gotchas when you actually want to use it?

gklijs11:05:53

@jumar I Just heared a defn about https://github.com/thheller/shadow-cljs and it has better support for it. For a pet project I have two builds, one for a visitor and one for an editor. I did it by having component-like structure, and call the units of the needed components in either the editor or visitor main.

jumar11:05:50

Great, thanks for sharing.

Dormo11:05:15

@pontus.colliander I have a mixed Clojure and Clojurescript codebase, though

Dormo11:05:09

Thanks for the link

Dormo11:05:06

:foreign-libs looks promising

gklijs11:05:31

Mixed content should not be a problem for shadow-cljs loading the cljc/cljs sources should work the same.

Dormo11:05:23

So it can be a total replacement for lein?

Dormo11:05:47

I have everything setup nicely with lein so moving over to shadow-cljs makes me nervous

Dormo11:05:31

Oh, I think you misunderstood

Dormo11:05:40

I mean I have a JVM Clojure server

Dormo11:05:57

It's just Clojurescript on the frontend

Dormo11:05:28

Would you suggest keeping lein for the former and moving to shadow-cljs for the latter?

Dormo11:05:25

Two build tools sounds like it'd really complect my setup.

dominicm11:05:55

I think it can also run inside lein

Dormo11:05:18

I guess I'll look into it.

Dormo11:05:09

This seems like a good route. Thanks!

Dormo11:05:23

One more question: does it play nicely with figwheel or do I have to totally move over to shadow-cljs?

dominicm11:05:53

shadow replaces figwheel

Dormo11:05:55

looks like the latter...I'll try to make it play nicely but if it's an uphill battle i'll give up

Dormo11:05:59

Ah. Cool.

dominicm11:05:13

The #shadow-cljs group is pretty useful too btw 🙂

👍 4
zalky12:05:55

@vheuken: if you mean (.AutoReplace js/SlateAutoReplace args...) then I agree that is the more common form, but it is equivalent to ( js/SlateAutoReplace.AutoReplace args...). Neither works, where (.default js/SlateAutoReplace args...) does. There's something I don't understand about how export default is effecting the extern. Incidentally, I recall a blog post specifically about loading ReactPlayer in Leiningen: http://blob.tomerweller.com/reagent-import-react-components-from-npm . Might be an alternative if you don't want to bring in shadow-clj.

yen13:05:31

Does anyone have any expreience using core.logic in clojurescript?

Dormo13:05:52

Oh, my mistake.

souenzzo14:05:47

I think that it's a problem of #core-async with #js tag

dnolen14:05:20

try js-obj

👍 4
souenzzo14:05:31

It's inside a go block js-obj, clj->js works I think that it's a issue with async/go and # js

Bravi22:05:45

I’m trying to use a package from cljsjs (to be more specific cljsjs/sortable). I’ve added the package to my dependencies and I’m importing in my namespace as instructed but it immediately throws an error and the error is not that helpful unfortunately. is there anything else I need to add to my config?