Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup the javascript files into a nice object definition #17

Open
klattimer opened this issue Apr 15, 2019 · 4 comments
Open

Cleanup the javascript files into a nice object definition #17

klattimer opened this issue Apr 15, 2019 · 4 comments

Comments

@klattimer
Copy link
Owner

The JS was thrown up quite adhoc, so I need to clean that up a bit.

@klattimer
Copy link
Owner Author

{
    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.

@klattimer
Copy link
Owner Author

@JHarding-Method

@klattimer
Copy link
Owner Author

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.

@klattimer
Copy link
Owner Author

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant