2.0.0 • Published 8 years ago

qpipejs v2.0.0

Weekly downloads
61
License
-
Repository
github
Last release
8 years ago

qpipejs

welcome to heaven

qpipejs is designed to help you to write kiss code.

It is built uppon the concepts of glocal and tasks.

how code looks like

var qpipejs = require('qpipejs')

qpipe = qpipejs({
  foo: 'foo',
  bar: 'bar'
})
.do(someTask)
.do(otherTask)
.do(thisOneFails, firstFallbackTask, secondFallbackTask, andSoOn)

You do not need to care whether your tasks are synchronous or asynchronous, promises or callbacked functions.

methods

qpipejs([glocal, options])

  • glocal is the object to be this of every task
  • options is an object with some options, currently only fail

Returns a Qpipe Object

var qpipejs = require('qpipejs')

var qpipe = qpipejs({
  foo: 'foo',
  bar: 'bar'
}, {
  fail: function (error) {
    console.log(error)
  }
})

qpipejs.use

It is a helper to be used in express

When you do app.use(qpipe.use) or router.use(qpipe.use) the res parameter will be populated with a qpipejs function that returns a Qpipe object with some sugar.

qpipe.do(task[, fallback, ...])

Executes task, passing glocal as this If tasks fails, then executes the next fallback If there is no more fallbaks the qpipe fails and options.fail is executed

var qpipejs = require('qpipejs')

qpipe = qpipejs(glocal)
.do(someTask)
.do(otherTask)
.do(thisOneFails, firstFallbackTask, secondFallbackTask, andSoOn)

The tasks are called with task.call(glocal, resolve, reject)

If the task returns resolve, it waits until resolve (or reject) is called If the task returns a promise, it waits until the promise is resolved or rejected If the task returns anything else, the next task is executed.

If the current task throw an exception, calls reject or reject the promise that it has returned, the next fallback task in the same do is executed.

qpipe.each(array, callback)

If array is an Array, execute callback.call(glocal, element, resolve, reject) for each element in array

If array is an Array, execute callback.call(glocal, element, resolve, reject) for each element in glocal[array]

qpipe.all(task, task, ...)

It executes all tasks like that task.call(glocal, resolve, reject) and waits until every one is resolved, or anyone is rejected.

qpipe.race(task, task, ...)

It executes all tasks like that task.call(glocal, resolve, reject) and waits until anyone is resolved or rejected.

qpipe.wait()

It returns the promise at that point. It is the same that qpipe.promise

qpipe.response('foo', 'bar', ...)

Express sugar It response the request with a object that has the keys passed as arguments, and theirs values on the glocal.

If 'status' is passed, it set the glocal.status status

qpipe.ok()

Express sugar It response the request with {"ok": true} and status 200

attributes

qpipe.glocal

It is the object that is passed to every task executed by the qpipe

qpipe.options

It is the object with the options passed.

currently only fail is used

qpipe.options.fail(error)

It is called when any task throw an exception or rejects

If you do not set your own fail function, the default ones are called.

In express: it response the request with status 500 (or error.status) and the json of the error

promise

It is the promise of the last Qpipe method called. Not of the task called.

2.0.0

8 years ago

0.0.17

8 years ago

0.0.16

9 years ago

0.0.15

9 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago