skip to navigation
skip to content

GreenRocket 0.1

A simple implementation of Observer pattern via Signals

Latest Version: 0.30

Green Rocket is a simple implementation of Observer (or Publish/Subscribe)

design pattern using Signals.

Create specific signal from base class:

>>> from greenrocket import Signal
>>> class MySignal(Signal):
...     pass

Subscribe handler:

>>> @MySignal.subscribe
... def handler(signal):
...     print('handler: ' + repr(signal))

Fire signal:

>>> MySignal().fire()
handler: MySignal()

Note, that signal propagates over inheritance, i.e. all subscribes of base signal will be called when child signal fired:

>>> @Signal.subscribe
... def base_hadler(signal):
...     print('base_handler: ' + repr(signal))
>>> MySignal().fire()
handler: MySignal()
base_handler: MySignal()

Unsubscribe handler:

>>> MySignal.unsubscribe(handler)
>>> MySignal().fire()
base_handler: MySignal()

Any keyword argument passed to signal constructor becomes its attribute:

>>> s = Signal(a=1, b=2)
>>> s.a
>>> s.b
File Type Py Version Uploaded on Size
GreenRocket-0.1.tar.gz (md5) Source 2013-02-28 3KB