[Zope3-dev] Event service should adapt to ISubscriber
Steve Alexander
steve@cat-box.net
Thu, 23 Jan 2003 21:42:01 +0200
I'm working on a Zope 3 project.
I want to keep my implementation classes pretty free of zope3-isms. I
have my interfaces in package/intefaces.py, my implementation classes in
package/system.py, and I've encapsulated all zope3-isms into adapters in
package/adapters.py.
One class needs its instances to clear certain indexes when something
not directly related to it changes.
The clear way to do this is to use the Zope3 event service.
I need to get the instance hooked up to the event service after being
added, and unhooked from it on being removed. That's easily sorted with
an adapter:
class FooSystemSubscriptionAdapter:
__implements__ = IAddNotifiable, IDeleteNotifiable
def __init__(self, foo_system)
self.context = foo_system
def manage_afterAdd(self):
'See IAddNotifiable'
es = getService(self.context, 'Subscriptions')
es.subscribe(self.context, IFooEvent)
def manage_afterDelete(self):
'See IDeleteNotifiable'
es = getService(self.context, 'Subscriptions')
es.subscribe(self.context, IFooEvent)
I can register this adapter using zcml.
However, I still need to make the implementation class implement
ISubscriber so that it can be validly subscribed to the event service,
and can receive its events.
What I'd rather do is implement a specific method, like
_notifyFooChanged() in my pythonic implementation class, and make an
ISubscriber adapter for my class that will get notified of an IFooEvent,
and call _notifyFooChanged() on its context.
def notify(self, event):
'See ISubscriber'
if IFooEvent.isImplementBy(event):
self.context._notifyFooChanged(event.fooDetails)
I'd also like to make ISubscribingAware something that can be adapted
to, rather than the current situation where it has to be implemented by
the object being subscribed to an event service.
Any objections to this?
--
Steve Alexander