Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var async = require("async");
- var _ = require("highland");
- function joinable(bus) {
- return mesh.fallback(
- mesh.accept(
- sift({ join: { $exists: true }}),
- mesh.map(bus, function(operation, data, writable) {
- async.each(Object.keys(operation.join), function(collection, next) {
- bus(mesh.op("load", {
- multi: true,
- collection: collection,
- query: operation.join[collection](operation)
- }))
- .pipe(_.pipeline(_.collect))
- .on("data", function(items) {
- data[collection] = items;
- })
- .on("end", next);
- }, function() {
- writable.end(data);
- });
- })
- ),
- bus
- )
- }
- var bus = mesh.top(joinable(api()));
- bus("load", {
- collection: "messages",
- join: {
- tags: function(message) {
- return {
- messageId: message.uid
- };
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement