mobx icon indicating copy to clipboard operation
mobx copied to clipboard

Reaction reacting to all changes in an array instead of just its length

Open mshibl opened this issue 9 years ago • 1 comments

I have an issue with Reactions, I just realized that the following code reacts to any changes in the todos array (ex. changing the title), I was expecting it only to change in response to changing the length of the array:

reaction(
  () => ({length: this.todos.length}),
  (length) => {console.log('something changed')}
)

I'm not sure if this is a bug or if it's the intended behavior? if it's the intended behavior, then how do I get a more fine grained control on the observables that trigger a reaction.

Please note that the reason I returned an object from the first function, is that I have other observables (unrelated to todos) besides length that I want to track.

I'm using mobX 2.5.1

mshibl avatar Apr 12 '17 01:04 mshibl

Turns out I had a syntax error

mshibl avatar Apr 12 '17 02:04 mshibl