MVC for building web server using lark.js

Lark-MVC
A manager for MVC design.
How to use
First define some module, then dispatch works.
Define a controller class inherits from LarkMVC.Controller
, then implements the method main
.
class ShowIntroduction extends LarkMVC.Controller {
async main(ctx, next) {
const person = new this.model.Person('Sun Haohao');
ctx.body = await this.view().render(person);
return;
}
}
Define a model Person
class Person extends LarkMVC.Model {
constructor(name) {
super();
this.name = name;
}
async introduction() {
return new Promise(resolve => setTimeout(() => resolve(`Hello, I am ${this.name}`), 1000));
}
}
Define a view
class MyView extends LarkMVC.View {
async render(person) {
return await person.introduction();
}
}
Register them
const app = new Koa();
const mvc = new LarkMVC();
mvc.use(ShowIntroduction).use(Person).use(MyView);
app.use(async (...args) => await mvc.dispatch('ShowIntroduction', ...args)).listen(3000);