DEV Community

Discussion on: Vue: When a computed property can be the wrong tool

Collapse
 
linusborg profile image
Thorsten Lünborg

Thanks for the review. I fixed the example in your second point.

About the first point: It's not actually wrong in the place you thought, just an imrecise statement- the filter method would indeed not be run if the length of todos doesn't change - except if you would mutate the array with something like .reverse() or .sort().

But the example at the end of the article you refer to is indeed a copy-paste error from the initial example, so I fixed that to refer to openTodos.

Thanks again

Collapse
 
aantipov profile image
Alexey Antipov • Edited

I tend to disagree :)

const todos = reactive([
  { title: 'Wahs Dishes', done: true},
  { title: 'Throw out trash', done: false }
])

const openTodos = computed(
  () => todos.filter(todo => !todo.done)
)
Enter fullscreen mode Exit fullscreen mode

Reactive todos is deeply reactive, right?
So if you change "done" prop of any of the todos, then the computed openTodos will need to be reevaluated and rerun the filter method even though the length stays the same.

Thread Thread
 
linusborg profile image
Thorsten Lünborg

Argh. It's so hard to come up with good examples 😭

Yes you are right in this case - I wasn't really paying attention to what the filter did. 😬

Will see if I can change it to be more precise.