i have multiple charts on dashboard shows counts, group bys etc. backend data has on million rows. have decided not use subscriptions. don't need reactive updates charts.
my server methods using rawcollection, running aggregations results , assigning data chart objects via session variables setting in client callbacks.
server method:
function purchaseditemdollarsbycategory () { future = npm.require('fibers/future'); var icat = new future(); purchasing.rawcollection().aggregate([ { $project: { "glcodename": 1, "amount" : 1 } }, { $group : { _id: "$glcodename", amount: { $sum : "$amount" } } }, { $sort : {_id : 1} } ], function(err,docs) { if (err) { icat.throw(err); } else { icat.return(docs); } } ); return icat.wait(); }
in template, calling
function getpurchaseditemdollarsbycategory () { meteor.call('purchaseditemdollarsbycategory', function (err, results) { if (err) { toastr.error('something went wrong. not retrieve purchased item count'); return false; } else { session.set( 'purchaseditemdollarsbycategory', results); } }) }
now, using function shape data chart:
function getpurchaseditemcountbycategorychartdata () { var allitemspurchasedbycategory = session.get('purchaseditemcountbycategory'); var allglcodes = []; var allitempurchasedcountdatapoints = []; var contractedpurchasedcountdatapoints = []; _.foreach(allitemspurchasedbycategory, function(d) { allglcodes.push(d._id); allitempurchasedcountdatapoints.push(d.items); }); session.set('allglcodes', allglcodes); session.set('allitempurchasedcountdatapoints', allitempurchasedcountdatapoints); }
now assigning 'allglcodes' , 'allitempurchasedcountdatapoints' highcharts config object in template onrendered event.
server method working fine. client getting data well. rendering happening before data coming back. chart renders empty. if click around app , come page, see data. not sure if understand happening guessing data coming , populating session variable , since session sticky, see data after delay.
i not render till data comes back. have created reactivevar in template oncreated.
this.isloadinga = new reactivevar( false ); this.isloadingb = new reactivevar( false ); this.isloading = new reactivevar ( this.isloadinga && this.isloadingb );
now question should set these false. have multiple server calls going on. have isloading each call , create alldataready variable. if try set in success callback server method:
template.instance().isloadinga.set( true );
i following error:
typeerror: cannot read property 'isloadinga' of null
i hope explaining problem , attempts clearly. thoughts?
i believe template.instance() unavailable in callbacks meteor methods on own. instead do:
examplehelper() { var template = template.instance(); meteor.call( 'example', function(error, results) { console.log(template.instance()); // undefined console.log(template); // want in order set reactive variables. }); }
that allow use reactive vars , setting state appropriately in callbacks.
Comments
Post a Comment