Added subject
This commit is contained in:
@@ -3,15 +3,18 @@ from cpl_reactive_extensions.observable import Observable
|
||||
|
||||
|
||||
class Subject(Observable):
|
||||
def __init__(self):
|
||||
def __init__(self, _t: type):
|
||||
Observable.__init__(self)
|
||||
|
||||
self._t = _t
|
||||
self._value: T = None
|
||||
|
||||
@property
|
||||
def value(self) -> T:
|
||||
return self._value
|
||||
|
||||
def emit(self, value: T):
|
||||
def next(self, value: T):
|
||||
if not isinstance(value, self._t):
|
||||
raise TypeError(f"Expected {self._t.__name__} not {type(value).__name__}")
|
||||
|
||||
self._value = value
|
||||
self._subscriptions()
|
||||
|
||||
Reference in New Issue
Block a user