I have been offline from serious JavaScript development for a few years. I am now diving back in but have been hung up for about a day now on a seemingly trivial, basic thing.
This is being developed in TypeScript using ES2019 transpiled to JavaScript, so modern bells and whistles are available if that helps.
I want to convert some functions I wrote into a class that queries, processes, then ultimately stores data within a class from a DB. This is an extraction of one of the function flows.
This basic (non class) version works...
var setSetData = $.Deferred(); // activates when an array of ID's is converted from the url params string into actual DB ids of elements in those sets
// takes in a string of URL params, and in PHP returns index IDs to objects that belong to a set of objects
//names is an array of names derived from a URL param variable like set1,set2,set3
function getIDsBySet(names:Array<string> | false){
var dbRecord = $.ajax({
url: "./src/php/getIdsBySet.php",
type: 'POST',
dataType: "json",
data: {
sets:names,
},
success: function(data:JSON){
return setSetData.resolve(data);
}
});
}
function addToPriorityLoader(ids:Array<number>){
// processing code here, which does involve further DB query, but this should suffice as an example to get me back on track
}
//When we have a set specified in the URL send these DB ids to the priority loading lane
$.when(setSetData).then(addToPriorityLoader),
function(failed:object){
console.log("error in processing set list", failed);
};
How on earth do you get that into class that TypeScript can compile and then will run? I seriously have spent about a day on and off trying different methods. They all fail because of strict mode typing (that wait statement causes no end of trouble when strict mode typed to my VS code compiler) or they flat out won't compile, they loose scope along the way, or they compile fine but then in browser there is no end to the errors in console when fired.