|
3 | 3 | import dash |
4 | 4 | import inspect |
5 | 5 |
|
6 | | -def callback(*args, clientside=False, **kwargs): |
| 6 | +def callback(*args, clientside=False, enable_es6=True, enable_stage3=True, **kwargs): |
7 | 7 | """ |
8 | 8 | A decorator to register a Dash callback. If `clientside` is True, the python callback |
9 | | - will be executed clientside using jsbuilder, which will convert it to javascript. |
| 9 | + will be executed clientside using https://github.com/metapensiero/metapensiero.pj |
| 10 | + which will convert it to javascript. |
10 | 11 | |
11 | 12 | If `clientside` is False or not set, the callback will be executed serverside |
12 | 13 | using Dash's standard callback system. |
13 | 14 |
|
14 | 15 | Other than clientside argument, all other arguments are the same as Dash's @callback function. |
15 | 16 |
|
16 | 17 | :param clientside: Whether to execute the callback clientside. Defaults to False. |
| 18 | + :param enable_es6: Whether to enable ES6 syntax. Defaults to True. |
| 19 | + :param enable_stage3: Whether to enable Stage3 syntax. Defaults to True. |
| 20 | + :param args: Arguments to pass to the Dash callback. Include dash.Output, dash.Input, and dash.State. |
| 21 | + :param kwargs: Keyword arguments to pass to the Dash callback. Includes `prevent_initial_call=True`. |
17 | 22 | """ |
18 | 23 |
|
19 | 24 | def decorator(func): |
20 | 25 |
|
21 | 26 | if clientside: |
22 | 27 | python_code = inspect.getsource(func) |
23 | 28 | python_code = python_code[python_code.find("def "):] |
24 | | - js_code = metapensiero.pj.__main__.transform_string(python_code) |
| 29 | + js_code = metapensiero.pj.__main__.transform_string(python_code, enable_es6=enable_es6, enable_stage3=enable_stage3) |
25 | 30 | dash.clientside_callback(js_code, *args, **kwargs) |
26 | 31 | else: |
27 | 32 | @dash.callback(*args, **kwargs) |
|
0 commit comments