Open klattimer opened 5 years ago
{
init: function () {},
update: [
{
interval: int,
func: function() {}
}
],
fetch: [
{
interval: int,
url: '/api/path',
params: {}
}
],
ui: {
element: 'selector'
}
}
The main.js will then lookup the selectors and cache them for every object it loads, each object will trigger it's own load by adding itself to a list on parse.
Eventually these JS files will be added to the client scripts via the API objects, therefore preventing their own load if the API fails in some way.
@JHarding-Method
Each js file needs to have itself split out into the specific UI part it affects... There's quite a bit of bundled together crap, partly in the name of hackery partly in efficiency O(2n) will creep up I fear in duplicating certain things.
I'd like the fetches to be de-duplicated, so if cpu gets called once per second, any other object that wants it once per 10 seconds will already have it fetched, the strange case appears when one process wants a fetch every 15 seconds, and another wants a fetch every 10 seconds... 10 seconds is undeniably smaller, but the 5 second offset will be pronounced in the charts.
In the latter case GCD(10, 15) would be the appropriate solution
Here's a recursive function which solves GCD in javascript.
function gcd(a, b) {
if (b) return gcd(b, a % b);
return Math.abs(a);
}
The JS was thrown up quite adhoc, so I need to clean that up a bit.