That context
does indeed look redundant to me. show-footnote.update(false)
itself doesn’t change when context is provided, and the it
(at least as fas as footnote
is concerned) contains its own context
. In any case, for the context
you removed to matter, it would have to come after the update:
show-footnote.update(false) + context it
Well, the proposed fix is unfortunately an instance of a common antipatttern regarding state updates; see Why is State Final not "final"? - #2 by SillyFreak. If I had to guess, other people testing this (including @Adrian_Weitkemper) have only one or two such footnotes in their document, and you at least four or five. I’d say that it probably disappears if you only have three or fewer footnotes like this. If that’s the case, I think it would be valuable for you to point it out in the issue (if you have a Github account).
The original reason for using
let origin-value = show-footnote.get()
...
show-footnote.update(origin-value)
Is to reset the value correctly even if you don’t know the previous value:
show-footnote
starts as true- you enter
clean-footnote
, it should be false in there - you exit
clean-footnote
, now it should be true again
but what if you call clean-footnote
inside clean-footnote
? then the inner one should not set show-footnote
back to true! Thus the use of the antipattern.
One solution is to use a stack for the state:
let show-footnote = state("show-footnote", (true,))
let clean-footnote(it) = context {
show-footnote.update(stack => (..stack, false))
it
show-footnote.update(stack => stack.slice(0, -1))
}
This way the previous state is preserved inside the state instead of in a layout iteration.