Matching message attributes with "on" decorator, without using CSS selectors. #6145
aaronrudkin
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a message class which has a property called
mode
, which is a string that contains a mode switch. I do this because a widget is going to be passing a wide variety of messages to the parent and I don't want to create a billion different message classes (though, I recognize that I could). My sense was that the on decorator's kwargs argument should allow the on decorator to dispatch matching on this property.Thus the idea would be the parent app could have methods like the following:
The alternatives being, obviously, to have a single message catcher that dispatches with if-elif or a dispatch table inside the function, or else to have multiple message classes.
The reason this doesn't work is that the kwargs argument of the on dispatcher wants to parse the mode argument here as a css selector. Which makes sense if the object you're matching against is a widget, but less so if you think about the message as directly exposing the attributes you want to match on.
Any thoughts about an elegant way to do this? If the idea is that the on decorator is only going to match on selectors then I'll probably go back to using a dispatch table inside one message catching function.
Beta Was this translation helpful? Give feedback.
All reactions