Events
======

The Component Architecture provides a way to dispatch events to event
handlers.  Event handlers are registered as *subscribers*
a.k.a. *handlers*.

Before we can start we need to import ``zope.component.event`` to make
the dispatching effective:

  >>> import zope.component.event

Consider two event classes:

  >>> class Event1(object):
  ...     pass

  >>> class Event2(Event1):
  ...     pass

Now consider two handlers for these event classes:

  >>> called = []

  >>> import zope.component
  >>> @zope.component.adapter(Event1)
  ... def handler1(event):
  ...     called.append(1)

  >>> @zope.component.adapter(Event2)
  ... def handler2(event):
  ...     called.append(2)

We can register them with the Component Architecture:

  >>> zope.component.provideHandler(handler1)
  >>> zope.component.provideHandler(handler2)

Now let's through the events.  We'll see that the handlers have been
called accordingly:

  >>> from zope.event import notify
  >>> notify(Event1())
  >>> called
  [1]

  >>> del called[:]
  >>> notify(Event2())
  >>> called.sort()
  >>> called
  [1, 2]
