I'm writing a full-stack app with a lot of .cljc files, I I frequently find myself doing a lot of dialect-conditional requires:
#?(:cljs [reitit.frontend :as rf])
#?(:cljs [reitit.frontend.controllers :as rfc])
#?(:cljs [reitit.frontend.easy :as rfe])
Fine but a little verbose. I'm wondering if there's any way to pass multiple forms for the :cljs key? Something like:
#?(:cljs [reitit.frontend :as rf]
[reitit.frontend.controllers :as rfc]
[reitit.frontend.easy :as rfe])
?Not really, unless you want to have separate I think the real solution to this problem is to use more libraries that are cljc compatible. If you have a lot of conditional requires, I'm sure you have equally lots of reader literals throughout your code. That kind of undermines the power of cljc in my mind.:require for clj and cljs.
Isn't there an unquote-splicing version of the reader conditional?
I don't know how to use it bc I avoid CLJC but pretty sure it's documented in the http://clojure.org guide on reader conditionals
(ns demo.dummy-cljc
(:require
[foo.all]
#?@(:cljs
[[reitit.frontend :as rf]
[reitit.frontend.controllers :as rfc]
[reitit.frontend.easy :as rfe]])))this works. bit ugly, but works an can have :clj branch as well. foo.all is example for require that is done in all variants in case you have something common
Ah, right! My first thought was something along these lines, then I couldn't remember it and thought I'd hallucinated it 🙈
Thanks @thheller, that does the trick.
I am trying to get mui-tiptap to run I keep getting this error react-dom.development.js:12056 Uncaught RangeError: Adding different instances of a keyed plugin (plugin$) From what I understand its because the text-box or the extensions keeps getting loaded hence the the defonce, key, and the mounted logic to try and stop it Any ideas?
imports
[reagent.core :as r]
["mui-tiptap" :as MuiTiptap]
["@tiptap/starter-kit" :as TiptapStarterKit]
(def rich-text-editor
(r/adapt-react-class
(or (.-RichTextEditor MuiTiptap)
(.-default MuiTiptap))))
(defonce starter-kit-extension
[(.configure
(or (.-StarterKit TiptapStarterKit)
(.-default TiptapStarterKit)))])
(defn tiptap-editor []
(let [editor-ref (r/atom nil)
mounted? (r/atom false)]
(r/create-class
{:display-name "tiptap-editor"
:component-did-mount (fn []
(reset! mounted? true))
:reagent-render
(fn []
(when @mounted?
[:div {:style {:border "1px solid #ccc"
:padding "10px"
:border-radius "4px"
:color "black"}}
[rich-text-editor
{:editor-ref editor-ref
:key "rte"
:extensions starter-kit-extension
:content "<p>Please show up</p>"}]]))})))
[:div [tiptap-editor]]
I'd just check what's going on with a debugger. Find where the error is originally created/thrown and break right before the associated check to see what exactly goes down that code path.
Hi, looks like it's not related to reagent. You could try to reinstall/update all peer dependencies of mui-tiptap
It looks like it was an existing bug with an underlying library I swapped to https://github.com/niuware/mui-rte and seems to work. Thanks