Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug with reactions 'firing' unnecessarily in 0.6.0 #277

Closed
yatesco opened this issue Nov 21, 2016 · 5 comments
Closed

Possible bug with reactions 'firing' unnecessarily in 0.6.0 #277

yatesco opened this issue Nov 21, 2016 · 5 comments
Labels

Comments

@yatesco
Copy link

yatesco commented Nov 21, 2016

posted originally in reagent google group

My understanding is that a reaction is memoised and only executes the body the first time it is derefed since any atoms or reactions it deref's have changed.

Given this, and the following code:

(def active-stage-headers (ratom/reaction .....)
 
(defonce old-stage-header-ids (atom [])) ;; - a "normal" atom, not a reagent.ratom/atom
(def active-stage-header-ids
  (ratom/reaction
   (let [result (mapv (comp :id :patient) @active-stage-headers)]
     (if (= @old-stage-header-ids result)
       (js/console.log "recalculating stage-header-ids SAME!")
       (js/console.log "recalculating stage-header-ids DIFFERENT!"))
     (reset! old-stage-header-ids result)
     result)))

I would never expect to see more than one "recalculating stage-header-ids SAME!", however I am seeing that message appear in an endless loop (in Chrome).

I do see the expected behaviour in other reaction 'chains'.

Is this a bug or have I misunderstood - thanks.

@ducky427
Copy link
Contributor

ducky427 commented Nov 21, 2016

@yatesco, reagent atoms/reactions behave markedly differently when inside a reagent component.

Have you tried the same using a reagent component?

@yatesco
Copy link
Author

yatesco commented Nov 21, 2016

Thanks @ducky427, that's interesting - I didn't realise this. Yes, both reactions are used independently inside components.

However, I still don't see that what I am doing (derefing a reaction inside another reaction) should cause that reaction to be fired over and over?

@yatesco
Copy link
Author

yatesco commented Nov 23, 2016

Can anybody at least confirm whether this is a bug or have I misunderstood something?

@Deraen Deraen added the bug label Oct 20, 2017
@atroche
Copy link

atroche commented Apr 28, 2018

I just tried this out on master, and when I deref'd it just printed this out once:
recalculating stage-header-ids DIFFERENT!

So maybe it's been inadvertently fixed?

@Deraen
Copy link
Member

Deraen commented May 4, 2018

Can't reproduce.

@Deraen Deraen closed this as completed May 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants