Bento
Documentation • Examples
Bento is a robust NodeJS application framework designed to make creating and maintaing complex projects a simple and fast process.
What does Bento do:
- Robust plugable application framework.
- Featuring: Components, Events, Plugins, Properties, Variables
- Component lifecycle state and management
- Consistent Component API
- Defines strict, opinionated, rules
What is a Bento Component?
Bento indroduces a concept of components. Components are logical chunks of code that all work together to provide your application to the world.
All components recieve their own ComponentAPI instance. The Component API is consistent across all components and provides a way for components to speak to eachother. As well as many other "Quality of life" features. Such as: variable injection and management, dependency management and injection, component event subscriptions, and more!
As a rule of thumb, components should not take on more then required. (IE: instead of having one component for connecting to Discord and processing messages. Have two, one for the connection and emitting the message events, and one that handles messages)
Here is a very basic example of a Bento component:
import { Component, ComponentAPI } from '@ayana/bento';
export class ExampleComponent {
public api: ComponentAPI;
public name: string = 'ExampleComponent';
public dependencies: Array<Component> = [];
public async onLoad() {
console.log('Hello world!');
}
public async onUnload() {
console.log('Goodbye world!');
}
}
A runnable version of this example is available on Gitlab
How to use Bento (IN-PROGRESS)
Using Bento is pretty simple. First import and initilize Bento and any plugins you wish to use. Then simply add the plugins to Bento. The below example assumes you have a directory called "components" in the same directory (relative) to it.
import { Bento, FSComponentLoader } from '@ayana/bento';
const bento = new Bento();
(async () => {
const fsloader = new FSComponentLoader();
await fsloader.addDirectory(__dirname, 'components');
await bento.addPlugin(fsloader);
await bento.verify();
})().catch(e => {
console.error(`Error while starting Bento:\n${e}`);
process.exit(1);
});
More examples available here