feat: Allow each extension to add a change handler. #7489
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
This is a draft PR for discussion; see notes below. Also still needs tests.
The details
Resolves
Originally posted by @BeksOmega in #7483 (comment)
Proposed Changes (and proposed next step)
Implement
Block.addOnChange
. Similar toBlock.setOnChange
but adds them to a list, and later calls them in the same order they were added.Block.setOnChange
is kept to preserve backwards compatibility, though some duplicate code could be merged. The handler set bysetOnChange
could always be called first (even if it was set later) for backwards compatibility.In practice, this means users can easily enforce the order when they fill the
extensions[]
list on the block specification.Reason for Changes
When a block already has an
onChange
handler, callingsetOnChange
from another extension currently overrides it.This makes it difficult to keep extensions small and local, i.e. an extension that deals with a field's final value as discussed in #7483, combined with some other extension on the block.
Similarly, it means
onChange
handlers can't easily be used with blocks that already use them internally, like those in block-shareable-procedures.Test Coverage
TBD
Documentation
TBD