Skip to content

feat: add rx(…, lazy=)#1106

Open
camriddell wants to merge 6 commits intoholoviz:mainfrom
camriddell:feat/rx-lazy
Open

feat: add rx(…, lazy=)#1106
camriddell wants to merge 6 commits intoholoviz:mainfrom
camriddell:feat/rx-lazy

Conversation

@camriddell
Copy link
Copy Markdown

Added an optional flag to rx(..., lazy: bool = True | False). When lazy=True chaining operations does not evaluate previous operations. Whereas when lazy=False the chaining a new operation evaluates the previous operation (original behavior).

Addresses #1105

This is the current/original behavior

fcalls = 0
def debug_call_count(value):
    nonlocal fcalls
    fcalls += 1
    return value

base = rx(input, lazy=False).rx.pipe(debug_call_count)
title = base.title() # evaluates the previous `.pipe` step
assert fcalls == 1
assert title.rx.value == 'Bob'
assert fcalls == 1 # the entire chain is not re-evaluated

When using lazy=True

fcalls = 0
def debug_call_count(value):
    nonlocal fcalls
    fcalls += 1
    return value

base = rx(input, lazy=True).rx.pipe(debug_call_count)
title = base.title() # does not evaluate the previous `.pipe` step
assert fcalls == 0
assert title.rx.value == 'Bob' # the entire chain is evaluated here
assert fcalls == 1

rx objects can defer their computation completely until an explicit
`.rx.value` is called.
@camriddell
Copy link
Copy Markdown
Author

@philippjfr all stable now. Let me know if this is the way you envisioned the API or if there's a different approach you'd like me to try out.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.38%. Comparing base (d93e585) to head (253ea6d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
param/reactive.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1106      +/-   ##
==========================================
+ Coverage   89.31%   89.38%   +0.06%     
==========================================
  Files           9        9              
  Lines        4734     4746      +12     
==========================================
+ Hits         4228     4242      +14     
+ Misses        506      504       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@philippjfr
Copy link
Copy Markdown
Member

@camriddell This is great, thanks for tackling this. I'll play around with it a bit but don't see any issues. @maximlt has also asked me to hold off on merging until we release a small patch release. So we should get this out some time in February I think.

@philippjfr
Copy link
Copy Markdown
Member

Sorry for the delay here. I'm quite happy with the PR and want to target it for 2.4.0. I'll probably merge this once I've released 2.3.3.

@philippjfr
Copy link
Copy Markdown
Member

@camriddell Hope you don't mind but I've pushed a change. There were a few things that had to be guarded correctly and either has to warn or error and then I parametrized a bunch of tests to run in lazy and non-lazy modes.

@philippjfr
Copy link
Copy Markdown
Member

Seems like the tests are a little flaky, will resolve tomorrow and merge.

@camriddell
Copy link
Copy Markdown
Author

@camriddell Hope you don't mind but I've pushed a change. There were a few things that had to be guarded correctly and either has to warn or error and then I parametrized a bunch of tests to run in lazy and non-lazy modes.

Absolutely, am happy that I was able to get the ball rolling for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants