milibopp / obsub

Small python module that implements the observer pattern via a decorator.
Other
12 stars 3 forks source link

support class based event subscription (?) #49

Closed coldfix closed 6 years ago

coldfix commented 10 years ago

Don't know if it is really useful, but I can think of a few instances, where it might have helped me out. For an example of what I am thinking about:

class Foo:
    @event
    def bar(self):
        pass

def baz(inst):
    print("baz: ", inst)

Foo.bar.connect(baz)
foo = Foo()
foo.bar()     # baz: <Foo object at ...>
DanielSank commented 10 years ago

So, hooking up through the class adds the observer to all instances?

coldfix commented 10 years ago

Yes, effectively that. It can be implemented with a separate class specific list as done here.