This repository has been archived on 2019-12-09. You can view files and clone it, but cannot push or open issues or pull requests.
pacman2/engine/observer.py

15 lines
445 B
Python
Raw Permalink Normal View History

class Observer(object):
def __init__(self):
super().__setattr__('_subscribers', {})
def subscribe(self, name, cb):
if name not in self._subscribers:
self._subscribers[name] = []
self._subscribers[name].append(cb)
def __setattr__(self, name, val):
if name in self._subscribers:
for cb in self._subscribers[name]:
cb(val)
super().__setattr__(name, val)