===========
Observables
===========

This document not only demonstrates how to use observables, it also
shows how they interact with the ZODB persistence machinery.

``Chicken`` is a persistent and annotatable class.  We add an instance
to the database by placing it in the root folder:

  >>> from zope.app.container.contained import setitem
  >>> root_folder = getRootFolder()
  >>> setitem(root_folder, root_folder.__setitem__, u'chicken', Chicken())
  >>> get_transaction().commit()
  >>> chicken = root_folder['chicken']

Now consider a possible subscriber for an object event:


Now we register it using the observable adapter:

  >>> from zope.app.observable.interfaces import IObservable
  >>> from zope.app.event.interfaces import IObjectModifiedEvent
  >>> observer = IObservable(chicken)
  >>> observer.handle([IObjectModifiedEvent], chickenModified)
  >>> get_transaction().commit()

When we now issue an ``IObjectModifiedEvent`` event, our subscriber
will be called:

  >>> from zope.event import notify
  >>> from zope.app.event.objectevent import ObjectModifiedEvent
  >>> notify(ObjectModifiedEvent(chicken))
  buh-PAH! I was modified.
