Fork me on GitHub
#clojurescript
<
2020-04-15
>
lilactown02:04:22

seems weird. have you tried macroexpanding it in cljs?

Mitch Dzugan10:04:13

same error on attempting to macroexpand

Mitch Dzugan10:04:54

a full macroexpand fails but if I macroexpand-1 I get

(cljs.core/defprotocol MyProtocol (proto-method [b]))
which works fine if I then copy and paste that into my source. very odd

schaueho11:04:21

I could use a hand with understanding an issue with using cljsjs packages. I've now run the second time into an issue where I would like to use a symbol from the underlying package, but I just get an undefined error when I try.

schaueho11:04:36

Concretely: I require ["@date-io/date-fns" :as df] and then try to use df/DateFnsUtils, but this is apparently undefined.

schaueho11:04:53

Trying to use df/DateIODateFnsUtils also just gives an undefined.

schaueho11:04:05

I guess I simply don't understand cljsjs package usage.

thheller12:04:46

@schaueho those are just externs. they are meant to prevent :advanced compilation from renaming them. the df is all you need? meaning it should have all the properties you might need?

schaueho12:04:45

Sort of ... In the end I want to use a different JS lib, material-ui-pickers (date/time pickers) and this expects to be handed over this DateFnsUtils constructor. I guess it's ultimately calling other functions from date-fns internally.

schaueho12:04:07

when I compare the date-io.ext.js contents above with the ones for the material-ui package (which I use without issues), then the latter defines all the various components / functions etc. as properties.

schaueho12:04:29

but that of course doesn't help me with understanding what I have to do to use the @date-io/date-fns package.

Mitch Dzugan17:04:38

I created a small repo that demonstrates this issue: https://clojurians.slack.com/archives/C03S1L9DN/p1586906676023300 https://github.com/mitchdzugan/proto-fail This very simple macro

#?(:clj
   (defmacro defprotom [proto-name fn-name fn-args]
     `(~(macros/case :clj 'clojure.core/defprotocol
                     :cljs 'cljs.core/defprotocol) ~proto-name
       (~fn-name ~fn-args))))
fails only in clojurescript running lein test-cljs will demonstrate the failure. If you comment out the usage of the macro it prints the result of macroexpand-1 the same thing which is strange because if you take that result and put it back in the file the test will pass. Appreciate any help this has been stumping me for several days now.

Mitch Dzugan19:04:10

For some reason this worked

#?(:clj
   (defmacro defprotom [proto-name fn-name fn-args]
     `(~(macros/case :clj 'clojure.core/defprotocol
                     :cljs 'cljs.core/defprotocol) ~proto-name
       ~(clojure.core/list fn-name fn-args))))
not sure why but ill take it

Santiago17:04:14

anyone has a library to turn sentences like “every 2 weeks” into something useful to do math with? (e.g. would be a seq of dates of today + intervals of two weeks)

Santiago17:04:54

hehe I knew there had to be something out there nice thanks!

potetm17:04:55

channels are basically queues

potetm17:04:38

you cannot introspect them

Franklin17:04:17

the word introspect is a little confusing to me

potetm17:04:46

You cannot see what’s in them without calling take.

potetm17:04:13

You can’t even get the current length of a channel, much to my own frustration 🙂

Franklin17:04:49

are there situations where you can use these interchangeably?

potetm17:04:12

channels and atoms?

potetm17:04:23

not really, unless you’re using an atom as a queue

potetm17:04:30

which is kind of an abuse of atoms

Franklin17:04:46

mmmh... makes sense

bfabry18:04:29

you could implement your own buffer if you really wanted something that would tell you the current size. you'd be using things inside .impl. ns's though so no guarantee on forward compatibility

potetm17:04:55

they are used to convey values

potetm17:04:17

In clojure, mutable state (e.g. atoms) contains values

Franklin18:04:02

but @potetm if a channel is not a buffered channel, then i'ts not really a queue right?

Alex Miller (Clojure team)18:04:32

unbuffered channels do have space for a single value, there is no buffer. they require both producer and consumer to show up at the same time to transfer the value directly from one to the other (this is called a "rendezvous" in other systems)

Franklin18:04:13

because we can only have a single value it it

potetm18:04:21

it’s a very small queue

potetm18:04:14

Even unbuffered, they offer pretty much the same semantics. Most importantly, asynchrony.

Franklin18:04:19

cool... thanks simple_smile... I have some more clarity on that now

bananadance 4
Mark Bailey18:04:54

(defn main-content []                                                                                                                                                                                                                     73   [:div                                                                                                                                                                                                                                   74    [:p "What we offer"]                                                                                                                                                                                                                   75    [:ul (fn []                                                                                                                                                                                                                            76           (doseq [xs (site-content :offerings)]                                                                                                                                                                                           77             [:li (xs :heading)]))]])

Mark Bailey18:04:30

okay! thank you!

🍷 4
Mark Bailey18:04:20

@U08E8UGF7 so, updated, the code looks like

(defn main-content []                                                                                                                                                                                                                        [:div
    [:p "What we offer"]
    [:ul (for [xs (site-content :offerings)]
             (do
               [:li (xs :heading)]
               [:li (xs :desc)]))]])
and it is only displaying the heading

Mark Bailey18:04:36

or rather the description

Mark Bailey18:04:48

should i be placing those <li>s in a vec?

kszabo18:04:37

user=> (do
         [:li :missed]
         [:li :returned])
[:li :returned]

kszabo18:04:52

so this explains why heading is not rendered

kszabo18:04:12

as it is not in the hiccup data

kszabo18:04:27

you have to figure out how to have ‘fragments’ returned

❤️ 4
Mark Bailey18:04:41

fragments?? never heard of those, lemme head to google

kszabo18:04:43

which is more than a single element

Mark Bailey18:04:23

you, sir, or madame, are a godsend! thank you so much!!

Mark Bailey18:04:02

working as expected now!

kszabo18:04:23

Awesome, cheers 🙂

Mark Bailey18:04:34

so, i am trying to build a dynamic <ul> that adds <li>s according to a datastructure that I have in my website

Mark Bailey18:04:58

so far, after many many attempts, i still cannot get those <li>s to work

Mark Bailey18:04:31

(def site-content {:main-header "Love and Labradorite"                    
                       :tagline "Love and Labradorite"
                     :offerings [{:heading "Tarot Reading ($15 and up)"
                                  :desc "30 minutes and up. Minimum of six cards maximum of 10 on a subject that you require guidance on."}
                                {:heading "Intuition Reading with Spirit Guidance ($30 and up)"
                                  :desc "Do you need guidance about career, love, or any other topic going on in your life? I can give you a full reading with spirit guidance on how to handle your current situation. This is my custome\
    r favorite."}
                                 {:heading "Mediumship ($60 and up)"
                                  :desc "Connect to a passed love ones to receive messages and closure."}
                                 {:heading "Reiki Distance Healing  ($25)"                                                                                                                                                                                                   :desc "Reiki is non-invasive and is used holistically to restore balance in mind, body and spirit while promoting the body's regenerative self-healing ability. Its healing energy connects us on an ene\    rgetic and spiritual level where the healing work is conducted."}]})

Mark Bailey18:04:10

there is the data structure