Learn how reactivity works in Plot notebooks
.sample()
allows reading a signal value without subscribing to its changes:
value
and value_str
are obviously related. The delayed updates ensure that the relationship is preserved at all times—cell 2 will never trigger an AssertionError
.
Contrast this with a hypothetical system that applies updates immediately.
cell_print 30 2
, cell_print 11 40
; which could be printed in an immediate-update system.
value
changes to 50
, the cell will execute the conditional and thus access and subscirbe to value_str
.
If necessary, the cell can always uncoditionally subscribe to a signal by just accessing its value and not using it:
del
:
locals()
:
x = Signal(initial)
defines a new signal with value set to initial
x()
reads the value of the signal and subscribesx(10)
sets the value of the signalx.sample()
reads the value of the signal without subscribing. Useful to avoid infinite update loops