# Mutable values with multiple setters "bounce" forever

**URL:** https://talk.observablehq.com/t/mutable-values-with-multiple-setters-bounce-forever/560
**Category:** Uncategorized
**Created:** [March 26, 2018, 9:48pm UTC](https://talk.observablehq.com/t/mutable-values-with-multiple-setters-bounce-forever/560 "2018-03-26T21:48:13Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)
#### Post date: [March 26, 2018, 10:40pm UTC](https://talk.observablehq.com/t/mutable-values-with-multiple-setters-bounce-forever/560/2 "2018-03-26T22:40:07Z")

</div>

Hello! The problem here is a circular definition:

```auto
{
  if (p !== mutable p_value) {
    mutable p_value = p;
    viewof p.input.p_value = p;
    viewof p.dispatchEvent(new CustomEvent("input"));
  }
}

```

The above cell references _p_ and _viewof p_, so it will run whenever either of those change. But it also sets the value of _p_ (indirectly) by dispatching an _input_ event on _viewof p_. And, it sets _mutable p\_value_, which triggers _viewof p_ to be re-initialized, because _viewof p_ depends on _p\_value_.

You should avoid circular definitions. I’d delete the _mutable p\_value_ cell and instead use only `viewof`. Make _viewof p_ the sole definition of the value of _p_, rather than trying to synchronize a view and a mutable. Here’s a short notebook showing how to mutate a view such as a slider from other cells:

> **[Mutating Views](https://observablehq.com/@mbostock/mutating-views)**
>
> An Observable notebook by Mike Bostock.

Alternatively, you could use a custom view as your definition of _p_. Here’s my notebook on custom views:

> **[Views are Mutable Values](https://observablehq.com/@mbostock/views-are-mutable-values)**
>
> An Observable notebook by Mike Bostock.

With a custom view, both the slider and the buttons would be considered “secondary” views: they would mutate the primary view, and listen non-reactively to the main view for value changes.

---

_[View the full topic](https://talk.observablehq.com/t/mutable-values-with-multiple-setters-bounce-forever/560)._
