Prevent a call to update from running before data has been initialized.

master
Adam Greenfield 5 years ago
parent e43efee3a1
commit 370cc060fb

@ -36,6 +36,10 @@ const checkRadioByValue = function (radio_array, value) {
radio_array.find(radio => radio.value == value).checked = true;
};
const state = {
initialized: false,
};
const sell_inputs = getSellFields();
const buy_input = $("#buy");
const first_buy_radios = getFirstBuyRadios();
@ -92,6 +96,9 @@ const initialize = function () {
update();
}
});
console.log('finished initializing');
state.initialized = true;
};
const updateLocalStorage = function (prices, first_buy, previous_pattern) {
@ -364,6 +371,11 @@ const flashMessage = function(message) {
};
const update = function () {
if(!state.initialized){
console.log('update function called before initial data load');
// calls to update before the previous data has been initialized / loaded will reset the data.
return;
}
const sell_prices = getSellPrices();
const buy_price = parseInt(buy_input.val());
const first_buy = getCheckedRadio(first_buy_radios) == 'true';

Loading…
Cancel
Save