create-discord-bot
create-discord-bot copied to clipboard
Global Dependencies
Currently there is no way to have global dependencies that are only initialized once. I think we should have a deps.js file which has some global dependencies. It could be like this:
const dbORM = require("db-orm");
const connection = dbOrm("my-connection");
module.exports = {
connection
};
So then only one connection is created which is reused through out the different widgets.
We would still have to figure out how exactly using those dependencies should work. How about, if the event handler is an object, use deps as a list of dependencies that match to names of keys in deps.js and create an object from that, and inject that into the creator value of that object, and use the output as the event handler. If it is a function, just use it. We would probably have to do some forwarding of the dependencies to the command handlers in the command widget.