Fork me on GitHub
#clojurescript
<
2020-07-28
>
phronmophobic00:07:38

@sova load-file in clojurescript doesn't seem right. what's wrong with require? I think the key is to remove any references in the cljc file to anything in the cljs file. is this project open source? it's hard to talk in the abstract about how to fix the dependencies

sova-soars-the-sora00:07:13

my main problem is that rum/defc is a macro that is used to define components for the serverside and clientside, but i cannot -- i don't know how -- import these variadic rum/defc component definitions. this pretty much makes the .cljc file useless in trying to be cljs/clj compatible. imagine the cljc file has a call

(rum/defc page-header [room-name]
  [:div room-name])
how would one import this .cljc result into a .cljs file?

sova-soars-the-sora00:07:34

if defn is there, you just use :require [vector of the functions] but if it's a custom macro, with a custom name... what to do

dpsutton00:07:15

Have you ever defined a component in a cljs file and then used it in another cljs file?

sova-soars-the-sora01:07:12

have never had the need, figured it would be possible if necessary, it's the exemplar use case for cljc and it doesn't seem to be possible

dpsutton01:07:57

How do you use the component? Presumably you just use a var that the macro interns

lilactown02:07:59

@sova I’m not sure I understand yet. vars defined by defc can be referred just the same as any other

lilactown02:07:32

ex if you have some namespace:

(ns my-app.feature
  (:require [rum.core :as rum]
   ,,,))

(rum/defc page-header [room-name]
  [:div room-name])
and then elsewhere,
(ns my-app.something-else
  (:require [my-app.feature :as feature :refer [page-header]]
   ,,,))

;; use the page-header here

lilactown02:07:43

that should all work. if not, there’s something wrong

😮 3
Vincent Cantin04:07:44

I found a difference between clojure and clojurescript:

(into nil nil)
; clj=> nil
; cljs=> ()

Vincent Cantin04:07:21

Is it to be expected or fixed?

penryu05:07:20

strange. I'm getting nil for both (clj 1.10.1, cljs 1.10.773)

Vincent Cantin06:07:25

I tested via Kaocha. I will test again tonight, manually.

Vincent Cantin06:07:28

I just tested via shadow-cljs and it returns nil. There must be something wrong with by kaocha setup.

Vincent Cantin15:07:31

The problem was Kaocha is using a version of CLJS by default which does not contain the fix to this bug. Not a problem related to the latest CLJS.

Vincent Cantin15:07:56

An easy fix was to add a dep to the latest CLJS in my project.

grounded_sage11:07:01

What is current best practice for cljs library development. When you also want a final artifact to be available on NPM for JS users. It obviously needs to be the minimum size possible. I’m assuming figwheel.main is the way to go??

thheller12:07:09

@grounded_sage those are really 2 completely separate questions. for CLJS lib you just publish the lib to clojars, no compiled code at all. lein works best IMHO. for npm you actually build the project and publish only the compiled code to npm, no sources. shadow-cljs has :target :node-library to make that easy. for figwheel I don't know, may require a bit more work. use :advanced to keep it as small as possible although small is relative given that it will contain a minimized version of cljs.core.

grounded_sage12:07:10

Cool. Yea I was wondering whether to move to tools.deps. Currently assessing between cljs.main, figwheel.main and shadow-cljs. Trying each of them out. Already familiar with shadow so seeing how the rest compare.

Sam Ritchie12:07:07

funny to see htis now, @grounded_sage -

Sam Ritchie12:07:18

I just wrote up a little guide for how to publish a namespaced dependency if cljsjs is slower to merge your PRs

thheller12:07:45

I don't think he is asking about cljsjs

Sam Ritchie12:07:59

ah, sorry, my eyes did a double-take at CLJS

Chris McCormick13:07:19

Hey all. I'm testing out node initializers and made this: https://github.com/chr15m/create-shadowfront Which you can use to very quickly bootstrap a Reagent application like this:

npm init shadowfront myapp
cd myapp
make watch
then browse to http://localhost:8000/ and http://localhost:9630/ Would appreciate any feedback!

thheller14:07:35

just did a quick glance. the template shadow-cljs.edn shouldn't have these two lines

Chris McCormick01:07:12

Fixed, thanks!

👍 3
sova-soars-the-sora15:07:14

@lilactown thanks a lot, i am now wondering how i can call the main socket-sending function in sente (chsk-send! [:event data]) from the cljc file. it seems like it operates as two separate instances if i simply replicate the code to .cjlc ... how can i have my socket sends from my ui work when moved to cljc land?

sova-soars-the-sora16:07:23

resolved. looks a little cray. but it works. moved the socket definition into the cljc with reader conditionals, and used refers to include them in the client.cljs it was not possible to use a let and nested defs, i had to explicitly make some keys happen

#?(:cljs    
   (def ma-sacket (sente/make-channel-socket-client!
        "/chsk" ; Must match server Ring routing URL
        ?csrf-token
        {:type   :ajax ;rand-chsk-type
         :packer :edn})))


#?(:cljs (def chsk       (:chsk ma-sacket)))
#?(:cljs (def ch-chsk    (:ch-recv ma-sacket))) ; ChannelSocket's receive channel
#?(:cljs (def chsk-send! (:send-fn ma-sacket))) ; ChannelSocket's send API fn
#?(:cljs (def chsk-state (:state ma-sacket)))   ; Watchable, read-only atom

sova-soars-the-sora16:07:52

that lives in a .cljc file and the functions are called by name so it's all groovy. thanks for your help everyone! @dpsutton @lilactown

gekkostate20:07:13

Hi all! Curious to know if people have ported their Clojurescript web app to re-natal (react native)? What was your experience in doing this? Our web app uses reagent and re-frame. My guess is that the logic would remain the same except we would have to change how the UI is rendered? Thanks a bunch for your help!

dnolen22:07:35

I think at this point shadow-cljs, figwheel, or krell (I work on it, still pretty alpha) are better options if you're going to do React Native - I think doing RN is a lot more effort than it sounds like - while the situation has improved greatly - I think you should expect to become familiar with some aspects Android / iOS development.

gekkostate23:07:54

I see, ok. Thankfully, we have some prior experience with Android but none with iOS. So, fingers crossed. I think we’ll try to port a small part first using shadow-cljs and see where it takes us. Thanks a bunch!

Vincent Cantin15:07:31

The problem was Kaocha is using a version of CLJS by default which does not contain the fix to this bug. Not a problem related to the latest CLJS.