Giter VIP home page Giter VIP logo

pigfarm.js's Introduction

配置化页面输出

对于大部分渲染页面的需求,可以归结为以下模型:

  1. 根据url参数向后台请求有关的数据
  2. 将数据丢到模版引擎上得到html

pigfarm.js就是完成这种职责的的一个模块

var pigfarm = require('pigfarm.js');

var app = pigfarm({
    render: function(data) {
        console.log(data.index); // 腾讯视频首页内容;
        return `eat ${data.title.food}`
    },
    data: {
        title: {
            type: "static",
            value: {
                "food": "cabbage"
            }
        },
        index: {
            type: "request",
            action: {
                url: "http://v.qq.com",
                fixAfter: function (data) {
                    return data;
                }
            }
        }
    }
});

console.log(await app()) // 输出 'eat cabbage'

其中,type=request的数据源,action内的配置即pigfarm-fetcher的配置方式。这让你可以获取任意的数据。

事件

app.on('fetchstart', function(koacontext) {

})
  1. fetchstart
  2. fetchend
  3. renderstart
  4. renderend

修改完之后记得npm run test

pigfarm.js's People

Contributors

zombieyang avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.