|
23 | 23 |
|
24 | 24 | from .fingerprint import build_fingerprint, check_fingerprint
|
25 | 25 | from .resources import Scripts, Css
|
26 |
| -from .dependencies import Input, Output, State |
| 26 | +from .dependencies import handle_callback_args |
27 | 27 | from .development.base_component import ComponentRegistry
|
28 | 28 | from .exceptions import PreventUpdate, InvalidResourceError, ProxyError
|
29 | 29 | from .version import __version__
|
@@ -101,45 +101,6 @@ class _NoUpdate(object):
|
101 | 101 | """
|
102 | 102 |
|
103 | 103 |
|
104 |
| -def extract_callback_args(args, kwargs, name, type_): |
105 |
| - """Extract arguments for callback from a name and type""" |
106 |
| - print(args, kwargs) |
107 |
| - parameters = kwargs.get(name, []) |
108 |
| - if not parameters: |
109 |
| - while args and isinstance(args[0], type_): |
110 |
| - parameters.append(args.pop(0)) |
111 |
| - return parameters |
112 |
| - |
113 |
| - |
114 |
| -def _handle_callback_args(*args, **kwargs): |
115 |
| - """Split args into outputs, inputs and states""" |
116 |
| - prevent_initial_call = kwargs.get("prevent_initial_call", None) |
117 |
| - # flatten args |
118 |
| - args = [ |
119 |
| - arg |
120 |
| - # for backward compatibility, one arg can be a list |
121 |
| - for arg_or_list in args |
122 |
| - # flatten args that are lists |
123 |
| - for arg in ( |
124 |
| - arg_or_list if isinstance(arg_or_list, (list, tuple)) else [arg_or_list] |
125 |
| - ) |
126 |
| - ] |
127 |
| - outputs = extract_callback_args(args, kwargs, "output", Output) |
128 |
| - inputs = extract_callback_args(args, kwargs, "inputs", Input) |
129 |
| - states = extract_callback_args(args, kwargs, "state", State) |
130 |
| - |
131 |
| - if args: |
132 |
| - raise TypeError( |
133 |
| - "callback must received first all Outputs, then all Inputs, then all States" |
134 |
| - ) |
135 |
| - return [ |
136 |
| - outputs, |
137 |
| - inputs, |
138 |
| - states, |
139 |
| - prevent_initial_call, |
140 |
| - ] |
141 |
| - |
142 |
| - |
143 | 104 | # pylint: disable=too-many-instance-attributes
|
144 | 105 | # pylint: disable=too-many-arguments, too-many-locals
|
145 | 106 | class Dash(object):
|
@@ -955,7 +916,7 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
|
955 | 916 | state,
|
956 | 917 | callback_args,
|
957 | 918 | prevent_initial_call,
|
958 |
| - ) = _handle_callback_args(args, kwargs) |
| 919 | + ) = handle_callback_args(args, kwargs) |
959 | 920 | self._insert_callback(output, inputs, state, callback_args)
|
960 | 921 |
|
961 | 922 | # If JS source is explicitly given, create a namespace and function
|
@@ -1004,7 +965,7 @@ def callback(self, *args, **kwargs):
|
1004 | 965 | # for backward compatibility, store whether first argument is a
|
1005 | 966 | # list of only 1 Output
|
1006 | 967 | specified_output_list = isinstance(output, (list, tuple)) and len(output) == 1
|
1007 |
| - (output, inputs, state, prevent_initial_call,) = _handle_callback_args( |
| 968 | + (output, inputs, state, prevent_initial_call,) = handle_callback_args( |
1008 | 969 | *args, **kwargs
|
1009 | 970 | )
|
1010 | 971 | callback_id = self._insert_callback(output, inputs, state, prevent_initial_call)
|
|
0 commit comments