Change signal routing for increased consistency #2277
Merged
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.
It was recently brought to my attention that signal routing between blueprints and apps could be confusing depending upon where signals were registered.
For example, in the following case, dispatching
my.signal.two
from the app only works if it is also defined in the app. While this is not exactly a bug, and how it was intended to perform, it is a little confusing and the pattern does not really make sense to have to couple your definitions.Similarly, if you have a catch all
my.signal.<foo>
, it is difficult to knowingly predict if it will be executed if you also have a finite signal defined matching the namespace/context pair.Therefore, this PR does two things:
extra
, which is not needed since the actual matching happens outside of the router to allow for multiple handlers to be executed. Previously, this was used to force the routing into a dynamic state.One thing that needs to be thought through on this still is the breaking change this imposes.
The methog
app.signal_router.get
returns a tuple of(group, handlers, params)
. The list of handlers was what would be dispatched.With this change,
handlers
in the routerget
is not determinative. You still need to run through the dispatch since the change is to loop over signals in dispatch and not the getter. I left the signature as is, but it no longer will retrieve the proper handlers.An alternative is to set more context on the handler function (like
handler.__requirements__
). I would like to avoid this if we can, but it might be a cleaner solution since it would allow for theget()
method to continue without a breaking change.Still todo:
events
being set in the_dispatch
method are done properly according to the new matching requirements