3.2.0 • Published 7 years ago

lark-mvc v3.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

MVC for building web server using lark.js

NPM version build status Test coverage NPM downloads Node.js dependencies

Lark-MVC

A manager for MVC design.

How to use

  • see example/koa.js in source code

First define mvc and some module, then dispatch works.

const MVC = require('lark-mvc');
const mvc = new MVC();    // using default configs

Define a Page class inherits from mvc.Page as an controller

class ShowIntroduction extends mvc.Page {
    async main(ctx, next) {
        const person = new this.mvc.Data.Person('Sun Haohao');
        ctx.body = await this.mvc.View.render(person);
        await next();
    }
}

Define a Data Person as model

class Person extends mvc.Data {
    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 mvc.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) => {
    const showIntroduction = new ShowIntroduction();
    await showIntroduction.main(...args);
}).listen(3000);
3.2.0

7 years ago

3.1.4

8 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.0

8 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.2

9 years ago

1.0.0

10 years ago

0.4.7

10 years ago

0.4.6

10 years ago

0.4.5

10 years ago

0.4.4

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago