Fork me on GitHub
#portal
<
2023-06-04
>
Sam Ritchie15:06:16

@djblue what pattern would you recommend for passing configuration options to a viewer? I can guess here that the answer is “rpc!” but I wanted to check. katex supports a bunch of configuration options, like custom macros: https://katex.org/docs/options.html I can pass them in here, in this options map:

Sam Ritchie15:06:15

(defn get-opts []
  #js {:throwOnError false
       :displayMode true})

(defn tex [_]
  (let [opts (get-opts)]
    (fn [text]
      [:span
       {:dangerouslySetInnerHTML
        {:__html
         (k/renderToString text opts)}}])))

Sam Ritchie15:06:30

actually I’m not sure RPC call is the right way; I can figure that out, but I think I want to be able to take these options as arguments to my start! wrapper and supply them to the viewer

Sam Ritchie15:06:18

I love btw that with this {:on-load install!} flag you have, I can make changes to the viewers and reload the Chrome page and all changes are picked up

💯 1
djblue15:06:04

I think https://github.com/djblue/portal/blob/master/src/portal/ui/options.cljs#L33 is probably what you want but it isn't available to sci just yet :thinking_face:

Sam Ritchie15:06:03

yeah that sounds like it!

Sam Ritchie15:06:51

I would use it for mafs, for example, to let the user select the default theme vs the mafs theme

Sam Ritchie15:06:11

and for tex of course there are a bunch of options w/ the link above

djblue15:06:53

If you still have a copy of portal locally, you can quickly add it here https://github.com/djblue/portal/blob/master/src/portal/ui/sci/libs.cljs#L10

Sam Ritchie15:06:21

nice I’ll give it a try

Sam Ritchie15:06:50

I’m going to push today/tomorrow toward getting this all tested, documented and merged… I am taking the “get an enormous PR that does everything and then cut off tidy sections” approach

😂 1
djblue15:06:54

I would pull latest as well, you can pass in {:theme :portal.colors/zenburn} to open with a different theme:ok_hand:

🎉 1
Sam Ritchie19:06:42

@djblue so then I get access to all options that I’ve passed to p/open;

Sam Ritchie19:06:02

Do I have to wrap my component in with-options , or does portal do that for me?

djblue19:06:53

To get options, you just need to call the use-options hook

Sam Ritchie20:06:05

Yes for sure I was just wondering if I also have to call with-options to populate the context

djblue20:06:36

Gotcha, yeah context gets populated on app init here https://github.com/djblue/portal/blob/master/src/portal/ui/core.cljs#L44

❤️ 1
Sam Ritchie13:06:11

I accidentally passed :zenburn vs :portal.colors/zenburn and I kind of like the old macOS vibes!!

😂 2
Sam Ritchie13:06:45

@djblue works great!!

(def portal
  (p/start!
   {:emmy.portal/tex {:macros {"\\f" "#1f(#2)"}}
    :theme :portal.colors/zenburn}))
do you have opinions on a convention for passing options here? nested under :viewers, or without the key prefix, etc?

Sam Ritchie13:06:45

it might be nice to have a load-viewer or something that takes a namespace symbol and does this automatically:

(-> (io/resource "emmy/portal/tex.cljs")
    (slurp)
    (p/eval-str))

djblue19:06:24

I could see adding something like the following to portal.api:

(defn load-ns [ns]
  (p/eval-str (pr-str (list 'require ns))))

Sam Ritchie19:06:37

Oh nice is that enough, instead of my explicit slurp and eval-str?

djblue19:06:38

I think it would work, however, now you might need to specify :reload to re-require the ns :thinking_face:

djblue19:06:50

Maybe this instead:

(defn load-ns [& args]
  (p/eval-str (pr-str (conj args 'require))))

djblue19:06:21

Then you could (load-ns 'emmy.portal.tex :reload)

Sam Ritchie15:06:56

sorry to overshare here but this is nuts… I: • send out a Mafs chart using (of-x sin) • it renders and wraps itself in the appropriate (mafs/mafs (mafs/cartesian) …) shell • I then SELECT THE GRAPH in Portal, which makes the original fragment available via @portal • I can then build a new scene that includes @portal

(tap> (mafs/mafs
         (mafs/cartesian)
         @portal
         (mafs/of-y exp {:color :green})))

🙌 3