Improved subjects

This commit is contained in:
Sven Heidemann 2023-04-15 22:00:59 +02:00
parent 3ee617ee38
commit a463ac5274
2 changed files with 5 additions and 6 deletions

View File

@ -1,10 +1,10 @@
from cpl_core.type import T
from cpl_reactive_extensions.observable import Observable
from cpl_reactive_extensions.subject import Subject
class BehaviorSubject(Observable):
class BehaviorSubject(Subject):
def __init__(self, _t: type, value: T):
Observable.__init__(self, lambda x: x)
Subject.__init__(self, _t)
if not isinstance(value, _t):
raise TypeError(f"Expected {_t.__name__} not {type(value).__name__}")
@ -17,7 +17,6 @@ class BehaviorSubject(Observable):
return self._value
def next(self, value: T):
if not isinstance(value, self._t):
raise TypeError(f"Expected {self._t.__name__} not {type(value).__name__}")
super().next(value)
self._value = value

View File

@ -34,7 +34,7 @@ class Subject(Observable, Observer):
self._raise_if_closed()
if not isinstance(value, self._t):
raise TypeError()
raise TypeError(f"Expected {self._t.__name__} not {type(value).__name__}")
if self.is_stopped:
return