3
3
from collections import OrderedDict
4
4
from urllib .parse import parse_qsl , urlencode
5
5
from dash .exceptions import PreventUpdate
6
- from dateutil .parser import parse as parse_date
7
6
8
7
from chime_dash .app .utils .callbacks import ChimeCallback , register_callbacks
9
8
from chime_dash .app .utils import (
@@ -147,6 +146,11 @@ def update_parameters(i, *input_values) -> List[dict]:
147
146
148
147
def __init__ (self , component_instance ):
149
148
def update_parameters_helper (* args , ** kwargs ):
149
+ input_values = list (args )
150
+ input_dict = dict (zip (component_instance .input_value_map .keys (), input_values ))
151
+ sidebar_data = input_values .pop (- 1 )
152
+ if sidebar_data and input_dict and input_dict == sidebar_data ["inputs_dict" ]:
153
+ raise PreventUpdate
150
154
return SidebarCallbacks .update_parameters (component_instance , * args )
151
155
152
156
super ().__init__ (
@@ -156,6 +160,7 @@ def update_parameters_helper(*args, **kwargs):
156
160
changed_elements = component_instance .input_value_map ,
157
161
dom_updates = {"sidebar-store" : "data" },
158
162
callback_fn = update_parameters_helper ,
163
+ stores = ["sidebar-store" ],
159
164
)
160
165
]
161
166
)
@@ -165,13 +170,17 @@ def update_parameters_helper(*args, **kwargs):
165
170
class RootCallbacks (ComponentCallbacks ):
166
171
@staticmethod
167
172
def try_parsing_number (v ):
168
- try :
169
- return int ( v )
170
- except ValueError :
173
+ if v == 'None' :
174
+ result = None
175
+ else :
171
176
try :
172
- return float (v )
177
+ result = int (v )
173
178
except ValueError :
174
- return v
179
+ try :
180
+ result = float (v )
181
+ except ValueError :
182
+ result = v
183
+ return result
175
184
176
185
@staticmethod
177
186
def get_inputs (val_dict , inputs_keys ):
@@ -185,8 +194,6 @@ def parse_hash(hash_str, sidebar_input_types):
185
194
value_type = sidebar_input_types [key ]
186
195
if value_type == "number" :
187
196
parsed_value = RootCallbacks .try_parsing_number (value )
188
- # elif value_type == "date":
189
- # parsed_value = parse_date(value)
190
197
else :
191
198
parsed_value = value
192
199
hash_dict [key ] = parsed_value
@@ -208,10 +215,12 @@ def hash_changed(sidebar_input_types, hash_str=None, root_data=None):
208
215
def stores_changed (inputs_keys , root_mod , sidebar_mod , root_data , sidebar_data ):
209
216
root_modified = root_mod or 0
210
217
sidebar_modified = sidebar_mod or 0
211
- if root_modified < sidebar_modified :
218
+ if root_data and sidebar_data and root_data == sidebar_data .get ("inputs_dict" , None ):
219
+ raise PreventUpdate
220
+ if (root_modified + 100 ) < sidebar_modified :
212
221
inputs_dict = sidebar_data ["inputs_dict" ]
213
222
new_val = RootCallbacks .get_inputs (inputs_dict , inputs_keys )
214
- elif root_modified > sidebar_modified :
223
+ elif root_modified > ( sidebar_modified + 100 ) :
215
224
new_val = RootCallbacks .get_inputs (root_data , inputs_keys )
216
225
else :
217
226
raise PreventUpdate
0 commit comments