| Conditions | 1 |
| Total Lines | 21 |
| Code Lines | 2 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from typing import Optional |
||
| 9 | def rx_subject_behavior(subject_handler: Optional[SubjectHandler] = None) -> Subject: |
||
| 10 | """Create a behavior subject. |
||
| 11 | |||
| 12 | One of the variants of Subjects is the BehaviorSubject, which has a notion |
||
| 13 | of "the current value". |
||
| 14 | It stores the latest value emitted to its consumers, and whenever |
||
| 15 | a new Observer subscribes, it will immediately receive the "current value" |
||
| 16 | from the BehaviorSubject. |
||
| 17 | |||
| 18 | BehaviorSubjects are useful for representing "values over time". |
||
| 19 | For instance, an event stream of birthdays is a Subject, |
||
| 20 | but the stream of a person's age would be a BehaviorSubject. |
||
| 21 | |||
| 22 | Args: |
||
| 23 | subject_handler (Optional[SubjectHandler]): optional suject handler callback |
||
| 24 | |||
| 25 | Returns: |
||
| 26 | (Subject): the subject |
||
| 27 | |||
| 28 | """ |
||
| 29 | return rx_subject_replay(buffer_size=1, subject_handler=subject_handler) |
||
| 30 |