Under Construction
This site is currently under construction. This page is generated by AI and has not undergone thorough review by a human. There may be hallucination!
In fact, for now only /, /reactive, and the llms.txt are carefully crafted by myself.
Effects¶
Side effects that automatically rerun when their dependencies change. Effects subscribe to signals and derived values, executing whenever those dependencies update.
Unlike a simple print(s.get()), when the value of s changes, related Effects will rerun.
In the example above, we use a lambda as the handler. But you can actually pass any callable function that can be called without arguments! I personally like to use effect as a decorator, like this:
Example¶
from reactivity import signal, effect
s = signal(0)
effect(lambda: print(s.get())) # like above, this would print 0
Now, when the value of s changes, the related effects will rerun. For example:
This will print out 1, even though you didn't explicitly call print(s.get()) again.
Decorator usage¶
Runs immediately by default; set call_immediately=False to defer. Dispose with .dispose() or context manager.
Tips¶
memoizedcaches computations as dependencies;effectruns side effectsbatch()groups updates to run effects once- Keep effects small and idempotent
- Use
async_effectfor async tasks - Dispose to avoid leaks
- Effects are semantically closer to "what to do with the data source" rather than "return processed data"
See Also¶
- Signals for observable data sources
- Derived for cached computations
- Advanced Reactivity for async effects and patterns