Skip to content

Can't use the same listener with different filters #2

@corranwebster

Description

@corranwebster

In the events API you can't bind the same function callback to the same class with different filters. The actual behaviour is somewhat surprising:

from encore.events.api import EventManager, BaseEvent
em = EventManager()

def listener(event):
    print event.source

em.connect(BaseEvent, listener, filter={'source': 1})
em.emit(BaseEvent(source=1)) # prints 1
em.emit(BaseEvent(source=2)) # doesn't fire
em.connect(BaseEvent, listener, filter={'source': 2})
em.emit(BaseEvent(source=1)) # doesn't fire
em.emit(BaseEvent(source=2)) # fires twice, printing 2 each time

I think it is reasonable to have the same callback bound with two different filters; however even if it isn't then binding the same function with a different filter should probably remove the old function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions