shadow-collection
Meteor collections shadow objects and helpers
This package is a utility package for other packages. It provides a reusable non-conflict way to extend Meteor JS Mongo.Collections and instance transforms.
usage
1addShadow({ 2 before: function (collection, args) { 3 //collection: the collection before the transforms 4 //args 5 }, 6 transform: function (doc, collection, shadow) { 7 //doc: do something to the doc like you would in a transform 8 //collection: the calling collection (use for read only!) 9 //shadow: a unique shadow object for this specific doc, use to store and reference hidden data 10 return doc; 11 }, 12 after: function (collection, args) { 13 //same as before but the collection has been instantiated. 14 } 15});
example
An arbitrary example
1addShadow({ 2 before: function (collection, args) { 3 collection.setTime = true; 4 }, 5 transform: function (doc, collection, shadow) { 6 if (!collection.setTime) return doc //always return the doc! 7 8 shadow.instantiationTime = new Date() 9 10 doc.instantiationTime = function () { 11 return shadow.instantiationTime 12 } 13 14 return doc; //always! 15 } 16}); 17 18Example = new Mongo.Collection('example'); 19var id = Example.insert({}); 20var obj = Example.findOne(id); 21obj.instantiationTime() //returns date object