Fork me on GitHub
#reagent
<
2017-07-12
>
fedreg14:07:35

Hi all, I find myself doing lots of (let [index (:index @state/app-state)]) statements in my reagent app. Is there some sort of global alias I can use to define these at the top level? Something like (def index (:index @state/app-state))? thx!

pesterhazy14:07:55

no but you can use a cursor

ajs15:07:09

I'm new to reagent but I suppose a reaction set up to access that property could also be elegant?

pesterhazy08:07:49

yup, though IMO r/track and r/cursor have sort of superseded using raw reactions

ajs08:07:25

good to know, most tutorials I've seen focus on reactions over cursors, claiming cursors are less useful or more problematic. but i suppose all of this is moot if you are using re-frame

pesterhazy14:07:19

(def !index (r/cursor !app-state [:index]))

pesterhazy14:07:28

then use @!index to deref

pesterhazy14:07:51

an additional benefit is that components get rerendered more selectively

pesterhazy14:07:23

by the way I use the exclamation mark to mark "dereffables"

fedreg14:07:39

@pesterhazy Thx! Looks like what I need. Will have to read up on cursor a bit. Thanks again!

pesterhazy14:07:02

remember, you need to deref (use @) in the component you want rerendered when the dereffable changes

ajs15:07:09
replied to a thread:no but you can use a cursor

I'm new to reagent but I suppose a reaction set up to access that property could also be elegant?

mattgeb22:07:46

Trying to translate some Props from a React component. Not sure what to do with references like "this"

class WebcamCapture extends React.Component {
  *setRef = (webcam) => { this.webcam = webcam* ; }

mrchance23:07:05

Hi! I am trying to use react-codemirror via

(defonce code-mirror-component (js/require "react-codemirror"))
(defonce code-mirror (reagent/adapt-react-class code-mirror-component))

(defn editor [state]
  [code-mirror {:value @state
                :on-change #(reset! state %)}])
It works, but it doesn't update when I reset! state, only on fighweel reload. Any ideas why?

mrchance23:07:40

I'm on electron, in case you're wondering about the require...

juhoteperi23:07:10

@mrchance Is state a Reagent atom?

mrchance23:07:21

@mattgeb maybe the this-as macro can help there?

mrchance23:07:33

In fact I tried this:

[:div
 [editor my-state]
 [:div @my-state]
 [button {:on-click #(swap! my-state str "f")} "Append"]]
the div updates, the editor doesn't...

mrchance23:07:48

If I move the dereference out of the fn, it's the same as well

mrchance23:07:54

I am really confused

mrchance23:07:47

I can also type in the editor to reset the state, which is reflected in the div as well Oo

mattgeb23:07:07

@mrchance Ooh, thanks! I'll give that a try.