Methods as event handlers not called?
See original GitHub issueIt seems that event handling methods on custom components are not called. It seemed only natural (given the function signature) and useful to have methods as method handlers.
This code illustrates the problem:
import justpy as jp
class MyInlineHello(jp.Div):
def __init__(self, **kwargs):
self.counter = 1
super().__init__(**kwargs)
self.classes = 'm-1 p-1 text-2xl text-center text-white bg-blue-500 hover:bg-blue-800 cursor-pointer'
self.text = 'Inline Hello! (click me)'
async def click(self, msg):
print('In INLINE CLICK handler')
self.text = f'Hello! I was clicked {self.counter} times'
self.counter += 1
self.on('click', click)
class MyMethodHello(jp.Div):
async def click(self, msg):
print('In METHOD CLICK handler')
self.text = f'Hello! I was clicked {self.counter} times'
self.counter += 1
def __init__(self, **kwargs):
self.counter = 1
super().__init__(**kwargs)
self.classes = 'm-1 p-1 text-2xl text-center text-white bg-orange-500 hover:bg-orange-800 cursor-pointer'
self.text = 'Method Hello! (click me)'
self.on('click', self.click)
def hello_test():
wp = jp.WebPage()
for i in range(5):
wp.add(MyInlineHello()) # or jp.Hello(a=wp)
for i in range(5):
wp.add(MyMethodHello()) # or jp.Hello(a=wp)
return wp
jp.justpy(hello_test)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
c# - Event handler not firing on class method - Stack Overflow
From my (winforms, c#, . net 3.5) UI form, I'm trying to get the received message(s) back to the UI. If I call...
Read more >Non Aggregate @EventHandler methods are not getting called.
Hi All, I am facing strange issue, i have same @EventHandler method with same event class in Aggregate and in non Aggregate class,...
Read more >Event listeners not working? 3 key areas to troubleshoot
Are your event listeners not working as you'd expect? Here are 3 key areas to troubleshoot to help you get everything triggering as...
Read more >Handling and Raising Events | Microsoft Learn
These delegates have no return type value and take two parameters (an object ... The following example shows an event handler method named...
Read more >4 Working with Event Handlers (Release 8)
This method takes the event type and the handler as arguments. In Example 4-1, the first handler is added to a single node...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That construct defeats the purpose of simplicity and I’d be hesitant to use it for fear of not understanding my own code after a few months 😉 If normal methods would be possible one would get the ‘self’ reference for free. As it stands now I’ll stick to the inline version
this had the advantage of simplicity and still have acces to self (if one uses another name than self for the first arg).
Thank you, and keep the suggestions coming!