2021-07-20 13:23:13 +00:00
|
|
|
/**
|
2022-03-05 16:49:35 +00:00
|
|
|
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
2024-01-10 23:11:09 +00:00
|
|
|
* Copyright (C) 2021-2024 Ad5001
|
2024-03-28 02:09:37 +00:00
|
|
|
*
|
2021-07-20 13:23:13 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2024-03-28 02:09:37 +00:00
|
|
|
*
|
2021-07-20 13:23:13 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2024-03-28 02:09:37 +00:00
|
|
|
*
|
2021-07-20 13:23:13 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-03-28 02:09:37 +00:00
|
|
|
/**
|
|
|
|
* Base class for global APIs in runtime.
|
|
|
|
*/
|
2024-03-29 00:55:13 +00:00
|
|
|
export class Module {
|
2021-07-20 13:23:13 +00:00
|
|
|
|
2024-03-28 02:09:37 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} name - Name of the API
|
2024-03-29 00:55:13 +00:00
|
|
|
* @param {(Module|undefined)[]} requires - List of APIs required to initialize this one.
|
2024-03-28 02:09:37 +00:00
|
|
|
*/
|
|
|
|
constructor(name, requires = []) {
|
|
|
|
console.log(`Loading module ${name}...`)
|
|
|
|
this.__check_requirements(requires, name)
|
2021-07-20 13:23:13 +00:00
|
|
|
}
|
2024-03-28 02:09:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if all requirements are defined.
|
2024-03-29 00:55:13 +00:00
|
|
|
* @param {(Module|undefined)[]} requires
|
2024-03-28 02:09:37 +00:00
|
|
|
* @param {string} name
|
|
|
|
*/
|
|
|
|
__check_requirements(requires, name) {
|
|
|
|
for(let requirement of requires) {
|
|
|
|
if(requirement === undefined)
|
|
|
|
throw new Error(`Requirement ${requires.indexOf(requirement)} of ${name} has not been initialized.`)
|
2021-07-20 13:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-28 02:09:37 +00:00
|
|
|
}
|