Skip to content

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

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

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

Conversation

@camriddell
Copy link

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
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

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.26%. Comparing base (3ecffd7) to head (96d530a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1106      +/-   ##
==========================================
+ Coverage   89.22%   89.26%   +0.03%     
==========================================
  Files           9        9              
  Lines        4716     4723       +7     
==========================================
+ Hits         4208     4216       +8     
+ Misses        508      507       -1     

☔ 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
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.

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