# Reactives, timed events and updating vis

**URL:** https://talk.observablehq.com/t/reactives-timed-events-and-updating-vis/402
**Category:** Uncategorized
**Created:** [February 22, 2018, 1:52pm UTC](https://talk.observablehq.com/t/reactives-timed-events-and-updating-vis/402 "2018-02-22T13:52:06Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)
#### Post date: [February 22, 2018, 9:23pm UTC](https://talk.observablehq.com/t/reactives-timed-events-and-updating-vis/402/2 "2018-02-22T21:23:45Z")

</div>

Hey Simon,

Here’s a forked version that addresses your concerns:

[https://beta.observablehq.com/@jashkenas/visualisation-of-contact-networks](https://beta.observablehq.com/@jashkenas/visualisation-of-contact-networks)

The best way to separate initialization from updating, within a cell, is to rely on `this`. In an Observable notebook, [`this` is the previous value of the cell](https://beta.observablehq.com/@tmcw/untitled/5). So, for a cell that is a D3 SVG visualization, `this` is `undefined` the first time the cell runs, and can be the running SVG visualization on every cell re-evaluation thereafter.

Using `this`, and Mike’s reference for modifying a force layout: [https://bl.ocks.org/mbostock/1095795](https://bl.ocks.org/mbostock/1095795)

… you wind up with a cell that reuses its own svg element, force simulation and link list, and can restart the simulation when the list of links changes.

As for the playable slider, I’ve relied on the slider’s value as the mutable source of truth, and have a little playloop as an [asynchronous generator](https://beta.observablehq.com/@mbostock/introduction-to-asynchronous-iteration) that updates the slider’s value before waiting two seconds to proceed.

There are other ways to glue this together, but this seemed like the easiest one that required minimal-ish changes to your code.

Let me know if you have any questions!

---

_[View the full topic](https://talk.observablehq.com/t/reactives-timed-events-and-updating-vis/402)._
