Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid multiple unncessary evaluations when making rx clone #873

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions param/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ def __init__(
self._method = method
self._operation = operation
self._depth = depth
self._dirty = True
self._dirty = _current is None
self._dirty_obj = False
self._error_state = None
self._current_ = None
self._current_ = _current
if isinstance(obj, rx) and not prev:
self._prev = obj
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/testreactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,14 @@ def test_reactive_set_value_non_root_raises():
rx_val = rx(1) + 1
with pytest.raises(AttributeError):
rx_val.rx.value = 3

def test_reactive_clone_evaluates_once():
namex = rx('bob')

items = []
def debug(value):
items.append(value)
return value

assert namex.rx.pipe(debug).title().rx.value == 'Bob'
assert len(items) == 1