Skip to content

Instantly share code, notes, and snippets.

@mwiegant
Created November 15, 2019 08:03
Show Gist options
  • Save mwiegant/b9380206def4588f8620a8ba34ec20be to your computer and use it in GitHub Desktop.
Save mwiegant/b9380206def4588f8620a8ba34ec20be to your computer and use it in GitHub Desktop.
One potential way to compact all the initialization stuff for CPE400's project
/*
NOTE: I am hesitant to use this potential design because I think it is harder to read. Since I am working with 2 others
who don't have the same level of Javascript experience, I think this code may be harder for them to understand.
*/
/*
initialization.js -- This file defines the things that should be done as soon as the web page initially loads.
Some things that need to be done at initialization:
- setup the default routers
- draw the canvas
*/
let GLOB = {};
(function () {
function setupDefaultRouters() {
if (GLOB_topology.hasRouters()) {
alert("Attempted to reset the global topology to its default routers. Failing out; default routers not set.")
return;
}
GLOB_topology.addRouter(new Router('A', 250, 150));
GLOB_topology.addRouter(new Router('B', 200, 200));
GLOB_topology.addRouter(new Router('C', 300, 200));
GLOB_topology.addRouter(new Router('D', 250, 250));
GLOB_topology.addEdge('A', 'B');
GLOB_topology.addEdge('A', 'C');
GLOB_topology.addEdge('D', 'B');
GLOB_topology.addEdge('D', 'C');
}
document.addEventListener('DOMContentLoaded', function() {
setupDefaultRouters();
// TODO - draw the canvas
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment