@@ -102,6 +102,38 @@ class _NoUpdate(object):
102
102
"""
103
103
104
104
105
+ def _handle_callback_args (args , kwargs ):
106
+ """Split args into outputs, inputs and states"""
107
+ prevent_initial_call = None
108
+ for k , v in kwargs .items ():
109
+ if k == "prevent_initial_call" :
110
+ prevent_initial_call = v
111
+ else :
112
+ raise TypeError (
113
+ "callback got an unexpected keyword argument '{}'" .format (k )
114
+ )
115
+ args = [
116
+ arg
117
+ # for backward compatibility, one arg can be a list
118
+ for arg_or_list in args
119
+ # flatten args that are lists
120
+ for arg in (
121
+ arg_or_list if isinstance (arg_or_list , (list , tuple ))
122
+ else [arg_or_list ]
123
+ )
124
+ ]
125
+ return [
126
+ # split according to type Output, Input, State
127
+ [arg for arg in args if isinstance (arg , class_ )]
128
+ for class_ in [Output , Input , State ]
129
+ ] + [
130
+ # keep list of args in order, for matching order
131
+ # in the callback's parameters
132
+ [arg for arg in args if not isinstance (arg , Output )],
133
+ prevent_initial_call
134
+ ]
135
+
136
+
105
137
# pylint: disable=too-many-instance-attributes
106
138
# pylint: disable=too-many-arguments, too-many-locals
107
139
class Dash (object ):
@@ -913,7 +945,7 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
913
945
not to fire when its outputs are first added to the page. Defaults to
914
946
`False` unless `prevent_initial_callbacks=True` at the app level.
915
947
"""
916
- output , inputs , state , callback_args , prevent_initial_call = self . _handle_callback_args (args , kwargs )
948
+ output , inputs , state , callback_args , prevent_initial_call = _handle_callback_args (args , kwargs )
917
949
self ._insert_callback (output , inputs , state , callback_args )
918
950
919
951
# If JS source is explicitly given, create a namespace and function
@@ -945,37 +977,6 @@ def clientside_callback(self, clientside_function, *args, **kwargs):
945
977
"function_name" : function_name ,
946
978
}
947
979
948
- def _handle_callback_args (self , args , kwargs ):
949
- """Split args into outputs, inputs and states"""
950
- prevent_initial_call = None
951
- for k , v in kwargs .items ():
952
- if k == "prevent_initial_call" :
953
- prevent_initial_call = v
954
- else :
955
- raise TypeError (
956
- "callback got an unexpected keyword argument '{}'" .format (k )
957
- )
958
- args = [
959
- arg
960
- # for backward compatibility, one arg can be a list
961
- for arg_or_list in args
962
- # flatten args that are lists
963
- for arg in (
964
- arg_or_list if isinstance (arg_or_list , (list , tuple ))
965
- else [arg_or_list ]
966
- )
967
- ]
968
- return [
969
- # split according to type Output, Input, State
970
- [arg for arg in args if isinstance (arg , class_ )]
971
- for class_ in [Output , Input , State ]
972
- ] + [
973
- # keep list of args in order, for matching order
974
- # in the callback's parameters
975
- [arg for arg in args if not isinstance (arg , Output )],
976
- prevent_initial_call
977
- ]
978
-
979
980
def callback (self , * args , ** kwargs ):
980
981
"""
981
982
Normally used as a decorator, `@app.callback` provides a server-side
@@ -988,7 +989,7 @@ def callback(self, *args, **kwargs):
988
989
not to fire when its outputs are first added to the page. Defaults to
989
990
`False` unless `prevent_initial_callbacks=True` at the app level.
990
991
"""
991
- output , inputs , state , callback_args , prevent_initial_call = self . _handle_callback_args (args , kwargs )
992
+ output , inputs , state , callback_args , prevent_initial_call = _handle_callback_args (args , kwargs )
992
993
callback_id = self ._insert_callback (output , inputs , state , callback_args , prevent_initial_call )
993
994
994
995
def wrap_func (func ):
0 commit comments