This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-26
Channels
- # announcements (1)
- # babashka (106)
- # beginners (11)
- # biff (7)
- # calva (16)
- # clj-kondo (40)
- # clj-on-windows (5)
- # clj-yaml (10)
- # clojars (4)
- # clojure (37)
- # clojure-austin (22)
- # clojure-australia (1)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (10)
- # clojure-spec (6)
- # clojure-uk (6)
- # clojurescript (13)
- # conjure (11)
- # cursive (14)
- # datalevin (8)
- # datascript (5)
- # emacs (39)
- # events (1)
- # fulcro (55)
- # gratitude (4)
- # holy-lambda (2)
- # humbleui (9)
- # instaparse (1)
- # lsp (3)
- # malli (12)
- # meander (2)
- # membrane (7)
- # nbb (1)
- # off-topic (16)
- # pathom (9)
- # releases (3)
- # sci (14)
- # shadow-cljs (25)
Here is the code I'm trying to translate:
import Prism from "prism-react-renderer/prism";
(typeof global !== "undefined" ? global : window).Prism = Prism;
require("prismjs/components/prism-clojure");
I am trying to do it like this:
(ns ui-cards
(:require
[com.fulcrologic.fulcro.algorithms.react-interop :as interop]
[com.fulcrologic.fulcro.dom :as dom]
[nubank.workspaces.card-types.react :as ct.react]
[nubank.workspaces.core :as ws]
[nubank.workspaces.model :as wsm]
["prism-react-renderer" :default Highlight :refer [defaultProps]]
["prism-react-renderer/themes/github" :default _ :as theme]
["prism-react-renderer/prism" :as Prism]
["prismjs/components/prism-clojure" :as Clojure]))
(set! (. (if (exists? global)
js/global
js/window)
-Prism) Prism))
The resulting error:
main.js:1426 ReferenceError: Prism is not defined
at shadow$provide.module$node_modules$prismjs$components$prism_clojure (prism-clojure.js:3:1)
at shadow.js.jsRequire (js.js:66:18)
at shadow.js.require (js.js:113:20)
at eval (ui_cards.js:5:68)
at eval (<anonymous>)
at goog.globalEval (main.js:472:11)
at env.evalLoad (main.js:1534:12)
at main.js:1889:12
I can't use a require
call - it gives an error stating that the require must be part of the ns
form:
ns* not supported (require, require-macros, import, import-macros, ... must be part of your ns form)
The confusing thing is I can make it "work" by commenting out ["prismjs/components/prism-clojure" :as Clojure]
, building, and then uncommenting it and building again. It just doesn't survive a page refresh.
Any tip for how to get this working? Please excuse me if I'm missing this in the docs.
and finally see the translation examples provided here https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages
It is from the documentation here https://github.com/FormidableLabs/prism-react-renderer#user-content-faq (adding a language)
if that is the only language you need I'd recommend just writing that part in pure CLJS
I don't have a very good grasp on interop. Writing the definition is trivial, but how would I apply it so that Prism uses it?
not a clue but the prism-clojure.js files just assigs a property, so thats probably enough
Alright, I can try that. Strange that such a popular library is written in this way.
Indeed. The mess we're in :man-shrugging: Thanks for the advice, @U05224H0W 🙏