@@ -18,6 +18,7 @@ class Contribution(ABC):
1818 name: A name that should be unique within an extension.
1919 initial_state: contribution specific attribute values.
2020 """
21+
2122 # noinspection PyShadowingBuiltins
2223 def __init__ (self , name : str , ** initial_state ):
2324 self .name = name
@@ -27,8 +28,13 @@ def __init__(self, name: str, **initial_state):
2728 self .callbacks : list [Callback ] = []
2829
2930 def to_dict (self ) -> dict [str , Any ]:
30- """Convert this contribution into a
31- JSON serializable dictionary.
31+ """Convert this contribution into a JSON serializable dictionary.
32+
33+ May be overridden by subclasses to allow for specific
34+ JSON serialization.
35+
36+ Returns:
37+ A JSON serializable dictionary.
3238 """
3339 d = dict (name = self .name )
3440 if self .initial_state is not None :
@@ -41,10 +47,13 @@ def to_dict(self) -> dict[str, Any]:
4147 d .update (callbacks = [cb .to_dict () for cb in self .callbacks ])
4248 return d
4349
44- def layout (self , * args ) -> Callable :
45- """A decorator for a user-provided function that
50+ def layout (self , * args ) -> Callable [[ Callable ], Callable ] :
51+ """Provides a decorator for a user-provided function that
4652 returns the initial user interface layout.
4753
54+ The layout decorator should only be used once for
55+ given contribution instance.
56+
4857 The decorated function must return an instance of
4958 a `chartlets.Component`, usually a `chartlets.components.Box`
5059 that arranges other components in some layout.
@@ -56,16 +65,18 @@ def layout(self, *args) -> Callable:
5665 called `ctx`.
5766
5867 Other parameters of the decorated function are user-defined
59- and must have a corresponding `chartlets.Input` argument
60- in the `layout` decorator in the same order.
68+ and must have a corresponding `chartlets.Input` or
69+ `chartlets.State` arguments in the `layout` decorator in the
70+ same order.
6171
6272 Args:
63- args: Instances of the `chartlets.Input` class that
73+ args:
74+ `chartlets.Input` or `chartlets.State` objects that
6475 define the source of the value for the corresponding
6576 parameter of the decorated function. Optional.
6677
6778 Returns:
68- The decorated, user-provided function .
79+ The decorator .
6980 """
7081
7182 def decorator (function : Callable ) -> Callable :
@@ -77,7 +88,39 @@ def decorator(function: Callable) -> Callable:
7788 return decorator
7889
7990 def callback (self , * args : Channel ) -> Callable [[Callable ], Callable ]:
80- """Decorator."""
91+ """Provide a decorator for a user-provided callback function.
92+
93+ Callback functions are event handlers that react
94+ to events fired by the host application state or by events
95+ fired by related components provided by this contribution's
96+ layout.
97+
98+ The first parameter of the decorated function must be a
99+ positional argument. It provides an application-specific
100+ context that is used to allow for access server-side
101+ configuration and resources. The parameter should be
102+ called `ctx`.
103+
104+ Other parameters of the decorated function are user-defined
105+ and must have a corresponding `chartlets.Input` argument
106+ in the `layout` decorator in the same order.
107+
108+ The return value of the decorated function is used to change
109+ the component or the application state as described by its
110+ `Output` argument passed to the decorator. If more than out
111+ output is specified, the function is supposed to return a tuple
112+ of values with the same number of items in the order given
113+ by the `Output` arguments passed to the decorator.
114+
115+ Args:
116+ args:
117+ `chartlets.Input`, `chartlets.State`, and `Output` objects that
118+ define sources and targets for the parameters passed to the
119+ callback function and the returned from the callback function.
120+
121+ Returns:
122+ The decorated, user-provided function.
123+ """
81124
82125 def decorator (function : Callable ) -> Callable :
83126 self .callbacks .append (
@@ -88,6 +131,3 @@ def decorator(function: Callable) -> Callable:
88131 return function
89132
90133 return decorator
91-
92- def __str__ (self ):
93- return self .name
0 commit comments