@ayanaware/本多

Bento是一个应用框架,旨在帮助创建和维护g模块化项目.
目标
协助开发者使用模块化代码库中使用的共同模式. 在外面待着 他们的方式, 最低头痛, 最低债务.
承诺
- 可读性 第一:本多的"法典"应该有详细记载,易于阅读.
- 有限依赖:通过写出代码来解决问题,不添加依赖.
- 测试所有的东西:在出道前抓住一些虫子.
班多做的东西
- 可插件应用框架.
- 配置:组件、事件、插件、属性、变量
- 构成部分和插件生命周期管理
- 一致部分 API
- 定义严格,有见解,规则
本多不会的
- 宾多 应 在浏览器中工作,但它不是一个网站框架.
安装
yarn add @ayanaware/bento
npm i @ayanaware/bento
什么是本多组件?
本多(Bentro indroduces)构件的概念. 组件是逻辑的块代码,所有代码合作为世界提供你的应用.
所有组件重现自己的组件API实例 。 构件API在所有构件之间是一致的,为构件相互说话提供了一种方式. 以及许多其他"生活质量"特征. 例如:依赖性解析和注射,可变注射,组件事件等等!
作为拇指的通则,组件不应承担更多的需要。 (IE:而不是有一个连接到Discord和处理消息的组件. 有两个,一个是连接和发布消息事件,一个是处理消息)
以下是本多元素的一个非常基本的例子:
import { Component, ComponentAPI } from '@ayanaware/bento';
export class Basic implements Component {
// required for all components, must be unique
public name = 'Basic';
// this property becomes available after onLoad see ComponentAPI for more info
public api!: ComponentAPI;
// Optionally define other components we depend upon
// Some decorators auto append to this array such as @Subscribe
public dependencies: Array<Component> = [];
// Lifecycle event, called right before component fully loaded
public async onLoad() {
console.log('Hello world!');
}
// Lifecycle event, called right before component is unloaded
public async onUnload() {
console.log('Goodbye world!');
}
}
此示例的可运行版本可见于 胶片
怎样使用本多
从本多开始很简单 首先导入并插入本多和任何您想要使用的插件 。 然后简单地将插件添加到本多. 以下示例假设您在同一目录(相对)中有一个名为"组件"的目录.
import { Bento, EntityType, FSEntityLoader } from '@ayanaware/bento';
// Create a Bento instance
const bento = new Bento();
// Anonymous async function so we can use await
(async () => {
// Create FSEntityLoader
// NOTE: Keep in mind all FSEntityLoader does is
// find components in a path, instantiates them and
// calls Bento.addComponent() behind the scenes
const fsel = new FSEntityLoader();
await fsel.addDirectory([__dirname, 'components'], EntityType.COMPONENT);
// Apply plugin to Bento.
await bento.addPlugin(fsloader);
// Verify that Application looks good to continue
await bento.verify();
})().catch(e => {
console.error(`Error while starting Bento:\n${e}`);
process.exit(1);
});
Bento 应用程序
应用使得本多应用更加容易被拖住. 幕后风声
FSnentity Loader 用于在 ./plugins 财务报告和审定财务报表 ./components 页:1.
变量也使用变量FileLoader从 ../env.example.json 财务报告和审定财务报表 ../env.json。 。 。 .
最后,便当实例和上述插件在需要时会完全被曝光.
import { Application } from '@ayanaware/bento';
// Bento Application Helper
const app = new Application();
// Anonymous async function so we can use await
(async () => {
// Default Variables are loaded from `../env.example.json`
// Variables are loaded from `../env.json`
// Plugins in `./plugins` are instantiated and added to Bento
// Components in `./components` are instantiated and added to Bento
// All this behavior can be modifed using cfg in Application constructor
await app.start();
// Must be called, calls `bento.verify();` and returns `ApplicationState`
await app.verify();
})().catch(e => {
console.error(`Error while starting Application:\n${e}`);
process.exit(1);
});
更多可用实例 这里
证词
下面是几个关于使用本多的狂言!
到目前为止,本多只是 良好的记忆生产, 它的工作非常出色, 我们规模达到了40克, 10个硬块一个集群, 本多让生活与缩放 不那么可怕. - 普莱克西开发公司captchabot.xyz (英语)(中文(简体) )