这个 Observablehq 例子中的 "invalidation" 是什么?

What is "invalidation" in this Observablehq example?

https://observablehq.com/@d3/force-directed-lattice?collection=@d3/d3-drag

有一行

invalidation.then(() => simulation.stop());

这个失效是什么? console.log,这是一个承诺,但我没有看到它在任何地方定义。

Observablehq 加载 standard library, which provides the invalidation 方法。根据文档,invalidation 是...

A promise that resolves when the current cell is re-evaluated: when the cell’s code changes, when it is run using Shift-Enter, or when a referenced input changes.

本笔记本详细解释:https://observablehq.com/@observablehq/invalidation