New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
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

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
3
Weekly downloads
 
Created
Source

MVC for building web server using lark.js

NPM version build status

Features:

* Seperate bussiness codes into layers such as `pageServices`, `dataServices` and `daoServices`, which accord to `MVC` concept. (`C`in `MVC` implements in `lark-router`).
* Make calling rules between MVC layers.
* Support hook between MVC layers (not implemented yet).

Install:

npm install lark-mvc

Example:

First of all, import web server and this module in the app.

import mvc from 'lark-mvc/middleware';
import KOA from 'koa'; // koa2.x
const app = new Koa();
app.use(mvc()) 
app.run(3000)

Secondely, write pageServices layer to implement V in MVC, which generates html codes by rendering tempalate and data.

import MVC from 'lark-mvc';
const service = MVC.getInstance().createService();
const access = service.access();

service.render = async (ctx) => {
    let res = '';
    let categroy = await access.data.demo.getArticles(ctx.params.id);
    let articles = await access.data.demo.getArticles(categroy);
    let data = {
        'categroy': categroy,
        'articles': articles
    };
    res = await ctx.render('demo.html', data);
    return res;
})
export default service;

Thirdly, write dataServices layer to implement M in MVC, which collects data from database and passes them to pageServices.

import MVC from 'lark-mvc';
const service = MVC.getInstance().createService();
const access = service.access();

service.getData = async (ctx) => {
    // get data by dao
    let articles = {}
    articles = await access.dao.demo.get(ctx.request.id);
    return articles
}

export default service;

Forthly, write daoServices layer, which is a wrapper of accessing database.

import MVC from 'lark-mvc';
const service = MVC.getInstance().createService();
const access = service.access();

service.getData = async (ctx) => {
    db = redis.conn();
    data = await db.get('test-key');
    return data;
}

export default service;

We have all done here. And then, run the app to see the results. (Remember to compile with babel before running it)

Keywords

FAQs

Package last updated on 01 Apr 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc