0.0.9 • Published 11 years ago

skewer v0.0.9

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

Skewer

node-ttucsc 大同大學資訊創意研究社 node.js 第二堂課課程:npm + flow control - 自幹簡易 flow control module

  • npm 安裝/移除 module
  • package.josn
  • npm 發布 module
  • 常見 flow control 方法
  • 自幹簡易 flow control module

範例安裝

npm install skewer

用法

skewer()

正宗串燒阿...

用幾個 object 串起數個 function

skewer(function (err, obj) {
  console.log(obj);
})
  .add(function (obj, next) {
    obj.idiot = '馬囧';
    next();
  })
  .add(function (obj, next) {
    obj.idiot2 = '馬囧囧';
    next();
  })
  .run({});

skewer.chain()

鍊子!當前函式的參數由上一步的函式決定

skewer.chain(function (err, text) {
  console.log(b);
})
  .add(function (n, next) {
    next(null, 'xdd');
  })
  .add(function (a, b) {
    next(b);
  });

skewer.customs()

去你的海關,扣我 Geeksphone 這麼多的稅...

按照一開始函數傳入的變數名稱把結果排序並傳入函式

var emit = skewer.customs(function (error, text1, text2) {
  console.log(text1);
  console.log(text2);
});

setTimeout(function () {
  emit('text2', '馬囧');
}, 100);

setTimeout(function () {
  emit('text1', '123');
}, 200);

skewer.map()

把多個相似的異步處理寫在一起,最後把值按順序放入陣列

var square = {
  exponent: 2,
  calc: function (n, cb) {
    var val = Math.pow(n, this.exponent);
    setTimeout(function () {
      cb(null, val);
    }, 100);
  }
};
skewer.map([1, 2, 3], skewer.methodWrapper(square, square.calc), function (err, results) {
  results.toString().should.equal('1,4,9');
  done();
});

也可以傳入一些設定,像是 fs.readFile 可能會需要給 'utf8'

skewer.map(['./file1', './file2', './file3'], fs.readFile, 'utf8', function (err, results) {
  //...
});

License

(The MIT License)

Copyright (c) 2013 Po-Ying Chen

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago