nextcore icon indicating copy to clipboard operation
nextcore copied to clipboard

Start using 2 Dispatcher classes

Open TAG-Epic opened this issue 2 years ago • 2 comments

Currently there is only 1 Dispatcher - The Dispatcher.

It has no specific typing except for the event name, other than that its *args: Any, **kwargs: Any which kind of makes sense for gateway opcode events & gateway DISPATCH events. (as manually filtering this yourself is stupid)

I don't have any specific ideas for improvement for opcode events and DISPATCH events, however for events nextcore produces, using vauge and dynamic typing is stupid.

I propose something like this (No clue about class name

d: Dispatcher2[EventType1, EventType2] = Dispatcher2()

@d.listen()
async def all_events(event: EventType1 | EventType2): # Or just realistically use typing.Any
    ...
@d.listen(EventType1)
async def one_event(event: EventType1):
    ...

This avoids reading typehints - which I do not want in this library, as it is "magic".

TAG-Epic avatar Mar 25 '23 22:03 TAG-Epic

What about calling the new dispatcher TypedDispatcher since it has more specific typing? Alternatively, the current dispatcher could be renamed RawDispatcher, but that would obviously be a breaking change.

EmmmaTech avatar Jul 17 '23 03:07 EmmmaTech

imo EventDispatcher is more accurate

TAG-Epic avatar Jul 17 '23 14:07 TAG-Epic