Fork me on GitHub

Hello, Is there a way to dispatch reframe events from Javascript functions in the webpage? I would like to migrate to reframe an app I made that uses google maps. When you click on a markup in gmaps a javascript event function handler is called. I would like to know if there is a way to dispatch a reframe event from theses javascript functions. Thank you

David Pham04:07:25

You could write the handler in ClojureScript and export it.

👍 3

Wrap re-frame.core/dispatch in a function marked with ^:export.

👍 3

Can you easily construct keywords from js? And vectors? Or will js arrays work?


That wrapper can do that. And whatever else might be needed to bridge JS and re-frame.


JS arrays will not work because there's an explicit check for vector?.


Thank you for your answer


A non related question. Has anyone worked with reframe and I found some examples of integrating But I was wondering, given that reframe comes with its own react (from my understanding), if it was possible to tell reframe to use react-bootsrap instead of react or if that would lead to some unwanted conflicts? Thank you


re-frame doesn't come with its own React. re-frame uses Reagent, which requires React.


And react-bootstrap is just a library built on top of React. If you decide to use it, it will just use React that's already used in your project.


Ah ok. Thanks for clarifying @U2FRKM4TW


Its pretty easy to use react-bootstrap especialy if you use shadow-cljs to load the react and react-bootstrap npm libraries via the package.json. Something along the lines of:

(ns myapp.react-bootstrap
   [reagent.core :as r]
   ["react-bootstrap" :as rs]))

(defn adapt [component]
    (r/adapt-react-class component)
    (catch js/Object e
      (prn e.message))))

(def accordion        (u/adapt rs/Accordion))
(def accordion-toggle (u/adapt rs/Accordion.Toggle))
(def accordion-collapse (u/adapt rs/Accordion.Collapse))
(def alert (u/adapt rs/Alert))
...  Continue with all the react-bootstrap components you want to use

Then use them in your app
(ns myapp.view
   [reagent.core :as r]
   [myapp.react-bootstrap :as rb]))

(defn some-alert []
  [rb/alert {:variant "warning"} "It's a trap!"])
You can also use the react-bootstrap compoents inline with the :> similar to how they used react-markdown in