Construct JSON object trees recursively, asynchronously to join data from multiple data sources.
Evented construction of JSON objects.
Reiterate creates a JSON object tree asynchronously, interpreting functions in the object heirarchy as data methods that accept a callback.
You can use functions to define the functions that populate the structure.
The data functions can inject more data functions into the heirarchy, so that the children can be created based on their parents.
var loadObject = require'reiterate'loadObjectdatastore = require'acme-datastore'datastore;datastoreselect'articles' 'personId' personId callback;datastoreselect'people' idif errorcallbackerror;elseperson = peopleshift;personarticles = getArticleByPersonpersonid;callbacknull person;;var data = person: getPeople1 ;loadObjectdatafor var i = 0; i < datapersonarticleslength; i++article = datapersonarticlesi;processstdoutwritearticletitle + ' by ' + personname + '\n';;
For those of you using a NoSQL database, this is an easy way to get a pseudo-JOIN, to create a psuedo-JOIN across database engines
reiterate module exports the
var loadObject = require'async-object'loadObject;
object— The object to populate.
callback— The callback to invoke when the object has been loaded, or when an error occurs.
loadObject method to load the
object and invoke the given
when the object is loaded or if there is an error.
Any valid JSON type can be passed to
loadObject. If the type is not an object,
array or function, the data is simply forwarded to the callback.
loadObject will descend the object contents recursively. Any values of type
function found in an object or array are assumed to be methods that accept a
single callback and invoked. The callback is of the form
If data generation function invokes the callback is invoked with an error, the
error is forwarded to the user callback passed to
loadObject and loading ends.
Otherwise, each value in th data passed to the callback descended searching for
Note that each value of the data given to the is first checked for a function that needs to be expanded, invokes the function if it exists. This means that a one data function can return a data structure with data functions in it, and those data functions will be be expanded before they are assigned to the tree.
You can also pass a function as the
object argument so that the expanded data
callback result is given to the user callback.
Changes for each release.
Released: Mon Jul 23 02:29:04 UTC 2012