Skip to content

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

from reactivity import effect

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:

s.set(1)

This will print out 1, even though you didn't explicitly call print(s.get()) again.

Decorator usage

@effect
def _():
    print(s.get())

Runs immediately by default; set call_immediately=False to defer. Dispose with .dispose() or context manager.

Tips

  • memoized caches computations as dependencies; effect runs side effects
  • batch() groups updates to run effects once
  • Keep effects small and idempotent
  • Use async_effect for 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