Skip to content

Commit

Permalink
fix "ev" for all bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Mar 19, 2024
1 parent cfabbf0 commit d061cdd
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 46 deletions.
6 changes: 3 additions & 3 deletions htag/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ async def interact(self,oid,method_name:str,args,kargs,event=None) -> dict:
logger.info(f"INTERACT with METHOD {fmtcaller(method_name,args,kargs)}, of %s", repr(obj) )

if method.__name__=="__on_event__": # NEW
cbname=args[0]
cbname,*args = args
if asyncio.iscoroutinefunction( method ):
r=await method(cbname,event)
r=await method(cbname,event,*args,**kargs)
else:
r=method(cbname,event)
r=method(cbname,event,*args,**kargs)
elif method.__name__=="__on__": # previous new
obj._event=event or {}
if asyncio.iscoroutinefunction( method ):
Expand Down
10 changes: 5 additions & 5 deletions htag/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __str__(self) -> str:
raise HTagException("Caller can't be serizalized, it's not _assign'ed to an event !")
newargs = tuple([self._assigned]+list(self.args))

isEventBased = (inspect.getfullargspec(self.callback).args[-1] == "ev")
isEventBased = "ev" in inspect.getfullargspec(self.callback).args[:2] #in the first 2 parameters
if isEventBased:
bc=BaseCaller(self.instance,"__on_event__", newargs, self.kargs)
else:
Expand Down Expand Up @@ -408,17 +408,17 @@ def add(self, elt:AnyTags, reparent=False):
#===============================================================================
# Overriden methods
#===============================================================================
async def __on_event__(self,method_name:str,jsevent): # new mechanism > v0.100 (method with "ev" param)
async def __on_event__(self,method_name:str,jsevent,*a,**ka): # new mechanism > v0.100 (method with "ev" param)
""" really new mechanism (could replace self.bind.<m>()) ... one day"""
logger.info(f"callback __on_event__ {method_name} ")
caller = self._callbacks_[method_name]
for method,a,ka in [(caller.callback,-1,-1)] + caller._others:
for method,a,ka in [(caller.callback,a,ka)] + caller._others:
typevent=namedtuple("event", ["target"] + list(jsevent.keys()))
event = typevent( self, **jsevent )
if asyncio.iscoroutinefunction( method ):
r=await method(event)
r=await method(event,*a,**ka)
else:
r=method(event)
r=method(event,*a,**ka)

if isinstance(r, types.AsyncGeneratorType):
async for i in r:
Expand Down
38 changes: 0 additions & 38 deletions manual_new_ev.py

This file was deleted.

Loading

0 comments on commit d061cdd

Please sign in to comment.