Correctly using collections in a meteor package? -
i trying create package uses collection. in normal application, same code works fine without issues.
collectiontest.js (package code)
// why need set global property manually? var globals = || window; testcol = new meteor.collection('test'); globals.testcol = testcol; console.log('defined'); if(meteor.isserver){ meteor.publish('test', function(){ return testcol.find(); }); meteor.startup(function(){ console.log('wtf'); testcol.remove({}); testcol.insert({test: 'a document'}); }); }; if(meteor.isclient){ meteor.subscribe('test'); };
test passes on client , server:
tinytest.add('example', function (test) { console.log('here'); var doc = testcol.findone(); test.equal(doc.test, 'a document'); console.log(doc); });
but if open developer tools on client , run:
testcol.find().count()
the result 0. why? also, why have have line globals.testcol = testcol;
tests run @ all? without line, error: testcol not defined occurs on both server , client.
objects defined in package can referenced in application once use api.export
.
in case:
api.export('testcol',['server','client']);
above line expose testcol
global variable , accesible application.
Comments
Post a Comment