use of createRef instead of not working { corrent: xxx }

This commit is contained in:
Jan Prochazka
2021-03-17 18:20:26 +01:00
parent 321d5d71de
commit 9c7df42948
9 changed files with 73 additions and 39 deletions

View File

@@ -13,27 +13,28 @@
import ModalBase from './ModalBase.svelte';
import { closeCurrentModal, closeModal } from './modalTools';
import createRef from '../utility/createRef';
export let connection;
let isTesting;
let sqlConnectResult;
const testIdRef = { current: 0 };
const testIdRef = createRef(0);
async function handleTest(e) {
isTesting = true;
testIdRef.current += 1;
const testid = testIdRef.current;
testIdRef.update(x => x + 1);
const testid = testIdRef.get();
const resp = await axiosInstance.post('connections/test', e.detail);
if (testIdRef.current != testid) return;
if (testIdRef.get() != testid) return;
isTesting = false;
sqlConnectResult = resp.data;
}
function handleCancelTest() {
testIdRef.current += 1; // invalidate current test
testIdRef.update(x => x + 1); // invalidate current test
isTesting = false;
}