skip to navigation
skip to content

Not Logged In

GreenRocket 0.1

A simple implementation of Observer pattern via Signals

Latest Version: 0.20

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
1
>>> s.b
2
 
File Type Py Version Uploaded on Size
GreenRocket-0.1.tar.gz (md5) Source 2013-02-28 3KB
  • Downloads (All Versions):
  • 13 downloads in the last day
  • 54 downloads in the last week
  • 323 downloads in the last month