Fork me on GitHub
#clojurescript
<
2017-12-19
>
hlolli01:12:47

any alternative to this pattern (new (type {}) 1) where you construct a new type based on the return value of type?

(deftype MyType [val])
(def a (new MyType 1))
(new (type a) 2)
=> cljs.core.type.call is not a constructor

phronmophobic01:12:39

@hlolli, for collections, you can use empty

hlolli01:12:43

ahhh ok! I see now what IEmptyableCollection is for. thanks @smith.adriane

mfikes03:12:13

An interesting example of that is if you compare (empty (first {:a 1})) in ClojureScript and Clojure.

mfikes03:12:07

Perhaps this may lead to things changing some day: https://dev.clojure.org/jira/browse/CLJS-2013

mikerod03:12:00

Interesting

justinlee03:12:41

Does anyone use cljs-devtools? The docs say that I should enable customer formatters in Chrome but I don’t see that option in Chrome 63.

Jakub Holý (HolyJak)09:12:18

Maybe they are now on by default, or moved elsewhere in the ui?

justinlee17:12:49

I’m still getting the warning that its not on.

Jakub Holý (HolyJak)18:12:20

I still see the option in Ch 63 (OS X) - dev tools settings - Preferences - section Console

justinlee19:12:27

I must be looking at the wrong thing. I’m clicking on the gear in the console tab of devtools.

Jakub Holý (HolyJak)20:12:12

As mentioned in the other thread that is indeed wrong :)

qqq05:12:31

my current dev setup is: client side: cljs + boot-reload server side: jvm + clj + nrepl + cider I am considering changing server side to: nodejs + cljs + ... is there still a way to get a repl here ? I have heard lumo/planck mentioned a bit. Does anyone have a working setup I can copy/paste ? @seancorfield @tbaldridge [ moved to #clojurescript ]

tbaldridge05:12:46

I did brew install lumo and did lumo and I have a repl

tbaldridge05:12:57

but I guess, what's the point of moving away from the jvm?

qqq05:12:17

$ lumo
Lumo 1.1.0
ClojureScript 1.9.456
 Docs: (doc function-name-here)
 Exit: Control+D or :cljs/quit or exit

cljs.user=> 
hmm, I have a repl now too 🙂

tjscollins06:12:04

I've got a baffling question related to using spec in clojurescript. I've got the following code:

tjscollins06:12:34

(defprotocol parse-dates
  (parse-date [date] "Convert date to formatted string")
  (parse-datetime [date] "Convert date-time to formatted string")
  (parse-date-at-time [date] "Convert date-time to formatted string w/ word 'at' between date and time"))


(s/fdef parse-date
        :args (s/cat :date (s/alt :string :webtools.spec.dates/date-str
                                  :date-time :webtools.spec.dates/date
                                  :nil :webtools.spec.core/nil))
        :ret :webtools.spec.dates/date)

(s/fdef parse-datetime
        :args (s/cat :date-time (s/alt :string :webtools.spec.dates/date-time-str
                                       :date-time :webtools.spec.dates/date
                                       :nil :webtools.spec.core/nil))
        :ret :webtools.spec.dates/date)

(s/fdef parse-date-at-time
        :args (s/cat :date-at-time (s/or :string :webtools.spec.dates/date-at-time-str
                                         :date-time :webtools.spec.dates/date
                                         :nil :webtools.spec.core/nil))
        :ret :webtools.spec.dates/date)

#?(:clj
   (extend-protocol parse-dates
     java.lang.String
     (parse-date [date] (format/parse const/date-formatter date))
     (parse-datetime [date] (format/parse const/date-time-formatter date))
     (parse-date-at-time [date] (format/parse const/date-at-time-formatter date))
     
     org.joda.time.DateTime
     (parse-date [date] date)
     (parse-datetime [date] date)
     (parse-date-at-time [date] date)

     nil
     (parse-date [date] nil)
     (parse-datetime [date] nil)
     (parse-date-at-time [date] nil))

   :cljs
   (extend-protocol parse-dates
     string
     (parse-date [date] (format/parse const/date-formatter date))
     (parse-datetime [date] (format/parse const/date-time-formatter date))
     (parse-date-at-time [date]
       (-> (clojure.string/replace date #"at" "")  ;; Workaround for bug in cljs-time handling of 'at'
           (clojure.string/replace #"\s+" " ")
           (parse-datetime)))
     
     function
     (parse-date [date] date)
     (parse-datetime [date] date)
     (parse-date-at-time [date] date)

     object
     (parse-date [date] date)
     (parse-datetime [date] date)
     (parse-date-at-time [date] date)

     nil
     (parse-date [date] nil)
     (parse-datetime [date] nil)
     (parse-date-at-time [date] nil)))

tjscollins06:12:28

If I comment out the specs, it works. If I leave the specs in (which work correctly in Clojure), it dies and gives me cryptic error messages that are no help.

tjscollins06:12:06

Any ideas what's wrong with the specs?

mv09:12:33

Hey, I’m trying to use a JS lib that makes heavy use of promise chaining. What’s the best, most cljs way of using a library like that? I’m fairly new, but I assume core.async is the recommended tool?

thheller10:12:57

@mv core.async doesn’t use promises. native interop is just fine, don’t need a library

Alex Miller (Clojure team)13:12:45

core.async has promise-chans

thheller16:12:47

I know, but we were talking about “trying to use a JS lib that makes heavy use of promise chaining” which promise-chans do not interface with. they act promise like but are still channels.

mv10:12:24

I’m trying to find examples of promises, but everything keeps pointing me to Promesa. Adding another lib doesn’t seem necessary

thheller10:12:47

(-> the-promise
     (.then do-something-cool)
     (.then do-more))

mv10:12:38

Ah I see

thheller10:12:50

or just (.then (fn [val] ...)) while (defn do-something-cool [val] ...)

thheller10:12:43

.then just takes one function arg for “resolve” and another for “reject” if you want it

mv10:12:12

What about async/await, is there a tool for that in cljs?

thheller10:12:02

async await is also just syntax sugar for promises. core.async would be that sugar for CLJS but no not for promises themselves.

thheller11:12:18

I’m using core.async most of the time and very rarely native promise interop when I have to. Never needed promesa but I am aware of it.

mccraigmccraig11:12:58

i'm the other way around - lots of promises with a touch of core.async for operations on streams of values

romain13:12:44

@qqq If you target nodejs, you can check #macchiato

Jakub Holý (HolyJak)17:12:47

Please let me know if it is inappropriate but eould like to share an article I have written about an experience that demonstrated to me, and hopefully also to others, the productivity gains one can get from ClojureScript compared to JavaScript. Feedback welcome, and feel free to share! http://techblog.telia.no/blog/experience-awesome-productivity-with-clojurescript-s-repl/

dnolen18:12:22

@tjscollins I’m assuming you can narrow what you’re trying so you don’t see a bunch of failures and only the ones that matter?

dnolen18:12:51

thanks for sharing

jacekschae20:12:56

Also not sure if this is appropriate to share it here: turns out that CLJS is approximately three times smaller (LoC) vs Elm when implementing the same app https://medium.freecodecamp.org/a-real-world-comparison-of-front-end-frameworks-with-benchmarks-e1cb62fd526c. Once again thanks to @danielcompton for the re-frame implementation.

justinlee20:12:23

@U8A5NMMGD FYI the link to “CLJS re-frame” in that article just links to the github homepage

jacekschae20:12:55

thanks @U8ES68TGX just corrected that

smw21:12:37

Good afternoon! I'm trying to adapt https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules to actually render in the browser. However, if I modify the :require stanza here:

(ns example.core
  (:require [react :refer [createElement]]
            ["react-dom/server" :as ReactDOMServer :refer [renderToString]]))
and change "react-dom/server" to "react-dom", I get:
java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "react-dom"
Is this known behavior? Is there some way around it?

smw21:12:46

Checking for the presence of a slash?

bronsa21:12:10

make sure you're using the latest cljs version

smw21:12:41

I am. Running 1.9.946 from cljs.jar downloaded from releases on github.

smw21:12:20

java -cp cljs.jar:src clojure.main build.clj
No lein or other abstractions that might make which version I'm using unclear.

smw21:12:33

And the example as given does work, it renders to a string in the console. It's just that I'm not able to modify it to require "react-dom" instead of "react-dom/server"

noisesmith22:12:17

@smw have you tried changing it to react-dom without the string? perhaps it only accepts those strings that would be illegal as args to require

briantrice23:12:41

What’s an idiom to invoke an npm-aligned module like https://github.com/iamdustan/smoothscroll ? note that the intended call path is require('smoothscroll-polyfill').polyfill(); (although I could call window.__forceSmoothScrollPolyfill__ = true; if I stage that statement before the require)