I have made an add-on with deckoptions. Today I find the option of it went wrong. I tried to delete almost all the code in ‘raw.js’ and it just stuck. Here’s the code. This file is called in python correctly.
function setup(options) {
// alert(2);
// console.log("2");
const store = options.auxData();
const boolInput = document.getElementById("autoAdd");
const boolAutoLink = document.getElementById("autoLink");
const numberAutoLinkInterval = document.getElementById("autoLinkInterval");
// const numberInput = document.getElementById("buryInterval");
// update html when state changes
store.subscribe((data) => {
boolInput.checked = data["autoAdd"];
boolAutoLink.checked = data["autoLink"];
numberAutoLinkInterval.value = data["autoLinkInterval"];
// numberInput.value = data["buryInterval"];
// and show current data for debugging
// document.getElementById("myDebug").innerText = JSON.stringify(
// data,
// null,
// 4
// );
});
// update config when check state changes
boolInput.addEventListener("change", (_) =>
store.update((data) => {
return { ...data, autoAdd: boolInput.checked };
})
);
boolAutoLink.addEventListener("change", (_) =>
store.update((data) => {
return { ...data, autoLink: boolAutoLink.checked };
})
);
numberAutoLinkInterval.addEventListener("change", (_) => {
let number = 0;
try {
number = parseInt(numberAutoLinkInterval.value, 10);
} catch (err) { }
return store.update((data) => {
return { ...data, autoLinkInterval: number };
});
});
// numberInput.addEventListener("change", (_) => {
// let number = 0;
// try {
// number = parseInt(numberInput.value, 10);
// } catch (err) {}
// return store.update((data) => {
// return { ...data, buryInterval: number };
// });
// });
}
$deckOptions.then((options) => {
options.addHtmlAddon(HTML_CONTENT, () => setup(options));
});
It works normally and is almost the same as another. In fact, I copied this from the first add-on and did some minor modifications at the beginning. After the first one broke down, I compared them again but found nothing. Both Python files have no error, and HTML files are very similar too. I tried deleting all code in the HTML file, and it didn’t help.
Finally, I found what’s wrong. I changed the function name ‘setup’ to ‘setup2’ in the first add-on. It was fixed. Also, I can change the counterpart in another add-on to fix it. I figure somehow the namespace is mixed. And the better practice for now is just put the code used to be in ‘setup’ outside like this.
$deckOptions.then((options) => {
options.addHtmlAddon(HTML_CONTENT, () => {
//code in setup should be moved to here
const store = options.auxData();
//blablabla
});
});