Fork me on GitHub
#clojurescript
<
2019-04-21
>
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.

roman01la08:04:03

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.

ackerleytng07:04:48

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?

ackerleytng07:04:24

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

ackerleytng09:04:36

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

metehan17:04:56

It looks like updating state recursively causes new state update.

ackerleytng14:04:26

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?

metehan16:04:41

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

(defn main
  []
  [:div#products.product-grid.dragarea
   (for [x (range 22)] [pcard {:key x}])
      (.emitter js/window "some")
   ]
  )

roman01la06:04:01

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"

metehan11:04:27

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

jimmy15:04:55

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.

metehan16:04:53

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

hlolli23:04:03

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

hlolli23:04:22

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