Fork me on GitHub
Oliver George03:04:25

I have 6 re-frame apps which share some common code. I'm looking for a nice way to define app specific constants which the common code references. I could put an atom in the common lib, have each app update the atom and common code could deref for the current value (perhaps there's a set!/var variant on that approach). I could have all the apps define the common.globals ns themselves and the common code could reference that ns. I can't see how goog-define can help and :preloads is for dev time only.


Having global config atom is fine, been doing this in multiple apps as well.

👍 4
Oliver George03:04:30

Am I missing a better approach?

Oliver George03:04:23

Having written that I think the common lib atom is probably the most sensible.


I'm using the re-frame template lein new re-frame frontend +10x +cider +routes +handler and the init function (exported) doesn't seem to be running at all. as a result app-db is empty. how do i have it run when clojurescript starts?


bah. i wasn't calling init in index.html. solved, thanks!


Anyone else getting this when working with re-frame-10x? Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. When this appears, re-frame-10x won't be able to load. sometimes, after refreshing, it goes away


It looks like updating state recursively causes new state update.


I'm turning a button into a spinner based on a flag, and the button's onclick dispatches something to change that flag. could that be it?


hi how can i run a js code when a react element loaded, i tried like thisb ut no luck ->

(defn main
   (for [x (range 22)] [pcard {:key x}])
      (.emitter js/window "some")


First: for is not meant for side effects, it's lazy and returns a sequence of values. Use doseq instead. Second: this code will be called on every update, unless you really want that you have need to use lifecycle methods such as component-did-mount so that the code runs only once, when component is "loaded"


thank you very much I solved the problem with your guidance. and yes i wanted to run this script on every update


Just to super clear on this. Using render in react for side effects is a bad idea even if you want it to happen on every render. As react moves to concurrent mode, this becomes and even worse idea. If your react wrapper supports hooks, look into use effects. If not look at lifecycle methods or your libraries recommended way to run side effects.


i try to run (.emitter js/window "some")


@m373h4n for returns a lazySequence, which is illeagal react element


what is window.emitter for you? Are you trying to emit an Event?