Fork me on GitHub
#clojurescript
<
2022-11-11
>
jpmonettas14:11:07

Hi all! I'm getting an error when trying to evaluate the macroexpanded form of defrecord at the repl. On clojurescript if I (macroexpand '(defrecord ARecord [n])) and look for the ->ARecord fn definition it looks like (cljs.core/defn ->ARecord [n] (new cljs.user/ARecord n nil nil nil)) where it calls the ARecord constructor with 4 args (I imagine for meta, extension map, etc) . But if I try to eval that constructor at the repl like this (new cljs.user/ARecord n nil nil nil) it fails with Wrong number of args (4) passed to cljs.user/ARecord What am I missing here?

pez15:11:22

Hi ClojureScriptians! We have a reagent+re-frame application where we want to let content (stuff loaded from the server) get control over the page, add and remove things from the DOM. The application is being ported from a PHP+jquery version, where the content could do this manipulation using javascript/jquery. What would happen if we let jquery loose on a react controlled DOM? Anti-matter forms? If so, is there some way we can give the jquery scripts some handle to the react components enabling peaceful co-existence? I'm also thinking that if we used reagent via scittle maybe that could work better than jquery for the requirement? Please share any ideas around this you might have. 🙏

👍 1
isak15:11:19

Yea if you want to have both react and jquery controlling the same dom components, I expect that will cause problems. But are you able to isolate it? It isn't a problem to have other components inside of react. Here is an example from the documentation: https://day8.github.io/re-frame/Using-Stateful-JS-Components/

isak15:11:32

Or you could do the inverse, mounting react many places in certain DOM nodes instead. But having both libraries modify the same piece of the DOM I don't think will work.

Lone Ranger15:11:34

form-3 components is the typical answer, although the dynamically loaded code is an interesting twist

isak15:11:51

> If so, is there some way we can give the jquery scripts some handle to the react components enabling peaceful co-existence? I have done this before with plain react and a class component. I think you just save the result of 'React.createElement', and that is the component instance you can call methods on. I haven't done it with re-frame, but I guess you could export namespace-level functions from the CLJS side instead.

pez15:11:39

Thanks! ❤️ I'll have to unpack the suggestions here and will do some experiments.