@jack-waugh said in Code Readability:
That technique obscures what is dependent on what
Yeah, for stuff like that, I wait until a project becomes bigger to worry about it. It's easy to change it later if you need to be more rigorous about such things. For whatever it is worth, my suggestion is to relax a bit on such things, it might result in getting things working more quickly.
@jack-waugh said in Code Readability:
I had moved away from app-specific HTML for so long that I sort of forgot that you can load everything as scripts from the HTML.
I also do a fair amount of loading stuff this way. That is, load the script files dynamically. Can be really handy if you want to load an updated version of some code without restarting the whole app. This is a bit more complicated because it allows loading directly from a file (via src property of a script tag), or actually reading the text of the js file, and inserting that into a script tag.
(I wouldn't leave it this way on any kind of production app, but it is handy while building something out)
let loadAllJavascript = (isReload) => {
var filteredPath = 'http://localhost:9999/js/filtered/';
// third item true to pull from sandbox files instead
var files = [
['ElemMaker', 'http://localhost:9999/js/library/', true],
['PopupBox', filteredPath, true],
['Scrubber', filteredPath, true],
['AccurateYoutubeTime', filteredPath, true],
['SynchronizerThread', filteredPath, true],
['VideoEventScheduler', filteredPath, true],
['VideoEventQueue', filteredPath, true],
['VideoPlayerNew', filteredPath, true]
];
for(var i=0; i<files.length; i++) {
let scr = document.createElement('script');
if(files[i][2]) {
if(!isReload) {
// this (fetching the text then applying it
// to script tag, rather than just setting the source
// url) should not be necessary, but it seems to be
// in this sandbox environment .
fetch('./js/' + files[i][0] + '.js?' + Math.random())
.then((response) => {
if (response.ok) return response.text()
throw new Error('Network response was not ok.')
})
.then((data) => {
let scr = document.createElement('script');
scr.appendChild(document.createTextNode(data))
document.body.appendChild(scr);
});
}
} else {
scr.src = files[i][1] + files[i][0] + '.js?' + Math.random();
document.body.appendChild(scr);
}
}
}