Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

lark-mvc

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lark-mvc

MVC for building web service

latest
Source
npmnpm
Version
3.2.0
Version published
Weekly downloads
8
-33.33%
Maintainers
3
Weekly downloads
 
Created
Source

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);

Keywords

lark.js

FAQs

Package last updated on 09 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts