Get the previous value of a cell when it's edited and saved

We can use this when the cell is re-evaluated, but when the cell is edited it’s null. See

You can’t. (At least, not directly…)

this is cleared when you edit the code because code can be changed in arbitrary ways, and often it does not make sense to access the previous value. Also, clearing the value of this after editing more closely matches the behavior of your notebook on a fresh load, increasing the likelihood that the state of your notebook is deterministic and consistent with what your readers will see; if we didn’t set this to be undefined after editing, we’d need some other mechanism (some other user interface control) to clear the state of a cell.

In general, using this should be treated with the same amount of caution as using mutable or side-effects. Which is to say: it’s better if you can avoid it, and stick with pure definitions.

What are trying to accomplish?

1 Like

I totally understand.

I’ve tried to describe what I want to accomplish in this notebook.

I was hoping there might be some kind of event that I could listen to that catches the previous cell value before it’s cleared. Or anything else that might to the trick. I guess It would need to be set up from the definition of adot template literal tag. I don’t want to add extra cells to the notebook that calls it.