(
callback_list,
callback_map,
config_prevent_initial_callbacks,
inline_scripts,
clientside_function: ClientsideFuncType,
*args,
**kwargs,
)
| 897 | |
| 898 | |
| 899 | def register_clientside_callback( |
| 900 | callback_list, |
| 901 | callback_map, |
| 902 | config_prevent_initial_callbacks, |
| 903 | inline_scripts, |
| 904 | clientside_function: ClientsideFuncType, |
| 905 | *args, |
| 906 | **kwargs, |
| 907 | ): |
| 908 | output, inputs, state, prevent_initial_call = handle_callback_args(args, kwargs) |
| 909 | no_output = isinstance(output, (list,)) and len(output) == 0 |
| 910 | insert_callback( |
| 911 | callback_list, |
| 912 | callback_map, |
| 913 | config_prevent_initial_callbacks, |
| 914 | output, |
| 915 | None, |
| 916 | inputs, |
| 917 | state, |
| 918 | None, |
| 919 | prevent_initial_call, |
| 920 | no_output=no_output, |
| 921 | hidden=kwargs.get("hidden", None), |
| 922 | ) |
| 923 | |
| 924 | # If JS source is explicitly given, create a namespace and function |
| 925 | # name, then inject the code. |
| 926 | if isinstance(clientside_function, str): |
| 927 | namespace = "_dashprivate_clientside_funcs" |
| 928 | # Create a hash from the function, it will be the same always |
| 929 | function_name = hashlib.sha256(clientside_function.encode("utf-8")).hexdigest() |
| 930 | |
| 931 | inline_scripts.append( |
| 932 | _inline_clientside_template.format( |
| 933 | namespace=namespace, |
| 934 | function_name=function_name, |
| 935 | clientside_function=clientside_function, |
| 936 | ) |
| 937 | ) |
| 938 | |
| 939 | # Callback is stored in an external asset. |
| 940 | else: |
| 941 | namespace = clientside_function.namespace |
| 942 | function_name = clientside_function.function_name |
| 943 | |
| 944 | callback_list[-1]["clientside_function"] = { |
| 945 | "namespace": namespace, |
| 946 | "function_name": function_name, |
| 947 | } |
no test coverage detected
searching dependent graphs…