WIP: #170 #172
@ -1,10 +1,10 @@
|
|||||||
from cpl_core.type import T
|
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):
|
def __init__(self, _t: type, value: T):
|
||||||
Observable.__init__(self, lambda x: x)
|
Subject.__init__(self, _t)
|
||||||
|
|
||||||
if not isinstance(value, _t):
|
if not isinstance(value, _t):
|
||||||
raise TypeError(f"Expected {_t.__name__} not {type(value).__name__}")
|
raise TypeError(f"Expected {_t.__name__} not {type(value).__name__}")
|
||||||
@ -17,7 +17,6 @@ class BehaviorSubject(Observable):
|
|||||||
return self._value
|
return self._value
|
||||||
|
|
||||||
def next(self, value: T):
|
def next(self, value: T):
|
||||||
if not isinstance(value, self._t):
|
super().next(value)
|
||||||
raise TypeError(f"Expected {self._t.__name__} not {type(value).__name__}")
|
|
||||||
|
|
||||||
self._value = value
|
self._value = value
|
||||||
|
@ -34,7 +34,7 @@ class Subject(Observable, Observer):
|
|||||||
self._raise_if_closed()
|
self._raise_if_closed()
|
||||||
|
|
||||||
if not isinstance(value, self._t):
|
if not isinstance(value, self._t):
|
||||||
raise TypeError()
|
raise TypeError(f"Expected {self._t.__name__} not {type(value).__name__}")
|
||||||
|
|
||||||
if self.is_stopped:
|
if self.is_stopped:
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user