Advertisement
Guest User

Untitled

a guest
May 27th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. var async = require("async");
  2. var _ = require("highland");
  3.  
  4. function joinable(bus) {
  5. return mesh.fallback(
  6. mesh.accept(
  7. sift({ join: { $exists: true }}),
  8. mesh.map(bus, function(operation, data, writable) {
  9. async.each(Object.keys(operation.join), function(collection, next) {
  10. bus(mesh.op("load", {
  11. multi: true,
  12. collection: collection,
  13. query: operation.join[collection](operation)
  14. }))
  15. .pipe(_.pipeline(_.collect))
  16. .on("data", function(items) {
  17. data[collection] = items;
  18. })
  19. .on("end", next);
  20. }, function() {
  21. writable.end(data);
  22. });
  23. })
  24. ),
  25. bus
  26. )
  27. }
  28.  
  29. var bus = mesh.top(joinable(api()));
  30.  
  31. bus("load", {
  32. collection: "messages",
  33. join: {
  34. tags: function(message) {
  35. return {
  36. messageId: message.uid
  37. };
  38. }
  39. }
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement