ordu
Execute functions in a configurable order, modifying a shared data structure.
Task functions are executed in order of addition, and passed a shared
context, and a modifiable data structure. Execution is
synchronous. You can exit early by returning a non-null value from a
task function.
You can tag task functions, and restrict execution to the subset of
task functions with matching tags.
This module is used by the Seneca framework to
provide configurable extension hooks.
Quick example
var Ordu = require('ordu')
var w = Ordu()
w.add(function first (ctxt, data) {
if (null == data.foo) {
return {kind: 'error', why: 'no foo'}
}
data.foo = data.foo.substring(0, ctxt.len)
})
w.add({tags: ['upper']}, function second (ctxt, data) {
data.foo = data.foo.toUpperCase()
})
var ctxt = {len: 3}
var data = {foo: 'green'}
w.process(ctxt, data)
console.log(data.foo)
data = {foo: 'blue'}
w.process({tags: ['upper']}, ctxt, data)
console.log(data.foo)
data = []
var res = w.process(ctxt, data)
console.log(res)
Install
npm install ordu
Notes
From the Irish ordú: instruction. Pronounced or-doo.
License
Copyright (c) 2014-2016, Seamus D'Arcy and other contributors.
Licensed under MIT.