Fork me on GitHub
#re-frame
<
2020-10-27
>
Александр Стоянов00:10:53

Hello! I'm learning clojurescript now and have some problem: (def click-count (atom 0)) (defn b [] [:div "The atom " [:code "click-count"] " has value: " @click-count ". " [:input {:type "button" :value "Click me!" :on-click #(swap! click-count inc)}]]) in main-panel: (b) So that's almost work. I have button on my page but it doesn't refresh. First value is 0 and when i click on button value don't changes. It changes only when i clicked some times then re-build it and it shows quantity of clicks. So what i should do to refresh it without re-building?

p-himik00:10:29

Replace (b) with [b]. Unrelated things: - Your code has nothing to do with re-frame - it would be better to ask the question in #reagent - You can use triple backticks to create whole code blocks

p-himik00:10:36

If you use triple backticks as first and last lines of your code, you will get something that looks like this:

(defn x[]
  (println "x"))

Александр Стоянов04:10:47

Replacing doesn't help. What it may be else?

lsenjov06:10:41

You need to use a reagent/atom, not a cljs atom

lsenjov06:10:21

Oh, someone answered this in #reagent already, excellent

wdullaer13:10:06

would anyone have some recommendations to add syntax highlighting in a preblock in a reframe app?

joshkh13:10:55

i don't think that's re-frame specific, but you can checkout highlight.js https://ask.clojure.org/index.php/9068/how-to-use-highlight-js-in-a-shadow-cljs-project

joshkh13:10:40

the trick there is to call the highlight function after the reagent component has been rendered

joshkh13:10:32

and if you're using shadow-cljs then you can probably easily import this node module and use highlight js as a react component https://github.com/bvaughn/react-highlight.js/

seqable17:10:56

use :ref, then querySelectorAll on ref and doseq over resulting elems

kennytilton15:10:45

This seems like a simple problem for re-frame, but I am stumped. I want to determine if a field has changed when the user tabs off it, but not before. So if they make a change and then immediately change it back to what it was before leaving the field, I need to recognize that in its final form it is unchanged. Unfortunately, this is a "new item" form so I have no existing source of truth against which to compare. Is there a simple solution I am missing? Thx!

kennytilton15:10:21

I realize this in part an issue with ReactJS which always wants the form to correspond to app state, IIUC.

p-himik16:10:40

By "tab out", do you mean losing focus? If so, you can use the :on-blur event handler.

p-himik16:10:56

It's more related to Reagent/React/JS than to re-frame.

kennytilton16:10:28

Thx, @U2FRKM4TW! Yeah, I am in the on-blur to avoid the hyperactive on-change handler, but I cannot tell if we have a net change from any on-change events. Playing with a vanilla atom now, but it feels ugly. 🙂 Yep, definitely a React issue at bottom. I hear they are moving away from imposing their own events scheme, btw.

p-himik16:10:34

Ah, I see what you mean. Yeah, I think you will have to store the original value somewhere. Not necessarily an atom.

👍 3
mikethompson03:10:48

@U0PUGPSFR Can you dispatch the new value in the on-blur handler and then, in the event handler, compare that with the existing value? Ie. I'm assuming the existing value is stored in app-db ? (I fear I'm not understanding something important here)

kennytilton14:10:50

Yep, that is the way we are going. I just had a bug loading the prior value into app-db, and my re-frame is rusty enough that I thought the whole approach was in vain. We spotted the bug and are in good shape now. Thx! @U051MTYAB