mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2024-11-16 01:10:48 +00:00
36 lines
855 B
Python
36 lines
855 B
Python
|
class Subject:
|
||
|
def __init__(self):
|
||
|
"""list of current observers"""
|
||
|
|
||
|
self._observables = []
|
||
|
|
||
|
def notify(self, modifier=None, data=None):
|
||
|
"""run callbacks on update"""
|
||
|
|
||
|
for observer in self._observables:
|
||
|
observer.on_update(modifier, data)
|
||
|
|
||
|
def add(self, observer):
|
||
|
"""adds an observer to observables"""
|
||
|
|
||
|
if observer not in self._observables:
|
||
|
self._observables.append(observer)
|
||
|
|
||
|
def remove(self, observer):
|
||
|
"""removes an observer from observables"""
|
||
|
|
||
|
try:
|
||
|
self._observables.remove(observer)
|
||
|
except ValueError:
|
||
|
pass
|
||
|
|
||
|
def get(self) -> list:
|
||
|
"""returns the current observables"""
|
||
|
|
||
|
return self._observables
|
||
|
|
||
|
def clear(self):
|
||
|
"""clears the observables list"""
|
||
|
|
||
|
self._observables.clear()
|