logo

Nucleoid是一個流程控制函式庫,基本靈感來自Async函式庫,基本上如果你熟悉Async.js,那你很快就能上手。

npm github

Document

Version Log

Example


目的

當你使用AWS Lambda + API Gateway‎建立一個標準的無伺服器架構來扮演後端的腳色時,你會發現你需要串接大量的AWS服務,此時使用大量的await會使程式變得非常慢,不使用code又不能看,Nucleoid為你提供了一個簡易良好的流程控制系統。


安裝

支援環境有 Nodejs 8+ or support ES6 browser.

web
<script src="https://khc-zhihao.github.io/Nucleoid/dist/index.js"></script>
webpack
import Nucleoid from 'nucleoid'
nodejs
var Nucleoid = require('nucleoid')

流程控制

在寫出Nucleoid之前,我使用了async.js

這是一個非常棒的函式庫,給了我許多初步的概念。

Nucleoid的整體改念來自waterfall :

async.waterfall([
    function(next) {
        next()
    },
    function(rst1, next) {
        next()
    },
], function(err, rst){
    // do something...
})

Packhouse

NPM Version github

Packhouse是一支細粒化函式的類函式導向library,他會是你使用Nucleoid的好夥伴。

let Packhouse = require('packhouse')
let factory = new Packhouse()
gene.setGenetic(() => {
    return {
        $fn: factory,
    }
})

Nucleoid命名來自原核細胞,中文為擬核,是儲藏GENE的地方。