Skip to content

Commit

Permalink
Improve reactive docstrings (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSkovMadsen authored Jan 2, 2025
1 parent b5a6630 commit 210419d
Show file tree
Hide file tree
Showing 5 changed files with 893 additions and 281 deletions.
2 changes: 1 addition & 1 deletion param/ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def params(self, parameter_s='', namespaces=None):
Usage:
%params <parameterized class or object>
Argsuments
Parameters
----------
parameter_s : str, optional
The name of the parameterized object to inspect. Defaults to an empty string.
Expand Down
28 changes: 18 additions & 10 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,37 +1329,45 @@ def schema(self, safe=False, subset=None, mode='json'):
@property
def rx(self):
"""
The reactive namespace.
The reactive operations namespace.
Provides reactive versions of operations that cannot be made reactive through operator overloading, such as
`.rx.and_` and `.rx.bool`. Calling this namespace (`()`) returns a reactive expression.
Provides reactive versions of operations that cannot be made reactive through
operator overloading. This includes operations such as `.rx.and_` and `.rx.bool`.
Calling this namespace (`.rx()`) creates and returns a reactive expression, enabling
dynamic updates and computation tracking.
Returns
-------
Reactive expression
The result of calling the reactive namespace is a reactive expression.
rx
A reactive expression representing the operation applied to the current value.
User Guide
----------
For more details, see the user guide:
https://param.holoviz.org/user_guide/Reactive_Expressions.html#special-methods-on-rx
Examples
--------
Create a Parameterized instance:
Create a Parameterized instance and access its reactive operations property:
>>> import param
>>> class P(param.Parameterized):
... a = param.Number()
>>> p = P(a=1)
Get the current value:
Retrieve the current value reactively:
>>> a_value = p.param.a.rx.value
>>> a = p.param.a.rx.value
Create a reactive expression by calling the namespace:
Call it to get a reactive expression:
>>> rx_expression = p.param.a.rx()
>>> rx_value = p.param.a.rx()
Use special methods from the reactive ops namespace for reactive operations:
>>> condition = p.param.a.rx.and_(True)
>>> piped = p.param.a.rx.pipe(lambda x: x * 2)
"""
from .reactive import reactive_ops
return reactive_ops(self)
Expand Down
Loading

0 comments on commit 210419d

Please sign in to comment.