Fork me on GitHub
#reagent
<
2018-01-04
>
sggdfgf15:01:32

hi, can I run custom script on :component-did-mount (possibly by a <script> tag)

sggdfgf15:01:26

like [:script "window.klipse_settings = {selector: '.language-klipse'};"]

juhoteperi15:01:49

@faxa Why wouldn't you just run the same code on the lifecycle method?

sggdfgf15:01:18

I dont know how 😄

juhoteperi15:01:30

:component-did-mount (fn [_] (set! (.-klipse_settings js/window) #js {:selector ".language-klipse"}))

sggdfgf15:01:29

@juhoteperi that is very great, thanks!

sggdfgf15:01:55

how can I output <script src="http://app.klipse.tech/plugin/js/klipse_plugin.js"></script> in the same function?

juhoteperi15:01:58

Dynamically loading scripts is not very common practice with Cljs or React... but you could do it the same way as in JS: http://unixpapa.com/js/dyna.html just write the same code in Cljs

sggdfgf15:01:52

actually I try to embed this into my reagent application, https://github.com/viebel/klipse just very hard to glimpse how to do it

curlyfry15:01:16

@faxa You have an index.html somewhere in your project, right? I'd probably just stick the script tag there if possible.

sggdfgf15:01:38

@curlyfry It just worked - thanks 😉