Core¶
signified.core
¶
Core reactive programming functionality.
Variable
¶
Bases: ABC
, _HasValue[Y]
, ReactiveMixIn[T]
An abstract base class for reactive values.
A reactive value is an object that can be observed by observer for changes and can notify observers when its value changes. This class implements both the observer and observable patterns.
This class implements both the observer and observable pattern.
Subclasses should implement the update
method.
Attributes:
Name | Type | Description |
---|---|---|
_observers |
list[Observer]
|
List of observers subscribed to this variable. |
subscribe
¶
Subscribe an observer to this variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to subscribe. |
required |
unsubscribe
¶
Unsubscribe an observer from this variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to unsubscribe. |
required |
observe
¶
Subscribe the observer (self
) to all items that are Observable.
This method handles arbitrarily nested iterables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Any
|
A single item, an iterable, or a nested structure of items to potentially subscribe to. |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
unobserve
¶
Unsubscribe the observer (self
) from all items that are Observable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Any
|
A single item or an iterable of items to potentially unsubscribe from. |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
update
abstractmethod
¶
Update method to be overridden by subclasses.
Raises:
Type | Description |
---|---|
NotImplementedError
|
If not overridden by a subclass. |
bool
¶
contains
¶
is_not
¶
eq
¶
Return a reactive value for whether self
equals other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
The value to compare against. |
required |
Returns:
Type | Description |
---|---|
Computed[bool]
|
A reactive value for self.value == other. |
Note
We can't overload __eq__
because it interferes with basic Python operations.
where
¶
Return a reactive value for a
if self
is True
, else b
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
HasValue[A]
|
The value to return if |
required |
b
|
HasValue[B]
|
The value to return if |
required |
Returns:
Type | Description |
---|---|
Computed[A | B]
|
A reactive value for |
Signal
¶
Bases: Variable[NestedValue[T], T]
A container that holds a reactive value.
bool
¶
contains
¶
is_not
¶
eq
¶
Return a reactive value for whether self
equals other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
The value to compare against. |
required |
Returns:
Type | Description |
---|---|
Computed[bool]
|
A reactive value for self.value == other. |
Note
We can't overload __eq__
because it interferes with basic Python operations.
where
¶
Return a reactive value for a
if self
is True
, else b
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
HasValue[A]
|
The value to return if |
required |
b
|
HasValue[B]
|
The value to return if |
required |
Returns:
Type | Description |
---|---|
Computed[A | B]
|
A reactive value for |
subscribe
¶
Subscribe an observer to this variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to subscribe. |
required |
unsubscribe
¶
Unsubscribe an observer from this variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to unsubscribe. |
required |
observe
¶
Subscribe the observer (self
) to all items that are Observable.
This method handles arbitrarily nested iterables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Any
|
A single item, an iterable, or a nested structure of items to potentially subscribe to. |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
unobserve
¶
Unsubscribe the observer (self
) from all items that are Observable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Any
|
A single item or an iterable of items to potentially unsubscribe from. |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
Computed
¶
A reactive value defined by a function.
bool
¶
contains
¶
is_not
¶
eq
¶
Return a reactive value for whether self
equals other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
The value to compare against. |
required |
Returns:
Type | Description |
---|---|
Computed[bool]
|
A reactive value for self.value == other. |
Note
We can't overload __eq__
because it interferes with basic Python operations.
where
¶
Return a reactive value for a
if self
is True
, else b
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
HasValue[A]
|
The value to return if |
required |
b
|
HasValue[B]
|
The value to return if |
required |
Returns:
Type | Description |
---|---|
Computed[A | B]
|
A reactive value for |
subscribe
¶
Subscribe an observer to this variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to subscribe. |
required |
unsubscribe
¶
Unsubscribe an observer from this variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to unsubscribe. |
required |
observe
¶
Subscribe the observer (self
) to all items that are Observable.
This method handles arbitrarily nested iterables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Any
|
A single item, an iterable, or a nested structure of items to potentially subscribe to. |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
unobserve
¶
Unsubscribe the observer (self
) from all items that are Observable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items
|
Any
|
A single item or an iterable of items to potentially unsubscribe from. |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
signified.utils
¶
Utility functions for reactive programming.
signified.ops
¶
Reactive operators and methods for reactive values.
ReactiveMixIn
¶
Bases: Generic[T]
Methods for easily creating reactive values.
bool
¶
contains
¶
is_not
¶
eq
¶
Return a reactive value for whether self
equals other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
The value to compare against. |
required |
Returns:
Type | Description |
---|---|
Computed[bool]
|
A reactive value for self.value == other. |
Note
We can't overload __eq__
because it interferes with basic Python operations.
where
¶
Return a reactive value for a
if self
is True
, else b
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
HasValue[A]
|
The value to return if |
required |
b
|
HasValue[B]
|
The value to return if |
required |
Returns:
Type | Description |
---|---|
Computed[A | B]
|
A reactive value for |