clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
zendevil 2021-04-10T01:59:16.056100Z

@lilactown any ideas?

lilactown 2021-04-10T02:18:11.056300Z

not without more info

lilactown 2021-04-10T02:18:27.056500Z

in the earlier form of this I think that the full error message was relevant

lilactown 2021-04-10T02:18:51.056700Z

JSON value '{
    nonceEnabled = 1;
    requestedOperation = 1;
    requestedScopes =     (
        "<null>",
        1
    );
}' of type NSMutableDictionary cannot be converted to ASAuthorizationAppleIDRequest *
you see requestScopes = ( "<null>" which isn't a valid member of the enum on the iOS side

lilactown 2021-04-10T02:19:04.056900Z

my best guess is you're still passing something incorrect to it

Timofey Sitnikov 2021-04-10T11:02:05.058600Z

Good Morning Clojurians, I am doing some cljs with shadow-cljs and my main.js file is 20 mega bytes and every time I update something it takes 30 seconds to re-compile, is that normal for cljs?

Timofey Sitnikov 2021-04-12T11:06:15.109600Z

@simongray my shadow-cljs.edn file:

{:deps   {:aliases [:dev]}
 :nrepl  {:port 9000}
 :builds {:main       {:target     :browser
                       :output-dir "resources/public/js/main"
                       :asset-path "/js/main"

                       :modules    {:main {:init-fn app.client/init}}
                       ;; guardrails checks only during dev
                       :dev {:compiler-options
                             {:external-config
                              {:guardrails {:emit-spec? true :throw? false}}}}

                       :devtools   {:after-load app.client/refresh
                                    :preloads   [com.fulcrologic.fulcro.inspect.preload app.development-preload]}}

          :test       {:target           :browser-test
                       :test-dir         "resources/public/js/test"
                       :ns-regexp        "-test$"
                       ;; static required for mocking to work
                       :compiler-options {:static-fns      false
                                          :external-config {:guardrails {:throw? true}}}
                       :devtools         {:http-port          8022
                                          :http-resource-root "public"
                                          :http-root          "resources/public/js/test"}}

          :ci-tests   {:target           :karma
                       :js-options       {:js-provider :shadow}
                       :compiler-options {:static-fns      false
                                          :external-config {:guardrails {:throw? true}}}
                       :output-to        "target/ci.js"
                       :ns-regexp        "-test$"}

          :workspaces {:target     nubank.workspaces.shadow-cljs.target
                       :ns-regexp  "-(test|ws)$"
                       :output-dir "resources/public/workspaces/js"
                       :asset-path "/workspaces/js"
                       :devtools   {:preloads           [com.fulcrologic.fulcro.inspect.preload]
                                    :http-root          "resources/public/workspaces"
                                    :http-port          8023
                                    :http-resource-root "."}}}}

p-himik 2021-04-12T11:09:23.110Z

@timofey.sitnikov If 20MB is the release build, then you can use this to understand what inflates the bundle: https://shadow-cljs.github.io/docs/UsersGuide.html#build-report

Timofey Sitnikov 2021-04-12T11:23:19.110200Z

No, 20 mb is development build.

p-himik 2021-04-12T11:23:56.110400Z

Then it's perfectly normal.

p-himik 2021-04-10T11:19:54.058700Z

Too few details. 20MB should be normal during development if you use a lot of and/or heavy third-party libraries (probably NPM). But it's not normal for a release bundle. 30 seconds is normal for a release build or for the initial debug build. It's not normal to wait 30 seconds for an incremental compilation step during watch.

1
simongray 2021-04-10T11:27:31.059100Z

try #shadow-cljs and post your shadow-cljs.edn file

2021-04-10T13:22:51.062400Z

Hi! I think I had confirmation that a dynamic import/require like in this example is not possible in CLJS (browser).

const app = document.getElementById('app');

render(
  <InertiaApp
    initialPage={JSON.parse(app.dataset.page)}
    resolveComponent={name =>
      import(`./Pages/${name}`).then(module => module.default)
    }
  />,
  app
);
Someone would have an idea of an alternative solution? I would like to avoid calling Reagent components one by one by hand and have the same level of automatism as in the example given.

2021-04-10T13:23:42.063Z

For now, here's how I do it.

(ns myreagent.core
  (:require ["@inertiajs/inertia-react" :refer [App]]
            [myreagent.pages.home :refer [Home]]
            [myreagent.pages.demo :refer [Demo]]
            [reagent.core :as r]
            [reagent.dom :as d]))

(def el (.getElementById js/document "app"))

(defn home-page []
  [:> App {:initial-page (.parse js/JSON (.. el -dataset -page))
           :resolve-component (fn [name] (r/reactify-component (case name
                                                                "Home" Home
                                                                "Demo" Demo)))}])

(defn mount-root []
  (d/render [home-page] el))

(defn ^:export init! []
  (mount-root))

p-himik 2021-04-10T13:47:37.063100Z

Module splitting, probably. But use it sparsely and only for isolated chunks of functionality. I.e. there's very little reason to split the main page with 10 panels into 10 modules if all the panels will be displayed at the same time unconditionally anyway.

Joseph Rollins 2021-04-10T14:36:52.064200Z

I'm having trouble using shadow-cljs. I have a basic build:

{:fn {:target :node-library
       :compiler-options {:infer-externs :auto}
       :output-to "functions/index.js"
       :exports-var functions.fn/exports}}
Yet it complains required namespace "functions.fn" is not available but I have src/functions/fn.cljs with:
(ns functions.fn
  (:require ["firebase-functions" :as functions]
            ["firebase-admin" :as admin]))

(defonce init (.initializeApp admin))

(defn echo [req res]
  (js/console.log req res))

(def exports
  #js {:echo (.onCall functions/https echo)})
I assume i'm missing something pretty trivial but I cannot figure it out. It was trivial -- I needed my file to be at src/main/functions/fn.cljs

1
2021-04-10T20:25:58.066100Z

Should't transit save metadata?

(write-transit (with-meta {:a 1} {:b 2}))
;; => "[\"^ \",\"~:a\",1]"
(meta (read-transit (write-transit (with-meta {:a 1} {:b 2}))))
;; => nil

alexmiller 2021-04-10T20:27:51.066300Z

no, transit does not preserve metadata

2021-04-10T20:27:57.066500Z

; (

alexmiller 2021-04-10T20:28:10.066900Z

it's designed to be language agnostic and that's not a feature generally available

djblue 2021-04-10T20:29:10.067400Z

You can add support to preserve metadata https://github.com/djblue/portal/blob/master/src/portal/runtime/transit.cljs#L32-L59 is how I did it

2021-04-10T20:29:11.067700Z

I found such a line in the code and I was convinced that it saves metadata https://github.com/cognitect/transit-cljs/blob/master/src/cognitect/transit.cljs#L195

djblue 2021-04-10T20:30:10.068Z

The key is :transform write-meta

2021-04-10T20:31:01.068200Z

thx!

alexmiller 2021-04-10T20:32:00.068700Z

looks like maybe the transit-clj / transit-cljs libs do have an optional transform for it

djblue 2021-04-10T20:33:39.069400Z

If you are also using transit-clj, watch out for this issue https://github.com/cognitect/transit-clj/issues/47

alexmiller 2021-04-10T20:33:53.069900Z

in transit-cljs, http://cognitect.github.io/transit-cljs/cognitect.transit.html#var-writer takes a :transform, and write-meta is an available transform

💯 2
alexmiller 2021-04-10T20:34:06.070300Z

so, I take it back, it does support it (if asked)!

2021-04-10T20:35:46.070800Z

@djblue already told me this solution in the thread

2021-04-10T20:35:48.071Z

awesome!

2021-04-10T20:36:39.071200Z

metadata is probably one of the most underrated feature

☝️ 1
djblue 2021-04-10T20:37:10.071500Z

Especially with how you can implement protocols via metadata!

2021-04-10T20:44:21.071700Z

I haven't tried this yet, but it sounds great.

djblue 2021-04-10T20:50:31.071900Z

It's particularly useful for implementing clojure.core.protocols/nav on your https://github.com/djblue/portal/blob/master/src/examples/hacker_news.cljc#L76-L80 which allows tools to help you navigate through your data.