rx.when not using initial value
- Dominant language
- Python
- Stars
- 521
- Forks
- 86
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 35
Description
I was trying to document `rx.when` on the `main` branch. Since there is no example in the docs about `initial` argument I tried to create one. But its not working as I would expect
```python
from param import rx
def expensive_function(a, b):
print(f'multiplying {a=} and {b=}')
return a * b
a = rx(1)
b = rx(2)
gate = rx(False)
gated_expr = rx(expensive_function)(a, b).rx.when(gate, initial="Initial")
assert gated_expr.rx.value=="Initial"
```
```bash
$ python script.py
multiplying a=1 and b=2
Traceback (most recent call last):
File "/home/jovyan/repos/private/param/script.py", line 12, in
assert gated_expr.rx.value=="Initial"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
```
I would expect this not to raise an error and for the `expensive_function` not to be evaluated.
Contributor guide
Assessment
This issue has not been assessed yet.